Simple symmetric Matrix based on std::vector<double>
More...
#include <VMatrix.h>
|
| VSymMatrix (const unsigned int nRows=0) |
|
virtual | ~VSymMatrix () |
|
void | resize (const unsigned int nRows) |
| Resize symmetric matrix.
|
|
unsigned int | invert () |
| Matrix inversion.
|
|
double & | operator() (unsigned int i, unsigned int j) |
| access element (i,j) assuming i>=j
|
|
double | operator() (unsigned int i, unsigned int j) const |
| access element (i,j) assuming i>=j
|
|
unsigned int | getNumRows () const |
| Get number of rows (= number of colums).
|
|
void | print () const |
| Print matrix.
|
|
VSymMatrix | operator- (const VMatrix &aMatrix) const |
| Subtraction SymMatrix-(sym)Matrix.
|
|
VVector | operator* (const VVector &aVector) const |
| Multiplication SymMatrix*Vector.
|
|
VMatrix | operator* (const VMatrix &aMatrix) const |
| Multiplication SymMatrix*Matrix.
|
|
|
unsigned int | numRows |
| Number of rows.
|
|
std::vector< double > | theVec |
| Data (symmetric storage)
|
|
Simple symmetric Matrix based on std::vector<double>
Definition at line 65 of file VMatrix.h.
◆ VSymMatrix()
gbl::VSymMatrix::VSymMatrix |
( |
const unsigned int |
nRows = 0 | ) |
|
Definition at line 142 of file VMatrix.cc.
142 :
144}
std::vector< double > theVec
Data (symmetric storage)
unsigned int numRows
Number of rows.
◆ ~VSymMatrix()
gbl::VSymMatrix::~VSymMatrix |
( |
| ) |
|
|
virtual |
◆ getNumRows()
unsigned int gbl::VSymMatrix::getNumRows |
( |
| ) |
const |
Get number of rows (= number of colums).
- Returns
- Number of rows.
Definition at line 162 of file VMatrix.cc.
◆ invert()
unsigned int gbl::VSymMatrix::invert |
( |
| ) |
|
Matrix inversion.
Invert symmetric N-by-N matrix V in symmetric storage mode V(1) = V11, V(2) = V12, V(3) = V22, V(4) = V13, . . . replaced by inverse matrix
Method of solution is by elimination selecting the pivot on the diagonal each stage. The rank of the matrix is returned in NRANK. For NRANK ne N, all remaining rows and cols of the resulting matrix V are set to zero.
- Exceptions
-
- Returns
- Rank of matrix.
Definition at line 326 of file VMatrix.cc.
326 {
327
328 const double eps = 1.0E-10;
330 std::vector<int> next(aSize);
331 std::vector<double> diag(aSize);
332 int nSize = aSize;
333
335 for (
int i = 1;
i <= nSize; ++
i) {
337 diag[
i - 1] = fabs(
theVec[(i * i + i) / 2 - 1]);
338 }
339 next[aSize - 1] = -1;
340
341 unsigned int nrank = 0;
342 for (
int i = 1;
i <= nSize; ++
i) {
344 double vkk = 0.0;
345
346 int jCandidate =
first;
347 int previous = 0;
348 int last = previous;
349
350 while (jCandidate > 0) {
351 int jj = (jCandidate * jCandidate + jCandidate) / 2 - 1;
352 if (fabs(
theVec[jj]) > std::max(fabs(vkk), eps * diag[jCandidate - 1])) {
355 last = previous;
356 }
357 previous = jCandidate;
358 jCandidate = next[jCandidate - 1];
359 }
360
361 if (k > 0) {
362 int kk = (
k *
k +
k) / 2 - 1;
363 if (last <= 0) {
365 } else {
366 next[last - 1] = next[
k - 1];
367 }
369 nrank++;
370
371 vkk = 1.0 / vkk;
374 int jl = -1;
375 for (
int j = 1;
j <= nSize; ++
j) {
376 if (j == k) {
377 jk = kk;
379 } else {
380 if (j < k) {
381 ++jk;
382 } else {
384 }
385
389 if (j >= k) {
390 for (
int l = 1;
l <=
k - 1; ++
l) {
391 ++jl;
392 ++lk;
394 }
395 ++jl;
396 lk = kk;
397 for (
int l = k + 1;
l <=
j; ++
l) {
398 ++jl;
401 }
402 } else {
403 for (
int l = 1;
l <=
j; ++
l) {
404 ++jl;
405 ++lk;
407 }
408 }
409 }
410 }
411 } else {
412 for (
int n = 1;
n <= nSize; ++
n) {
413 if (next[n - 1] >= 0) {
414 int nn = (
n *
n -
n) / 2 - 1;
415 for (
int j = 1;
j <= nSize; ++
j) {
416 if (next[j - 1] >= 0) {
418 }
419 }
420 }
421 }
422 throw 1;
423 }
424 }
425 for (int ij = 0; ij < (nSize * nSize + nSize) / 2; ++ij) {
427 }
428 return nrank;
429}
real(dp), parameter, public eps
◆ operator()() [1/2]
double & gbl::VSymMatrix::operator() |
( |
unsigned int |
i, |
|
|
unsigned int |
j |
|
) |
| |
|
inline |
access element (i,j) assuming i>=j
Definition at line 104 of file VMatrix.h.
104 {
105 return theVec[(iRow * iRow + iRow) / 2 + iCol];
106}
◆ operator()() [2/2]
double gbl::VSymMatrix::operator() |
( |
unsigned int |
i, |
|
|
unsigned int |
j |
|
) |
| const |
|
inline |
access element (i,j) assuming i>=j
Definition at line 109 of file VMatrix.h.
110 {
111 return theVec[(iRow * iRow + iRow) / 2 + iCol];
112}
◆ operator*() [1/2]
Multiplication SymMatrix*Matrix.
Definition at line 207 of file VMatrix.cc.
207 {
208 unsigned int nCol = aMatrix.getNumCols();
209 VMatrix aResult(
numRows, nCol);
210 for (
unsigned int l = 0;
l < nCol; ++
l) {
211 for (
unsigned int i = 0;
i <
numRows; ++
i) {
212 aResult(i, l) =
theVec[(
i *
i +
i) / 2 + i] * aMatrix(i, l);
213 for (
unsigned int j = 0;
j <
i; ++
j) {
214 aResult(j, l) +=
theVec[(
i *
i +
i) / 2 + j] * aMatrix(i, l);
215 aResult(i, l) +=
theVec[(
i *
i +
i) / 2 + j] * aMatrix(j, l);
216 }
217 }
218 }
219 return aResult;
220}
◆ operator*() [2/2]
Multiplication SymMatrix*Vector.
Definition at line 194 of file VMatrix.cc.
194 {
196 for (
unsigned int i = 0;
i <
numRows; ++
i) {
197 aResult(i) =
theVec[(
i *
i +
i) / 2 + i] * aVector(i);
198 for (
unsigned int j = 0;
j <
i; ++
j) {
199 aResult(j) +=
theVec[(
i *
i +
i) / 2 + j] * aVector(i);
200 aResult(i) +=
theVec[(
i *
i +
i) / 2 + j] * aVector(j);
201 }
202 }
203 return aResult;
204}
◆ operator-()
Subtraction SymMatrix-(sym)Matrix.
Definition at line 183 of file VMatrix.cc.
183 {
185 for (
unsigned int i = 0;
i <
numRows; ++
i) {
186 for (
unsigned int j = 0;
j <=
i; ++
j) {
187 aResult(i, j) =
theVec[(
i *
i +
i) / 2 + j] - aMatrix(i, j);
188 }
189 }
190 return aResult;
191}
VSymMatrix(const unsigned int nRows=0)
◆ print()
void gbl::VSymMatrix::print |
( |
| ) |
const |
Print matrix.
Definition at line 167 of file VMatrix.cc.
167 {
168 std::cout <<
" VSymMatrix: " <<
numRows <<
"*" <<
numRows << std::endl;
169 for (
unsigned int i = 0;
i <
numRows; ++
i) {
170 for (
unsigned int j = 0;
j <=
i; ++
j) {
171 if (j % 5 == 0) {
172 std::cout << std::endl << std::setw(4) <<
i <<
","
173 << std::setw(4) <<
j <<
"-" << std::setw(4)
174 << std::min(j + 4, i) << ":";
175 }
176 std::cout << std::setw(13) <<
theVec[(
i *
i +
i) / 2 + j];
177 }
178 }
179 std::cout << std::endl << std::endl;
180}
◆ resize()
void gbl::VSymMatrix::resize |
( |
const unsigned int |
nRows | ) |
|
Resize symmetric matrix.
- Parameters
-
Definition at line 153 of file VMatrix.cc.
153 {
155 theVec.resize((nRows * nRows + nRows) / 2);
156}
◆ numRows
unsigned int gbl::VSymMatrix::numRows |
|
private |
Number of rows.
Definition at line 79 of file VMatrix.h.
◆ theVec
std::vector<double> gbl::VSymMatrix::theVec |
|
private |
Data (symmetric storage)
Definition at line 80 of file VMatrix.h.
The documentation for this class was generated from the following files: