Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
miscmaths
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
miscmaths
Commits
72f5364e
Commit
72f5364e
authored
16 years ago
by
Mark Jenkinson
Browse files
Options
Downloads
Patches
Plain Diff
Added memory efficient read_binary_matrix routines
parent
e5bd7fa4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
miscmaths.cc
+26
-13
26 additions, 13 deletions
miscmaths.cc
miscmaths.h
+2
-0
2 additions, 0 deletions
miscmaths.h
with
28 additions
and
13 deletions
miscmaths.cc
+
26
−
13
View file @
72f5364e
...
...
@@ -191,21 +191,35 @@ namespace MISCMATHS {
ReturnMatrix
read_binary_matrix
(
const
string
&
filename
)
{
Matrix
mat
;
if
(
filename
.
size
()
<
1
)
return
mat
;
Matrix
mres
;
read_binary_matrix
(
mres
,
filename
);
mres
.
Release
();
return
mres
;
}
int
read_binary_matrix
(
Matrix
&
mres
,
const
string
&
filename
)
{
if
(
filename
.
size
()
<
1
)
return
1
;
ifstream
fs
(
filename
.
c_str
(),
ios
::
in
|
ios
::
binary
);
if
(
!
fs
)
{
cerr
<<
"Could not open matrix file "
<<
filename
<<
endl
;
return
mat
;
return
2
;
}
mat
=
read_binary_matrix
(
fs
);
read_binary_matrix
(
mres
,
fs
);
fs
.
close
();
mat
.
Release
();
return
mat
;
return
0
;
}
ReturnMatrix
read_binary_matrix
(
ifstream
&
fs
)
{
Matrix
mres
;
read_binary_matrix
(
mres
,
fs
);
mres
.
Release
();
return
mres
;
}
int
read_binary_matrix
(
Matrix
&
mres
,
ifstream
&
fs
)
{
bool
swapbytes
=
false
;
unsigned
int
testval
;
...
...
@@ -216,9 +230,7 @@ namespace MISCMATHS {
Swap_Nbytes
(
1
,
sizeof
(
testval
),
&
testval
);
if
(
testval
!=
BINFLAG
)
{
cerr
<<
"Unrecognised binary matrix file format"
<<
endl
;
Matrix
mres
;
mres
.
Release
();
return
mres
;
return
2
;
}
}
...
...
@@ -235,7 +247,9 @@ namespace MISCMATHS {
// set up and read matrix (rows fast, cols slow)
double
val
;
Matrix
mres
(
nx
,
ny
);
if
(
(((
unsigned
int
)
mres
.
Ncols
())
!=
ny
)
||
(((
unsigned
int
)
mres
.
Nrows
())
<
nx
)
)
{
mres
.
ReSize
(
nx
,
ny
);
}
for
(
unsigned
int
y
=
1
;
y
<=
ny
;
y
++
)
{
for
(
unsigned
int
x
=
1
;
x
<=
nx
;
x
++
)
{
fs
.
read
((
char
*
)
&
val
,
sizeof
(
val
));
...
...
@@ -244,8 +258,7 @@ namespace MISCMATHS {
}
}
mres
.
Release
();
return
mres
;
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
miscmaths.h
+
2
−
0
View file @
72f5364e
...
...
@@ -55,6 +55,7 @@ namespace MISCMATHS {
ReturnMatrix
read_ascii_matrix
(
int
nrows
,
int
ncols
,
const
string
&
filename
);
ReturnMatrix
read_ascii_matrix
(
const
string
&
filename
);
ReturnMatrix
read_vest
(
string
p_fname
);
int
read_binary_matrix
(
Matrix
&
mres
,
const
string
&
filename
);
ReturnMatrix
read_binary_matrix
(
const
string
&
filename
);
ReturnMatrix
read_matrix
(
const
string
&
filename
);
...
...
@@ -71,6 +72,7 @@ namespace MISCMATHS {
ReturnMatrix
read_ascii_matrix
(
ifstream
&
fs
,
int
nrows
,
int
ncols
);
ReturnMatrix
read_ascii_matrix
(
int
nrows
,
int
ncols
,
ifstream
&
fs
);
ReturnMatrix
read_ascii_matrix
(
ifstream
&
fs
);
int
read_binary_matrix
(
Matrix
&
mres
,
ifstream
&
fs
);
ReturnMatrix
read_binary_matrix
(
ifstream
&
fs
);
int
write_ascii_matrix
(
const
Matrix
&
mat
,
ofstream
&
fs
,
int
precision
=-
1
);
int
write_ascii_matrix
(
ofstream
&
fs
,
const
Matrix
&
mat
,
int
precision
=-
1
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment