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
53ec4c3e
Commit
53ec4c3e
authored
17 years ago
by
Jesper Andersson
Browse files
Options
Downloads
Patches
Plain Diff
Added transpose ( .t() ) to SpMat class
parent
fc7e9967
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
+46
-19
46 additions, 19 deletions
SpMat.h
with
46 additions
and
19 deletions
SpMat.h
+
46
−
19
View file @
53ec4c3e
...
...
@@ -11,14 +11,6 @@
// for example inserting elements in a random order may be
// a bit slow.
//
// You will notice that some "obvious" functionality like e.g.
// transpose is missing. Instead I have supplied functionality
// like A.trans_mult(x) which is equivalent to A.t()*x in NEWMAT
// lingo. The reason for this is partly to supply an api that is
// consistent with that expected by IML++. But more so because I
// believe that when a matrix is unwieldily enough to warrant
// the use of a sparse matrix class, then one should not attempt
// to represent both the matrix and its transpose.
//
// Jesper Andersson, FMRIB Image Analysis Group
//
...
...
@@ -134,6 +126,8 @@ public:
SpMat
<
T
>&
operator
&=
(
const
SpMat
<
T
>&
bh
);
// Vert concat below
const
SpMat
<
T
>
TransMultSelf
()
const
{
return
(
TransMult
(
*
this
));}
// Returns transpose(*this)*(*this)
const
SpMat
<
T
>
t
()
const
;
// Returns transpose(*this). Avoid, if at all possible.
friend
class
Accumulator
<
T
>
;
...
...
@@ -146,18 +140,18 @@ public:
unsigned
int
miter
=
200
,
boost
::
shared_ptr
<
Preconditioner
<
T
>
>
C
=
boost
::
shared_ptr
<
Preconditioner
<
T
>
>
())
const
;
NEWMAT
::
ReturnMatrix
SolveForx
(
const
NEWMAT
::
ColumnVector
&
b
,
MatrixType
type
,
double
tol
,
unsigned
int
miter
,
const
NEWMAT
::
ColumnVector
&
x_init
)
const
;
NEWMAT
::
ReturnMatrix
SolveForx
(
const
NEWMAT
::
ColumnVector
&
b
,
MatrixType
type
,
double
tol
,
unsigned
int
miter
,
const
NEWMAT
::
ColumnVector
&
x_init
)
const
;
NEWMAT
::
ReturnMatrix
SolveForx
(
const
NEWMAT
::
ColumnVector
&
b
,
MatrixType
type
,
double
tol
,
unsigned
int
miter
,
boost
::
shared_ptr
<
Preconditioner
<
T
>
>
C
,
const
NEWMAT
::
ColumnVector
&
x_init
)
const
;
NEWMAT
::
ReturnMatrix
SolveForx
(
const
NEWMAT
::
ColumnVector
&
b
,
MatrixType
type
,
double
tol
,
unsigned
int
miter
,
boost
::
shared_ptr
<
Preconditioner
<
T
>
>
C
,
const
NEWMAT
::
ColumnVector
&
x_init
)
const
;
private
:
unsigned
int
_m
;
...
...
@@ -461,6 +455,39 @@ NEWMAT::ReturnMatrix SpMat<T>::SolveForx(const NEWMAT::ColumnVector&
x
.
Release
();
return
(
x
);
}
/////////////////////////////////////////////////////////////////////
//
// Returns a sparse matrix that is the transpose of *this
//
/////////////////////////////////////////////////////////////////////
template
<
class
T
>
const
SpMat
<
T
>
SpMat
<
T
>::
t
()
const
{
SpMat
<
T
>
t_mat
(
_n
,
_m
);
Accumulator
<
T
>
t_col
(
_n
);
for
(
unsigned
int
new_col
=
0
;
new_col
<
_m
;
new_col
++
)
{
// For all columns of transposed matrix
t_col
.
Reset
();
for
(
unsigned
int
old_col
=
0
;
old_col
<
_n
;
old_col
++
)
{
// Search old colums for row-index corresponding to new_col
int
pos
=
0
;
if
(
found
(
_ri
[
old_col
],
new_col
,
pos
))
{
t_col
(
old_col
)
=
_val
[
old_col
][
pos
];
}
}
t_mat
.
_ri
[
new_col
].
resize
(
t_col
.
NO
());
t_mat
.
_val
[
new_col
].
resize
(
t_col
.
NO
());
std
::
vector
<
unsigned
int
>&
t_mat_ri
=
t_mat
.
_ri
[
new_col
];
std
::
vector
<
T
>&
t_mat_val
=
t_mat
.
_val
[
new_col
];
for
(
unsigned
int
i
=
0
;
i
<
t_col
.
NO
();
i
++
)
{
t_mat_ri
[
i
]
=
t_col
.
ri
(
i
);
t_mat_val
[
i
]
=
t_col
.
val
(
i
);
}
t_mat
.
_nz
+=
t_col
.
NO
();
}
return
(
t_mat
);
}
/////////////////////////////////////////////////////////////////////
//
// Returns value at position i,j (one offset)
...
...
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