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
5130d908
Commit
5130d908
authored
14 years ago
by
Jesper Andersson
Browse files
Options
Downloads
Patches
Plain Diff
Made iterator inherit from standard library iterator
parent
de4e2997
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
+36
-36
36 additions, 36 deletions
SpMat.h
with
36 additions
and
36 deletions
SpMat.h
+
36
−
36
View file @
5130d908
...
...
@@ -89,39 +89,6 @@ template<class T>
class
SpMat
{
public:
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
);
...
...
@@ -133,9 +100,6 @@ 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
;
...
...
@@ -205,6 +169,42 @@ public:
boost
::
shared_ptr
<
Preconditioner
<
T
>
>
C
,
const
NEWMAT
::
ColumnVector
&
x_init
)
const
;
// Declaration and definition of bundled Iterator class
class
Iterator
:
public
std
::
iterator
<
std
::
forward_iterator_tag
,
T
>
{
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
;
};
Iterator
begin
()
{
return
(
Iterator
(
*
this
));
}
const
Iterator
&
end
()
{
return
(
_ei
);
}
private
:
unsigned
int
_m
;
unsigned
int
_n
;
...
...
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