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
73f01f11
Commit
73f01f11
authored
17 years ago
by
Jesper Andersson
Browse files
Options
Downloads
Patches
Plain Diff
Added .Print() function that outputs matrix in a row col val format
parent
84128da8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SpMat.h
+45
-0
45 additions, 0 deletions
SpMat.h
with
45 additions
and
0 deletions
SpMat.h
+
45
−
0
View file @
73f01f11
...
...
@@ -21,6 +21,8 @@
#define SpMat_h
#include
<vector>
#include
<fstream>
#include
<iomanip>
#include
<boost/shared_ptr.hpp>
#include
"newmat.h"
#include
"cg.h"
...
...
@@ -97,6 +99,12 @@ public:
unsigned
int
NZ
()
const
{
return
(
_nz
);}
NEWMAT
::
ReturnMatrix
AsNEWMAT
()
const
;
void
Print
(
const
std
::
string
&
fname
,
unsigned
int
precision
)
const
;
void
Print
(
const
std
::
string
&
fname
)
const
{
Print
(
fname
,
8
);}
void
Print
(
unsigned
int
precision
)
const
{
Print
(
std
::
string
(
""
),
precision
);}
void
Print
()
const
{
Print
(
8
);}
T
Peek
(
unsigned
int
r
,
unsigned
int
c
)
const
;
T
operator
()(
unsigned
int
r
,
unsigned
int
c
)
const
{
return
(
Peek
(
r
,
c
));}
// Read-only
...
...
@@ -373,6 +381,43 @@ NEWMAT::ReturnMatrix SpMat<T>::AsNEWMAT() const
return
(
M
);
}
/////////////////////////////////////////////////////////////////////
//
// Prints matrix in a row col val format that is useful for
// exporting it to Matlab (use Matlab function spconvert).
//
/////////////////////////////////////////////////////////////////////
template
<
class
T
>
void
SpMat
<
T
>::
Print
(
const
std
::
string
&
fname
,
unsigned
int
precision
)
const
{
ostream
*
sptr
=
0
;
if
(
!
fname
.
length
())
{
sptr
=
&
cout
;
}
else
{
try
{
sptr
=
new
ofstream
(
fname
.
c_str
());
}
catch
(...)
{
std
::
string
errmsg
(
"BFMatrix::print: Failed to write to file "
+
fname
);
throw
SpMatException
(
errmsg
);
}
}
(
*
sptr
)
<<
setprecision
(
precision
);
for
(
unsigned
int
c
=
0
;
c
<
_n
;
c
++
)
{
for
(
unsigned
int
i
=
0
;
i
<
_ri
[
c
].
size
();
i
++
)
{
if
(
_val
[
c
][
i
])
(
*
sptr
)
<<
_ri
[
c
][
i
]
+
1
<<
" "
<<
c
+
1
<<
" "
<<
_val
[
c
][
i
]
<<
endl
;
}
}
(
*
sptr
)
<<
_m
<<
" "
<<
_n
<<
" "
<<
0
<<
endl
;
if
(
fname
.
length
())
delete
sptr
;
}
/////////////////////////////////////////////////////////////////////
//
// Solves for x in expression b=(*this)*x. Uses the IML++ templates
...
...
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