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
Releases
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
Yuhao Liu
ogs
Commits
1cc3931a
Commit
1cc3931a
authored
11 years ago
by
Tom Fischer
Committed by
Norihiro Watanabe
11 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Used specific properties of dense matrices in applyKnownSolution().
parent
afc68b5c
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/Dense/DenseTools.cpp
+28
-28
28 additions, 28 deletions
MathLib/LinAlg/Dense/DenseTools.cpp
MathLib/LinAlg/Dense/DenseTools.h
+18
-13
18 additions, 13 deletions
MathLib/LinAlg/Dense/DenseTools.h
with
46 additions
and
41 deletions
MathLib/LinAlg/Dense/DenseTools.cpp
+
28
−
28
View file @
1cc3931a
...
...
@@ -17,41 +17,41 @@
namespace
MathLib
{
void
applyKnownSolution
(
DenseMatrix
<
double
>
&
eqsA
,
DenseVector
<
double
>
&
eqsRHS
,
std
::
size_t
k
,
double
x
)
void
applyKnownSolution
(
DenseMatrix
<
double
>
&
eqsA
,
DenseVector
<
double
>
&
eqsRHS
,
std
::
size_t
k
,
double
val
)
{
const
size_t
n_rows
=
eqsA
.
getNRows
();
const
size_t
n_cols
=
eqsA
.
getNCols
();
//A(k, j) = 0.
for
(
size_t
j
=
0
;
j
<
n_cols
;
j
++
)
const
std
::
size_t
n_rows
=
eqsA
.
getNRows
();
const
std
::
size_t
n_cols
=
eqsA
.
getNCols
();
// set all entries of the k-th row of the matrix to zero
// except the diagonal entry that is set to one
for
(
std
::
size_t
j
=
0
;
j
<
n_cols
;
j
++
)
eqsA
(
k
,
j
)
=
.0
;
//A(k, k) = 1,
eqsA
(
k
,
k
)
=
1.0
;
//b_i -= A(i,k)*val, i!=k
for
(
size_t
i
=
0
;
i
<
n_rows
;
++
i
)
{
if
(
i
==
k
)
continue
;
double
v_i_k
=
.0
;
for
(
size_t
j
=
0
;
j
<
n_cols
;
++
j
)
{
if
(
j
==
k
)
{
v_i_k
=
eqsA
(
i
,
k
);
eqsA
(
i
,
k
)
=
.0
;
break
;
}
else
if
(
j
>
k
)
{
break
;
}
}
eqsRHS
[
i
]
-=
v_i_k
*
x
;
}
//b_k = val
eqsRHS
[
k
]
=
x
;
// b_i -= A(i,k)*val, i!=k and
// set the entries of the k-th column of the matrix to zero
// except the diagonal entry A(k,k)
for
(
std
::
size_t
i
=
0
;
i
<
k
;
++
i
)
{
eqsRHS
[
i
]
-=
eqsA
(
i
,
k
)
*
val
;
eqsA
(
i
,
k
)
=
0.0
;
}
for
(
std
::
size_t
i
=
k
+
1
;
i
<
n_rows
;
++
i
)
{
eqsRHS
[
i
]
-=
eqsA
(
i
,
k
)
*
val
;
eqsA
(
i
,
k
)
=
0.0
;
}
// b_k = val
eqsRHS
[
k
]
=
val
;
}
void
applyKnownSolution
(
DenseMatrix
<
double
>
&
A
,
DenseVector
<
double
>
&
b
,
const
std
::
vector
<
std
::
size_t
>
&
_
vec_knownX_id
,
const
std
::
vector
<
double
>
&
_
vec_knownX_x
)
void
applyKnownSolution
(
DenseMatrix
<
double
>
&
A
,
DenseVector
<
double
>
&
b
,
const
std
::
vector
<
std
::
size_t
>
&
vec_knownX_id
,
const
std
::
vector
<
double
>
&
vec_knownX_x
)
{
const
std
::
size_t
n_bc
=
_
vec_knownX_id
.
size
();
const
std
::
size_t
n_bc
=
vec_knownX_id
.
size
();
for
(
std
::
size_t
i_bc
=
0
;
i_bc
<
n_bc
;
i_bc
++
)
{
applyKnownSolution
(
A
,
b
,
_
vec_knownX_id
[
i_bc
],
_
vec_knownX_x
[
i_bc
]);
applyKnownSolution
(
A
,
b
,
vec_knownX_id
[
i_bc
],
vec_knownX_x
[
i_bc
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
MathLib/LinAlg/Dense/DenseTools.h
+
18
−
13
View file @
1cc3931a
...
...
@@ -23,30 +23,35 @@ namespace MathLib
{
/**
*
a
pply known solutions to a system of linear equations
*
A
pply known solutions to a system of linear equations
.
*
* This function introduces the given constrain by diagonalizing a coefficient matrix.
* Symmetr
icit
y of the matrix is preserved.
* This function introduces the given constrain
s
by diagonalizing a coefficient matrix.
* Symmetry of the matrix is preserved.
*
* @param A
Coefficient matrix
* @param b
RHS vector
* @param
_
vec_knownX_id a vector of known solution entry IDs
* @param
_
vec_knownX_x a vector of known solutions
* @param A Coefficient matrix
* @param b RHS vector
* @param vec_knownX_id a vector of known solution entry IDs
* @param vec_knownX_x a vector of known solutions
*/
void
applyKnownSolution
(
DenseMatrix
<
double
>
&
A
,
DenseVector
<
double
>
&
b
,
const
std
::
vector
<
std
::
size_t
>
&
_vec_knownX_id
,
const
std
::
vector
<
double
>
&
_vec_knownX_x
);
void
applyKnownSolution
(
DenseMatrix
<
double
>
&
A
,
DenseVector
<
double
>
&
b
,
const
std
::
vector
<
std
::
size_t
>
&
vec_knownX_id
,
const
std
::
vector
<
double
>
&
vec_knownX_x
);
/**
*
a
pply known solutions to a system of linear equations
*
A
pply known solutions to a system of linear equations
\f$A x = b\f$.
*
* This function introduces the given constrain by diagonalizing a coefficient matrix.
* Symmetricity of the matrix is preserved.
* This function introduces the given constrain into the system of linear
* equations. For this purpose it modifies the entries of \f$A\f$ in the
* \f$k\f$-th row and column, i.e. all those entries are set to zero except
* the diagonal entry that is set to one. The right
* hand side \f$b\f$ is modified, too. The symmetry of \f$A\f$ is preserved.
*
* @param A Coefficient matrix
* @param b RHS vector
* @param row_id a known solution entry ID
* @param
x
a known solution
* @param
val
a known solution
*/
void
applyKnownSolution
(
DenseMatrix
<
double
>
&
A
,
DenseVector
<
double
>
&
b
,
std
::
size_t
row_id
,
double
x
);
void
applyKnownSolution
(
DenseMatrix
<
double
>
&
A
,
DenseVector
<
double
>
&
b
,
std
::
size_t
row_id
,
double
val
);
}
// MathLib
...
...
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