ACF $AcfVersion:0$
CVarMatrix.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
6#include <istd/istd.h>
7#include <istd/TArray.h>
8#include <istd/CIndex2d.h>
9
10
11namespace iser
12{
13 class IArchive;
14}
15
16
17namespace imath
18{
19
20
21class CVarVector;
22
23
108class CVarMatrix: public istd::TArray<double, 2>
109{
110public:
112
117
121 CVarMatrix(const CVarMatrix& matrix);
122
127
131 explicit CVarMatrix(const CVarVector& vector, bool isTransposed = false);
132
136 void Clear();
137
141 void InitToIdentity(int size);
142
143 /*
144 Get a matrix element at the given position.
145 */
146 double GetElementAt(int x, int y) const;
147
148 /*
149 Get the reference of a matrix element at the given position.
150 */
151 double& GetElementRef(int x, int y);
152
156 double GetMaxElement() const;
157
158 /*
159 Get minimal element.
160 */
161 double GetMinElement() const;
162
166 void GetNegated(CVarMatrix& result);
167
171 void GetAdded(const CVarMatrix& matrix, CVarMatrix& result) const;
172
176 void GetSubstracted(const CVarMatrix& matrix, CVarMatrix& result) const;
177
181 void GetMultiplied(const CVarMatrix& matrix, CVarMatrix& result) const;
182
186 CVarMatrix GetMultiplied(const CVarMatrix& matrix) const;
187
191 void GetScaled(double value, CVarMatrix& result) const;
192
196 void GetTransposed(CVarMatrix& result) const;
197
202
206 void Transpose();
207
211 double GetTrace() const;
212
213 /*
214 Get square of euclidean norm.
215 */
216 double GetFrobeniusNorm2() const;
217
218 /*
219 Get euclidean norm.
220 */
221 double GetFrobeniusNorm() const;
222
233 CVarMatrix& result,
234 CVarMatrix* matrix2Ptr = NULL,
235 int maxColumns = -1,
236 double minHhNorm = I_BIG_EPSILON) const;
237
241 bool TransformR(int firstPartWidth);
242
248 bool GetSolvedTriangle(const CVarMatrix& vector, CVarMatrix& result, double accuracy = I_BIG_EPSILON) const;
249
254 bool GetSolvedLSP(const CVarMatrix& vector, CVarMatrix& result, double minHhNorm = I_BIG_EPSILON) const;
255
260 bool GetDecompositionQDQ(CVarMatrix& matrixQ, CVarVector& diagonalD, double tolerance = I_BIG_EPSILON, int maxIterations = 100) const;
261
265 void GetColumnVector(int columnIndex, CVarVector& result);
269 void GetRowVector(int rowIndex, CVarVector& result);
270
271 bool Serialize(iser::IArchive& archive);
272
273 // operators
274 CVarMatrix operator+(const CVarMatrix& b) const;
275 CVarMatrix operator-(const CVarMatrix& b) const;
277 CVarMatrix operator*(const CVarMatrix& b) const;
278 CVarMatrix operator*(double value) const;
279
280 bool operator==(const CVarMatrix& matrix) const;
281 bool operator!=(const CVarMatrix& matrix) const;
282
283 // static methods
297 static void SolveRobustLSP(CVarMatrix matrixA, CVarMatrix& matrixY, CVarMatrix& matrixX, double minHhNorm = I_BIG_EPSILON);
298};
299
300
301// inline methods
302
304{
305 CVarMatrix result;
306
307 GetMultiplied(matrix, result);
308
309 return result;
310}
311
312
314{
315 CVarMatrix result;
316
317 GetTransposed(result);
318
319 *this=result;
320}
321
322
323inline CVarMatrix CVarMatrix::operator+(const CVarMatrix& matrix) const
324{
325 CVarMatrix result;
326
327 GetAdded(matrix, result);
328
329 return result;
330}
331
332
333inline CVarMatrix CVarMatrix::operator-(const CVarMatrix& matrix) const
334{
335 CVarMatrix result;
336
337 GetSubstracted(matrix, result);
338
339 return result;
340}
341
342
344{
345 CVarMatrix result;
346
347 GetNegated(result);
348
349 return result;
350}
351
352
353inline CVarMatrix CVarMatrix::operator*(const CVarMatrix& matrix) const
354{
355 CVarMatrix result;
356
357 GetMultiplied(matrix, result);
358
359 return result;
360}
361
362
363inline CVarMatrix CVarMatrix::operator*(double value) const
364{
365 CVarMatrix result;
366
367 GetScaled(value, result);
368
369 return result;
370}
371
372
373inline CVarMatrix operator*(double value, const imath::CVarMatrix& matrix)
374{
375 return matrix * value;
376}
377
378
379} // namespace imath
380
381
Implementation of variable-size mathematical matrix with double precision elements.
Definition CVarMatrix.h:109
double GetTrace() const
Get trace of this matrix.
CVarMatrix operator-()
Definition CVarMatrix.h:343
bool Serialize(iser::IArchive &archive)
void GetTransposed(CVarMatrix &result) const
Get transposed matrix.
CVarMatrix()
Create empty matrix.
double GetFrobeniusNorm() const
bool operator!=(const CVarMatrix &matrix) const
void Clear()
Set all matrix cells to zero.
bool GetSolvedTriangle(const CVarMatrix &vector, CVarMatrix &result, double accuracy=I_BIG_EPSILON) const
Solving of linear system with triangle matrix.
void InitToIdentity(int size)
Create identity matrix.
double GetFrobeniusNorm2() const
double GetMaxElement() const
Get maximal element.
istd::TArray< double, 2 > BaseClass
Definition CVarMatrix.h:111
bool operator==(const CVarMatrix &matrix) const
void GetColumnVector(int columnIndex, CVarVector &result)
Get single column as vector.
void GetSubstracted(const CVarMatrix &matrix, CVarMatrix &result) const
Get result of substraction of two matrices.
void GetAdded(const CVarMatrix &matrix, CVarMatrix &result) const
Get sum of two matrices.
CVarMatrix(const CVarVector &vector, bool isTransposed=false)
Create matrix from vector.
CVarMatrix GetTransposed() const
Get transposed matrix.
bool TransformR(int firstPartWidth)
Transform this matrix in place.
CVarMatrix(const CVarMatrix &matrix)
Copy constructor.
void Transpose()
Transpose matrix.
Definition CVarMatrix.h:313
CVarMatrix operator+(const CVarMatrix &b) const
Definition CVarMatrix.h:323
void GetMultiplied(const CVarMatrix &matrix, CVarMatrix &result) const
Get result of multiplication of two matrices.
CVarMatrix(istd::CIndex2d size)
Create matrix with specified size.
double GetElementAt(int x, int y) const
bool GetDecompositionQDQ(CVarMatrix &matrixQ, CVarVector &diagonalD, double tolerance=I_BIG_EPSILON, int maxIterations=100) const
Calculate decomposition in form of QDQ where Q is orthogonal matrix and D is diagonal one.
void GetScaled(double value, CVarMatrix &result) const
Get result of multiplication of this matrix with scalar value.
void GetNegated(CVarMatrix &result)
Get result matrix with negated all elements.
double & GetElementRef(int x, int y)
void GetRowVector(int rowIndex, CVarVector &result)
Get single row as vector.
CVarMatrix operator*(const CVarMatrix &b) const
Definition CVarMatrix.h:353
bool GetSolvedLSP(const CVarMatrix &vector, CVarMatrix &result, double minHhNorm=I_BIG_EPSILON) const
Solve 'Least Square Problem'.
static void SolveRobustLSP(CVarMatrix matrixA, CVarMatrix &matrixY, CVarMatrix &matrixX, double minHhNorm=I_BIG_EPSILON)
Solve 'Least Square Problem' using robust algorithm.
double GetMinElement() const
bool GetTriangleDecomposed(CVarMatrix &result, CVarMatrix *matrix2Ptr=NULL, int maxColumns=-1, double minHhNorm=I_BIG_EPSILON) const
Transform matrix to upper triangle form using method of Householder reflexions.
Implementation of variable-size mathematical vector with double precision elements.
Definition CVarVector.h:110
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:21
Multidimensional array with fixed number of dimensions.
Definition TArray.h:24
#define NULL
Definition istd.h:74
static const double I_BIG_EPSILON
Definition istd.h:26
Package with mathematical functions and algebraical primitives.
CVarMatrix operator*(double value, const imath::CVarMatrix &matrix)
Definition CVarMatrix.h:373
Contains general persistence mechanism with basic archives implementations.