CVarMatrix.h
Go to the documentation of this file.
1 #ifndef imath_CVarMatrix_included
2 #define imath_CVarMatrix_included
3 
4 
5 // ACF includes
6 #include <istd/istd.h>
7 #include <istd/TArray.h>
8 #include <istd/CIndex2d.h>
9 
10 
11 namespace iser
12 {
13  class IArchive;
14 }
15 
16 
17 namespace imath
18 {
19 
20 
21 class CVarVector;
22 
23 
27 class CVarMatrix: public istd::TArray<double, 2>
28 {
29 public:
31 
35  CVarMatrix();
36 
40  CVarMatrix(const CVarMatrix& matrix);
41 
45  explicit CVarMatrix(istd::CIndex2d size);
46 
50  explicit CVarMatrix(const CVarVector& vector, bool isTransposed = false);
51 
55  void Clear();
56 
60  void InitToIdentity(int size);
61 
62  /*
63  Get maximal element.
64  */
65  double GetMaxElement() const;
66 
67  /*
68  Get minimal element.
69  */
70  double GetMinElement() const;
71 
75  void GetNegated(CVarMatrix& result);
76 
80  void GetAdded(const CVarMatrix& matrix, CVarMatrix& result) const;
81 
85  void GetSubstracted(const CVarMatrix& matrix, CVarMatrix& result) const;
86 
90  void GetMultiplied(const CVarMatrix& matrix, CVarMatrix& result) const;
91 
95  CVarMatrix GetMultiplied(const CVarMatrix& matrix) const;
96 
100  void GetScaled(double value, CVarMatrix& result) const;
101 
105  void GetTransposed(CVarMatrix& result) const;
106 
110  CVarMatrix GetTransposed() const;
111 
115  void Transpose();
116 
120  double GetTrace() const;
121 
122  /*
123  Get square of euclidean norm.
124  */
125  double GetFrobeniusNorm2() const;
126 
127  /*
128  Get euclidean norm.
129  */
130  double GetFrobeniusNorm() const;
131 
142  CVarMatrix& result,
143  CVarMatrix* matrix2Ptr = NULL,
144  int maxColumns = -1,
145  double minHhNorm = I_BIG_EPSILON) const;
146 
150  bool TransformR(int firstPartWidth);
151 
157  bool GetSolvedTriangle(const CVarMatrix& vector, CVarMatrix& result, double accuracy = I_BIG_EPSILON) const;
158 
163  bool GetSolvedLSP(const CVarMatrix& vector, CVarMatrix& result, double minHhNorm = I_BIG_EPSILON) const;
164 
169  bool GetDecompositionQDQ(CVarMatrix& matrixQ, CVarVector& diagonalD, double tolerance = I_BIG_EPSILON, int maxIterations = 100) const;
170 
174  void GetColumnVector(int columnIndex, CVarVector& result);
178  void GetRowVector(int rowIndex, CVarVector& result);
179 
180  bool Serialize(iser::IArchive& archive);
181 
182  // operators
183  CVarMatrix operator+(const CVarMatrix& b) const;
184  CVarMatrix operator-(const CVarMatrix& b) const;
186  CVarMatrix operator*(const CVarMatrix& b) const;
187  CVarMatrix operator*(double value) const;
188 
189  bool operator==(const CVarMatrix& matrix) const;
190  bool operator!=(const CVarMatrix& matrix) const;
191 
192  // static methods
206  static void SolveRobustLSP(CVarMatrix matrixA, CVarMatrix& matrixY, CVarMatrix& matrixX, double minHhNorm = I_BIG_EPSILON);
207 };
208 
209 
210 // inline methods
211 
213 {
214  CVarMatrix result;
215 
216  GetMultiplied(matrix, result);
217 
218  return result;
219 }
220 
221 
223 {
224  CVarMatrix result;
225 
226  GetTransposed(result);
227 
228  *this=result;
229 }
230 
231 
232 inline CVarMatrix CVarMatrix::operator+(const CVarMatrix& matrix) const
233 {
234  CVarMatrix result;
235 
236  GetAdded(matrix, result);
237 
238  return result;
239 }
240 
241 
242 inline CVarMatrix CVarMatrix::operator-(const CVarMatrix& matrix) const
243 {
244  CVarMatrix result;
245 
246  GetSubstracted(matrix, result);
247 
248  return result;
249 }
250 
251 
253 {
254  CVarMatrix result;
255 
256  GetNegated(result);
257 
258  return result;
259 }
260 
261 
262 inline CVarMatrix CVarMatrix::operator*(const CVarMatrix& matrix) const
263 {
264  CVarMatrix result;
265 
266  GetMultiplied(matrix, result);
267 
268  return result;
269 }
270 
271 
272 inline CVarMatrix CVarMatrix::operator*(double value) const
273 {
274  CVarMatrix result;
275 
276  GetScaled(value, result);
277 
278  return result;
279 }
280 
281 
282 inline CVarMatrix operator*(double value, const imath::CVarMatrix& matrix)
283 {
284  return matrix * value;
285 }
286 
287 
288 } // namespace imath
289 
290 
291 #endif // !imath_CVarMatrix_included
292 
293 
bool operator==(const CVarMatrix &matrix) const
double GetMaxElement() const
double GetFrobeniusNorm2() const
double GetTrace() const
Get trace of this matrix.
CVarMatrix GetTransposed() const
Get transposed matrix.
double GetFrobeniusNorm() const
void Clear()
Set all matrix cells to zero.
bool operator!=(const CVarMatrix &matrix) const
Index implementation for addressing elements in 2D-space.
Definition: CIndex2d.h:20
CVarMatrix operator*(double value, const imath::CVarMatrix &matrix)
Definition: CVarMatrix.h:282
void GetSubstracted(const CVarMatrix &matrix, CVarMatrix &result) const
Get result of substraction of two matrices.
void GetRowVector(int rowIndex, CVarVector &result)
Get single row as vector.
void GetMultiplied(const CVarMatrix &matrix, CVarMatrix &result) const
Get result of multiplication of two matrices.
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.
Multidimensional array with fixed number of dimensions.
Definition: TArray.h:23
double GetMinElement() const
static void SolveRobustLSP(CVarMatrix matrixA, CVarMatrix &matrixY, CVarMatrix &matrixX, double minHhNorm=I_BIG_EPSILON)
Solve 'Least Square Problem' using robust algorithm.
bool Serialize(iser::IArchive &archive)
bool GetSolvedLSP(const CVarMatrix &vector, CVarMatrix &result, double minHhNorm=I_BIG_EPSILON) const
Solve 'Least Square Problem'.
Represent input/output persistence archive.
Definition: IArchive.h:30
void Transpose()
Transpose matrix.
Definition: CVarMatrix.h:222
void GetAdded(const CVarMatrix &matrix, CVarMatrix &result) const
Get sum of two matrices.
istd::TArray< double, 2 > BaseClass
Definition: CVarMatrix.h:30
bool TransformR(int firstPartWidth)
Transform this matrix in place.
#define NULL
Definition: istd.h:64
void InitToIdentity(int size)
Create identity matrix.
void GetColumnVector(int columnIndex, CVarVector &result)
Get single column as vector.
CVarMatrix operator*(const CVarMatrix &b) const
Definition: CVarMatrix.h:262
Simple implementation of variable-size vector.
Definition: CVarVector.h:34
CVarMatrix operator+(const CVarMatrix &b) const
Definition: CVarMatrix.h:232
CVarMatrix()
Create empty matrix.
Definition of mathematical matrix.
Definition: CVarMatrix.h:27
static const double I_BIG_EPSILON
Definition: istd.h:26
CVarMatrix operator-()
Definition: CVarMatrix.h:252
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.
bool GetSolvedTriangle(const CVarMatrix &vector, CVarMatrix &result, double accuracy=I_BIG_EPSILON) const
Solving of linear system with triangle matrix.

© 2007-2017 Witold Gantzke and Kirill Lepskiy