Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Mojtaba Abdolkhani
ogs
Commits
f67b7b9a
Commit
f67b7b9a
authored
9 years ago
by
Dmitri Naumov
Browse files
Options
Downloads
Patches
Plain Diff
[MaL] Update member functions of Eigen matrix/vec.
parent
815b4a1d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MathLib/LinAlg/Eigen/EigenMatrix.h
+19
-21
19 additions, 21 deletions
MathLib/LinAlg/Eigen/EigenMatrix.h
MathLib/LinAlg/Eigen/EigenVector.h
+6
-6
6 additions, 6 deletions
MathLib/LinAlg/Eigen/EigenVector.h
with
25 additions
and
27 deletions
MathLib/LinAlg/Eigen/EigenMatrix.h
+
19
−
21
View file @
f67b7b9a
...
...
@@ -62,14 +62,14 @@ public:
void
setZero
()
{
auto
const
N
=
_mat
.
nonZeros
();
for
(
std
::
remove_const
<
decltype
(
N
)
>::
type
i
=
0
;
i
<
N
;
i
++
)
for
(
auto
i
=
decltype
(
N
){
0
}
;
i
<
N
;
i
++
)
_mat
.
valuePtr
()[
i
]
=
0
;
// don't use _mat.setZero(). it makes a matrix uncompressed
}
/// set a value to the given entry. If the entry doesn't exist, this class
/// dynamically allocates it.
int
setValue
(
std
::
size_t
row
,
std
::
size_t
col
,
double
val
)
int
setValue
(
IndexType
row
,
IndexType
col
,
double
val
)
{
_mat
.
coeffRef
(
row
,
col
)
=
val
;
return
0
;
...
...
@@ -77,7 +77,7 @@ public:
/// add a value to the given entry. If the entry doesn't exist, the value is
/// inserted.
int
add
(
std
::
size_t
row
,
std
::
size_t
col
,
double
val
)
int
add
(
IndexType
row
,
IndexType
col
,
double
val
)
{
assert
(
row
<
getNRows
()
&&
col
<
getNCols
());
_mat
.
coeffRef
(
row
,
col
)
+=
val
;
...
...
@@ -87,7 +87,7 @@ public:
/// Add sub-matrix at positions \c row_pos and same column positions as the
/// given row positions. If the entry doesn't exist, the value is inserted.
template
<
class
T_DENSE_MATRIX
>
void
add
(
std
::
vector
<
std
::
size_t
>
const
&
row_pos
,
void
add
(
std
::
vector
<
IndexType
>
const
&
row_pos
,
const
T_DENSE_MATRIX
&
sub_matrix
,
double
fkt
=
1.0
)
{
...
...
@@ -97,7 +97,7 @@ public:
/// Add sub-matrix at positions given by \c indices. If the entry doesn't exist,
/// this class inserts the value.
template
<
class
T_DENSE_MATRIX
>
void
add
(
RowColumnIndices
<
std
::
size_t
>
const
&
indices
,
void
add
(
RowColumnIndices
<
IndexType
>
const
&
indices
,
const
T_DENSE_MATRIX
&
sub_matrix
,
double
fkt
=
1.0
)
{
...
...
@@ -113,19 +113,19 @@ public:
/// @param sub_matrix a sub-matrix to be added
/// @param fkt a scaling factor applied to all entries in the sub-matrix
template
<
class
T_DENSE_MATRIX
>
void
add
(
std
::
vector
<
std
::
size_t
>
const
&
row_pos
,
std
::
vector
<
std
::
size_t
>
const
&
col_pos
,
const
T_DENSE_MATRIX
&
sub_matrix
,
void
add
(
std
::
vector
<
IndexType
>
const
&
row_pos
,
std
::
vector
<
IndexType
>
const
&
col_pos
,
const
T_DENSE_MATRIX
&
sub_matrix
,
double
fkt
=
1.0
);
/// get value. This function returns zero if the element doesn't exist.
double
get
(
std
::
size_t
row
,
std
::
size_t
col
)
const
double
get
(
IndexType
row
,
IndexType
col
)
const
{
assert
(
row
<
getNRows
()
&&
col
<
getNCols
());
return
_mat
.
coeff
(
row
,
col
);
}
/// get value. This function returns zero if the element doesn't exist.
double
operator
()
(
std
::
size_t
row
,
std
::
size_t
col
)
const
double
operator
()
(
IndexType
row
,
IndexType
col
)
const
{
return
get
(
row
,
col
);
}
...
...
@@ -171,18 +171,17 @@ protected:
RawMatrixType
_mat
;
};
template
<
class
T_DENSE_MATRIX
>
void
EigenMatrix
::
add
(
std
::
vector
<
std
::
size_t
>
const
&
row_pos
,
std
::
vector
<
std
::
size_t
>
const
&
col_pos
,
const
T_DENSE_MATRIX
&
sub_matrix
,
double
fkt
)
template
<
class
T_DENSE_MATRIX
>
void
EigenMatrix
::
add
(
std
::
vector
<
IndexType
>
const
&
row_pos
,
std
::
vector
<
IndexType
>
const
&
col_pos
,
const
T_DENSE_MATRIX
&
sub_matrix
,
double
fkt
)
{
const
std
::
size_
t
n_rows
=
row_pos
.
size
();
const
std
::
size_
t
n_cols
=
col_pos
.
size
();
for
(
std
::
size_t
i
=
0
;
i
<
n_rows
;
i
++
)
{
const
std
::
size_
t
row
=
row_pos
[
i
];
for
(
std
::
size_t
j
=
0
;
j
<
n_cols
;
j
++
)
{
const
std
::
size_
t
col
=
col_pos
[
j
];
auto
cons
t
n_rows
=
row_pos
.
size
();
auto
cons
t
n_cols
=
col_pos
.
size
();
for
(
auto
i
=
decltype
(
n_rows
){
0
}
;
i
<
n_rows
;
i
++
)
{
auto
cons
t
row
=
row_pos
[
i
];
for
(
auto
j
=
decltype
(
n_cols
){
0
}
;
j
<
n_cols
;
j
++
)
{
auto
cons
t
col
=
col_pos
[
j
];
add
(
row
,
col
,
fkt
*
sub_matrix
(
i
,
j
));
}
}
...
...
@@ -192,4 +191,3 @@ EigenMatrix::add(std::vector<std::size_t> const& row_pos, std::vector<std::size_
}
// end namespace MathLib
#endif
This diff is collapsed.
Click to expand it.
MathLib/LinAlg/Eigen/EigenVector.h
+
6
−
6
View file @
f67b7b9a
...
...
@@ -56,30 +56,30 @@ public:
EigenVector
&
operator
*=
(
double
v
)
{
_vec
*=
v
;
return
*
this
;
}
/// access entry
double
const
&
operator
[]
(
std
::
size_t
rowId
)
const
{
return
_vec
[
rowId
];
}
double
&
operator
[]
(
std
::
size_t
rowId
)
{
return
_vec
[
rowId
];
}
double
const
&
operator
[]
(
IndexType
rowId
)
const
{
return
_vec
[
rowId
];
}
double
&
operator
[]
(
IndexType
rowId
)
{
return
_vec
[
rowId
];
}
/// get entry
double
get
(
std
::
size_t
rowId
)
const
double
get
(
IndexType
rowId
)
const
{
return
_vec
[
rowId
];
}
/// set entry
void
set
(
std
::
size_t
rowId
,
double
v
)
void
set
(
IndexType
rowId
,
double
v
)
{
_vec
[
rowId
]
=
v
;
}
/// add entry
void
add
(
std
::
size_t
rowId
,
double
v
)
void
add
(
IndexType
rowId
,
double
v
)
{
_vec
[
rowId
]
+=
v
;
}
/// add entries
template
<
class
T_SUBVEC
>
void
add
(
const
std
::
vector
<
std
::
size_t
>
&
pos
,
const
T_SUBVEC
&
sub_vec
)
void
add
(
const
std
::
vector
<
IndexType
>
&
pos
,
const
T_SUBVEC
&
sub_vec
)
{
for
(
std
::
size_t
i
=
0
;
i
<
pos
.
size
();
++
i
)
{
this
->
add
(
pos
[
i
],
sub_vec
[
i
]);
...
...
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