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
de4e2997
Commit
de4e2997
authored
14 years ago
by
Jesper Andersson
Browse files
Options
Downloads
Patches
Plain Diff
Added read/write forward iterator to SpMat
parent
6f413434
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
+42
-6
42 additions, 6 deletions
SpMat.h
with
42 additions
and
6 deletions
SpMat.h
+
42
−
6
View file @
de4e2997
...
...
@@ -89,8 +89,41 @@ template<class T>
class
SpMat
{
public:
SpMat
()
:
_m
(
0
),
_n
(
0
),
_nz
(
0
),
_ri
(
0
),
_val
(
0
),
_pw
(
false
)
{}
SpMat
(
unsigned
int
m
,
unsigned
int
n
)
:
_m
(
m
),
_n
(
n
),
_nz
(
0
),
_ri
(
n
),
_val
(
n
),
_pw
(
false
)
{}
class
Iterator
{
public:
Iterator
(
SpMat
<
T
>&
mat
,
bool
oob
=
false
)
:
_mat
(
mat
),
_i
(
0
),
_oob
(
oob
)
{
_j
=
0
;
while
(
_j
<
_mat
.
_n
&&
!
_mat
.
_ri
[
_j
].
size
())
_j
++
;
if
(
_j
==
_mat
.
_n
)
_oob
=
true
;
}
~
Iterator
()
{}
bool
operator
==
(
const
Iterator
&
other
)
{
return
(
&
_mat
==&
other
.
_mat
&&
((
_oob
&&
other
.
_oob
)
||
(
_i
==
other
.
_i
&&
_j
==
other
.
_j
)));
}
bool
operator
!=
(
const
Iterator
&
other
)
{
return
(
!
(
*
this
==
other
));
}
T
&
operator
*
()
{
return
((
_mat
.
_val
[
_j
])[
_i
]);
}
Iterator
&
operator
++
()
{
if
(
++
_i
<
_mat
.
_ri
[
_j
].
size
())
return
(
*
this
);
else
{
while
(
++
_j
<
_mat
.
_n
&&
!
_mat
.
_ri
[
_j
].
size
())
;
}
if
(
_j
==
_mat
.
_n
)
_oob
=
true
;
else
_i
=
0
;
return
(
*
this
);
}
unsigned
int
Row
()
{
return
((
_mat
.
_ri
[
_j
])[
_i
]
+
1
);
}
unsigned
int
Col
()
{
return
(
_j
+
1
);
}
private
:
SpMat
<
T
>&
_mat
;
unsigned
int
_i
;
unsigned
int
_j
;
bool
_oob
;
};
SpMat
()
:
_m
(
0
),
_n
(
0
),
_nz
(
0
),
_ri
(
0
),
_val
(
0
),
_pw
(
false
),
_ei
(
*
this
,
true
)
{}
SpMat
(
unsigned
int
m
,
unsigned
int
n
)
:
_m
(
m
),
_n
(
n
),
_nz
(
0
),
_ri
(
n
),
_val
(
n
),
_pw
(
false
),
_ei
(
*
this
,
true
)
{}
SpMat
(
unsigned
int
m
,
unsigned
int
n
,
const
unsigned
int
*
irp
,
const
unsigned
int
*
jcp
,
const
double
*
sp
);
SpMat
(
const
NEWMAT
::
GeneralMatrix
&
M
);
SpMat
(
const
std
::
string
&
fname
);
...
...
@@ -100,6 +133,9 @@ public:
unsigned
int
Ncols
()
const
{
return
(
_n
);}
unsigned
int
NZ
()
const
{
return
(
_nz
);}
Iterator
begin
()
{
return
(
Iterator
(
*
this
));
}
const
Iterator
&
end
()
{
return
(
_ei
);
}
NEWMAT
::
ReturnMatrix
AsNEWMAT
()
const
;
void
Save
(
const
std
::
string
&
fname
,
unsigned
int
precision
)
const
;
...
...
@@ -112,7 +148,6 @@ public:
void
WarningsOn
()
{
_pw
=
true
;}
void
WarningsOff
()
{
_pw
=
false
;}
T
Peek
(
unsigned
int
r
,
unsigned
int
c
)
const
;
T
operator
()(
unsigned
int
r
,
unsigned
int
c
)
const
{
return
(
Peek
(
r
,
c
));}
// Read-only
...
...
@@ -177,6 +212,7 @@ private:
std
::
vector
<
std
::
vector
<
unsigned
int
>
>
_ri
;
std
::
vector
<
std
::
vector
<
T
>
>
_val
;
bool
_pw
;
// Print Warnings
Iterator
_ei
;
bool
found
(
const
std
::
vector
<
unsigned
int
>&
ri
,
unsigned
int
key
,
int
&
pos
)
const
;
T
&
here
(
unsigned
int
r
,
unsigned
int
c
);
...
...
@@ -309,7 +345,7 @@ private:
template
<
class
T
>
SpMat
<
T
>::
SpMat
(
unsigned
int
m
,
unsigned
int
n
,
const
unsigned
int
*
irp
,
const
unsigned
int
*
jcp
,
const
double
*
sp
)
:
_m
(
m
),
_n
(
n
),
_nz
(
0
),
_ri
(
n
),
_val
(
n
),
_pw
(
false
)
:
_m
(
m
),
_n
(
n
),
_nz
(
0
),
_ri
(
n
),
_val
(
n
),
_pw
(
false
)
,
_ei
(
*
this
,
true
)
{
_nz
=
jcp
[
n
];
unsigned
long
nz
=
0
;
...
...
@@ -339,7 +375,7 @@ SpMat<T>::SpMat(unsigned int m, unsigned int n, const unsigned int *irp, const u
template
<
class
T
>
SpMat
<
T
>::
SpMat
(
const
NEWMAT
::
GeneralMatrix
&
M
)
:
_m
(
M
.
Nrows
()),
_n
(
M
.
Ncols
()),
_nz
(
0
),
_ri
(
M
.
Ncols
()),
_val
(
M
.
Ncols
()),
_pw
(
false
)
:
_m
(
M
.
Nrows
()),
_n
(
M
.
Ncols
()),
_nz
(
0
),
_ri
(
M
.
Ncols
()),
_val
(
M
.
Ncols
()),
_pw
(
false
)
,
_ei
(
*
this
,
true
)
{
double
*
m
=
static_cast
<
double
*>
(
M
.
Store
());
...
...
@@ -375,7 +411,7 @@ SpMat<T>::SpMat(const NEWMAT::GeneralMatrix& M)
template
<
class
T
>
SpMat
<
T
>::
SpMat
(
const
std
::
string
&
fname
)
:
_m
(
0
),
_n
(
0
),
_nz
(
0
),
_ri
(
0
),
_val
(
0
),
_pw
(
false
)
:
_m
(
0
),
_n
(
0
),
_nz
(
0
),
_ri
(
0
),
_val
(
0
),
_pw
(
false
)
,
_ei
(
*
this
,
true
)
{
// First read data into (nz+1)x3 NEWMAT matrix
NEWMAT
::
Matrix
rcv
;
...
...
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