TMatrix.h
Go to the documentation of this file.
1 #ifndef imath_TMatrix_included
2 #define imath_TMatrix_included
3 
4 
5 #include <istd/TArray.h>
6 #include <istd/CIndex2d.h>
7 
8 #include <iser/CArchiveTag.h>
9 
10 #include <imath/TVector.h>
11 
12 
13 namespace iser
14 {
15  class IArchive;
16 }
17 
18 
19 namespace imath
20 {
21 
22 
26 template <int Width, int Height, typename Element = double>
27 class TMatrix
28 {
29 public:
32  typedef Element ElementType;
35 
37  {
58  };
59 
63  TMatrix();
64 
68  explicit TMatrix(MatrixInitMode mode);
69 
73  TMatrix(const TMatrix& matrix);
74 
79  void Reset();
80 
85  void Clear();
86 
91  bool IsDimensionsCountFixed() const;
92 
97  int GetDimensionsCount() const;
98 
105  bool SetDimensionsCount(int count);
106 
110  const SizesType& GetSizes() const;
111 
117  bool SetSizes(const SizesType& sizes);
118 
122  int GetSize(int dimension) const;
123 
129  bool SetSize(int dimension, int size);
130 
134  const ElementType& GetAt(const IndexType& index) const;
135 
139  const ElementType& GetAt(int x, int y) const;
140 
144  ElementType& GetAtRef(const IndexType& index);
145 
149  ElementType& GetAtRef(int x, int y);
150 
154  void SetAt(const IndexType& index, const ElementType& value);
155 
159  void SetAt(int x, int y, const ElementType& value);
160 
164  void InitToIdentity();
165 
166  /*
167  Get maximal element.
168  */
169  double GetMaxElement() const;
170 
171  /*
172  Get minimal element.
173  */
174  double GetMinElement() const;
175 
180 
185 
190 
194  template <int SecondWidth>
196  {
197  for (int resultY = 0; resultY < Height; ++resultY){
198  for (int resultX = 0; resultX < SecondWidth; ++resultX){
199  double sum = 0;
200  for (int i = 0; i < Width; ++i){
201  sum += m_elements[i][resultY] * matrix.m_elements[resultX][i];
202  }
203 
204  result.m_elements[resultX][resultY] = sum;
205  }
206  }
207  }
208 
212  template <int SecondWidth>
214  {
216 
217  GetMultiplied(matrix, retVal);
218 
219  return retVal;
220  }
221 
225  void GetMultiplied(const TVector<Width, Element>& vector, TVector<Height, Element>& result) const;
226 
231 
235  void GetScaled(double value, TMatrix<Width, Height, Element>& result) const;
236 
241 
246 
250  void Transpose();
251 
255  double GetTrace() const;
256 
257  /*
258  Get square of euclidean norm.
259  */
260  double GetFrobeniusNorm2() const;
261 
262  /*
263  Get euclidean norm.
264  */
265  double GetFrobeniusNorm() const;
266 
279  int maxColumns = -1,
280  double minHhNorm = I_BIG_EPSILON) const;
281 
286  bool GetDecompositionQDQ(TMatrix<Height, Height, Element>& matrixQ, TVector<Height, Element>& diagonalD, double tolerance = I_BIG_EPSILON, int maxIterations = 100) const;
287 
291  void GetColumnVector(int columnIndex, TVector<Height, Element>& result);
292 
296  void SetColumnVector(int columnIndex, const TVector<Height, Element>& columnVector);
297 
301  void GetRowVector(int rowIndex, TVector<Width, Element>& result);
302 
303  bool Serialize(iser::IArchive& archive);
304 
305  // operators
309 
310  template <int SecondWidth>
312  {
314 
315  GetMultiplied(matrix, retVal);
316 
317  return retVal;
318  }
319 
320  TMatrix<Width, Height, Element> operator*(double value) const;
321 
325 
326  bool operator==(const TMatrix<Width, Height, Element>& matrix) const;
327  bool operator!=(const TMatrix<Width, Height, Element>& matrix) const;
328 
329  const ElementType& operator[](const IndexType& index) const;
330  ElementType& operator[](const IndexType& index);
331 
332 private:
333  typedef Element Elements[Width][Height];
334 
335  Elements m_elements;
336 };
337 
338 
339 // inline methods
340 
341 template <int Width, int Height, typename Element>
343 {
345 
346  GetTransposed(retVal);
347 
348  return retVal;
349 }
350 
351 
352 template <int Width, int Height, typename Element>
354 {
356 
357  GetTransposed(retVal);
358 
359  *this = retVal;
360 }
361 
362 
363 template <int Width, int Height, typename Element>
365 {
367 
368  GetMultiplied(vector, retVal);
369 
370  return retVal;
371 }
372 
373 
374 template <int Width, int Height, typename Element>
376 {
378 
379  GetAdded(matrix, retVal);
380 
381  return retVal;
382 }
383 
384 
385 template <int Width, int Height, typename Element>
387 {
389 
390  GetSubstracted(matrix, retVal);
391 
392  return retVal;
393 }
394 
395 
396 template <int Width, int Height, typename Element>
398 {
400 
401  GetNegated(retVal);
402 
403  return retVal;
404 }
405 
406 
407 template <int Width, int Height, typename Element>
409 {
410  TMatrix retVal;
411 
412  GetScaled(value, retVal);
413 
414  return retVal;
415 }
416 
417 
418 template <int Width, int Height, typename Element>
420 {
421  GetAdded(matrix, *this);
422 
423  return *this;
424 }
425 
426 
427 template <int Width, int Height, typename Element>
429 {
430  GetSubstracted(matrix, *this);
431 
432  return *this;
433 }
434 
435 
436 template <int Width, int Height, typename Element>
438 {
439  GetScaled(value, *this);
440 
441  return *this;
442 }
443 
444 
445 template <int Width, int Height, typename Element>
447 {
448  return matrix * value;
449 }
450 
451 
452 // public methods
453 
454 template <int Width, int Height, typename Element>
456 {
457 }
458 
459 
460 template <int Width, int Height, typename Element>
462 {
463  switch (mode){
464  case MIM_ZERO:
465  for (int x = 0; x < Width; ++x){
466  for (int y = 0; y < Height; ++y){
467  m_elements[x][y] = 0;
468  }
469  }
470  break;
471 
472  case MIM_ONES:
473  for (int x = 0; x < Width; ++x){
474  for (int y = 0; y < Height; ++y){
475  m_elements[x][y] = 1;
476  }
477  }
478  break;
479 
480  case MIM_IDENTITY:
481  for (int x = 0; x < Width; ++x){
482  for (int y = 0; y < Height; ++y){
483  if (x == y){
484  m_elements[x][y] = 1;
485  }
486  else{
487  m_elements[x][y] = 0;
488  }
489  }
490  }
491  break;
492 
493  case MIM_UPPER_TRIANGLE:
494  for (int x = 0; x < Width; ++x){
495  for (int y = 0; y < Height; ++y){
496  if (x <= y){
497  m_elements[x][y] = 1;
498  }
499  else{
500  m_elements[x][y] = 0;
501  }
502  }
503  }
504  break;
505 
506  case MIM_DOWNER_TRIANGLE:
507  for (int x = 0; x < Width; ++x){
508  for (int y = 0; y < Height; ++y){
509  if (x >= y){
510  m_elements[x][y] = 1;
511  }
512  else{
513  m_elements[x][y] = 0;
514  }
515  }
516  }
517  break;
518  }
519 }
520 
521 
522 template <int Width, int Height, typename Element>
524 {
525  for (int x = 0; x < Width; ++x){
526  for (int y = 0; y < Height; ++y){
527  m_elements[x][y] = matrix.m_elements[x][y];
528  }
529  }
530 }
531 
532 
533 // init operations
534 
535 template <int Width, int Height, typename Element>
537 {
538  for (int x = 0; x < Width; ++x){
539  for (int y = 0; y < Height; ++y){
540  m_elements[x][y] = 0;
541  }
542  }
543 }
544 
545 
546 template <int Width, int Height, typename Element>
548 {
549  Reset();
550 }
551 
552 
553 template <int Width, int Height, typename Element>
555 {
556  return true;
557 }
558 
559 
560 template <int Width, int Height, typename Element>
562 {
563  return 2;
564 }
565 
566 
567 template <int Width, int Height, typename Element>
569 {
570  return (count == 2);
571 }
572 
573 
574 template <int Width, int Height, typename Element>
576 {
577  static SizesType retVal(Width, Height);
578 
579  return retVal;
580 }
581 
582 
583 template <int Width, int Height, typename Element>
585 {
586  return (sizes[0] == Width) && (sizes[1] == Height);
587 }
588 
589 
590 template <int Width, int Height, typename Element>
592 {
593  switch (dimension){
594  case 0:
595  return Width;
596 
597  case 1:
598  return Height;
599 
600  default:
601  return 0;
602  }
603 }
604 
605 
606 template <int Width, int Height, typename Element>
607 bool TMatrix<Width, Height, Element>::SetSize(int dimension, int size)
608 {
609  switch (dimension){
610  case 0:
611  return (size == Width);
612 
613  case 1:
614  return (size == Height);
615 
616  default:
617  return false;
618  }
619 }
620 
621 
622 template <int Width, int Height, typename Element>
624 {
625  return m_elements[index[0]][index[1]];
626 }
627 
628 
629 template <int Width, int Height, typename Element>
631 {
632  return m_elements[x][y];
633 }
634 
635 
636 template <int Width, int Height, typename Element>
638 {
639  return m_elements[index[0]][index[1]];
640 }
641 
642 
643 template <int Width, int Height, typename Element>
645 {
646  return m_elements[x][y];
647 }
648 
649 
650 template <int Width, int Height, typename Element>
652 {
653  m_elements[index[0]][index[1]] = value;
654 }
655 
656 
657 template <int Width, int Height, typename Element>
658 void TMatrix<Width, Height, Element>::SetAt(int x, int y, const ElementType& value)
659 {
660  m_elements[x][y] = value;
661 }
662 
663 
664 template <int Width, int Height, typename Element>
666 {
667  for (int x = 0; x < Width; ++x){
668  for (int y = 0; y < Height; ++y){
669  if (x != y){
670  m_elements[x][y] = 0;
671  }
672  else{
673  m_elements[x][y] = 1;
674  }
675  }
676  }
677 }
678 
679 
680 template <int Width, int Height, typename Element>
682 {
683  double retVal = m_elements[0][0];
684 
685  for (int x = 0; x < Width; ++x){
686  for (int y = 0; y < Height; ++y){
687  double value = m_elements[x][y];
688 
689  if (value > retVal){
690  retVal = value;
691  }
692  }
693  }
694 
695  return retVal;
696 }
697 
698 
699 template <int Width, int Height, typename Element>
701 {
702  double retVal = m_elements[0][0];
703 
704  for (int x = 0; x < Width; ++x){
705  for (int y = 0; y < Height; ++y){
706  double value = m_elements[x][y];
707 
708  if (value < retVal){
709  retVal = value;
710  }
711  }
712  }
713 
714  return retVal;
715 }
716 
717 
718 template <int Width, int Height, typename Element>
720 {
721  for (int x = 0; x < Width; ++x){
722  for (int y = 0; y < Height; ++y){
723  result.m_elements[x][y] = -m_elements[x][y];
724  }
725  }
726 }
727 
728 
729 template <int Width, int Height, typename Element>
731 {
732  for (int x = 0; x < Width; ++x){
733  for (int y = 0; y < Height; ++y){
734  result.m_elements[x][y] = m_elements[x][y] + matrix.m_elements[x][y];
735  }
736  }
737 }
738 
739 
740 template <int Width, int Height, typename Element>
742 {
743  for (int x = 0; x < Width; ++x){
744  for (int y = 0; y < Height; ++y){
745  result.m_elements[x][y] = m_elements[x][y] - matrix.m_elements[x][y];
746  }
747  }
748 }
749 
750 
751 template <int Width, int Height, typename Element>
753 {
754  for (int resultY = 0; resultY < Height; ++resultY){
755  double sum = 0;
756  for (int i = 0; i < Width; ++i){
757  sum += m_elements[i][resultY] * vector[i];
758  }
759 
760  result[resultY] = sum;
761  }
762 }
763 
764 
765 template <int Width, int Height, typename Element>
767 {
768  for (int x = 0; x < Width; ++x){
769  for (int y = 0; y < Height; ++y){
770  result.m_elements[x][y] = m_elements[x][y] * value;
771  }
772  }
773 }
774 
775 
776 template <int Width, int Height, typename Element>
778 {
779  for (int x = 0; x < Width; ++x){
780  for (int y = 0; y < Height; ++y){
781  result.m_elements[y][x] = m_elements[x][y];
782  }
783  }
784 }
785 
786 
787 template <int Width, int Height, typename Element>
789 {
790  int commonSize = qMin(Width, Height);
791 
792  double retVal = 0;
793  for (int i = 0; i < commonSize; ++i){
794  retVal += m_elements[i][i];
795  }
796 
797  return retVal;
798 }
799 
800 
801 template <int Width, int Height, typename Element>
803 {
804  double retVal = 0.0;
805 
806  for (int x = 0; x < Width; ++x){
807  for (int y = 0; y < Height; ++y){
808  double value = m_elements[x][y];
809  retVal += double(value * value);
810  }
811  }
812  return retVal;
813 }
814 
815 
816 template <int Width, int Height, typename Element>
818 {
819  return qSqrt(GetFrobeniusNorm2());
820 }
821 
822 
823 template <int Width, int Height, typename Element>
825 {
826  if (Width != Height){
827  return false;
828  }
829 
830  TMatrix<Width, Height, Element> matrixR = *this;
831  matrixQ.Clear();
832 
833  for (int i = 0; i < maxIterations; ++i){
836  if (!matrixR.GetTriangleDecomposed(tempMatrixR, &tempMatrixQ)){
837  return false;
838  }
839  matrixR = tempMatrixR.GetMultiplied(tempMatrixQ);
840 
841  matrixQ = tempMatrixQ.GetMultiplied(matrixQ);
842 
843  double residue = 0;
844  istd::CIndex2d index;
845  for (index[0] = 0; index[0] < Width; ++index[0]){
846  for (index[1] = 0; index[1] < Width; ++index[1]){
847  if (index[0] != index[1]){
848  double element = matrixR.GetAt(index);
849 
850  residue += element * element;
851  }
852  }
853  }
854 
855  if (residue <= tolerance){
856  for (int i = 0; i < Height; ++i){
857  diagonalD[i] = matrixR.GetAt(i, i);
858  }
859 
860  return true;
861  }
862  }
863 
864  return false;
865 }
866 
867 
868 template <int Width, int Height, typename Element>
870 {
871  Q_ASSERT(columnIndex < Width);
872  Q_ASSERT(columnIndex >= 0);
873 
874  for (int y = 0; y < Height; ++y){
875  result[y] = m_elements[columnIndex][y];
876  }
877 }
878 
879 
880 template <int Width, int Height, typename Element>
882 {
883  Q_ASSERT(columnIndex < Width);
884  Q_ASSERT(columnIndex >= 0);
885 
886  for (int y = 0; y < Height; ++y){
887  m_elements[columnIndex][y] = columnVector[y];
888  }
889 }
890 
891 
892 template <int Width, int Height, typename Element>
894 {
895  Q_ASSERT(rowIndex < Height);
896 
897  for (int x = 0; x < Width; ++x){
898  result[rowIndex] = m_elements[x][rowIndex];
899  }
900 }
901 
902 
903 template <int Width, int Height, typename Element>
907  int maxColumns,
908  double minHhNorm) const
909 {
910  if (&result != this){
911  result = *this;
912  }
913 
914  int columnsCount = qMin(Height - 1, Width);
915  if ((maxColumns >= 0) && (maxColumns < columnsCount)){
916  columnsCount = maxColumns;
917  }
918 
919  for (int hhIndex = 0; hhIndex < columnsCount; ++hhIndex){
920  double hhNorm2 = 0;
921  for (istd::CIndex2d normIndex(hhIndex, hhIndex); normIndex[1] < Height; ++normIndex[1]){
922  double element = result.GetAt(normIndex);
923 
924  hhNorm2 += element * element;
925  }
926 
927  if (hhNorm2 < minHhNorm){
928  return false;
929  }
930 
931  double element0 = result[istd::CIndex2d(hhIndex, hhIndex)];
932 
933  double hhLength = (element0 >= 0)? qSqrt(hhNorm2): -qSqrt(hhNorm2); // destination diagonal value of current processed column, sign is choosen optimal for maximal householder vector length
934 
935  double hhVector0 = element0 + hhLength; // element 0 of householder vector, rest of ist will be taken directly from matrix elements
936  double hhVectorNorm2 = hhNorm2 + hhVector0 * hhVector0 - element0 * element0; // sqare of norm of householder vector, first element replaced from original column norm sqare
937 
938  // correct next columns
939  istd::CIndex2d matrixIndex;
940  for (matrixIndex[0] = hhIndex + 1; matrixIndex[0] < Width; ++matrixIndex[0]){
941  matrixIndex[1] = hhIndex;
942  double dotProduct = result[matrixIndex] * hhVector0;
943  for (matrixIndex[1]++; matrixIndex[1] < Height; ++matrixIndex[1]){
944  dotProduct += result.GetAt(matrixIndex) * result.GetAt(istd::CIndex2d(hhIndex, matrixIndex[1]));
945  }
946 
947  double reflexionFactor = 2 * dotProduct / hhVectorNorm2;
948  matrixIndex[1] = hhIndex;
949  result[matrixIndex] -= hhVector0 * reflexionFactor;
950  for (matrixIndex[1]++; matrixIndex[1] < Height; ++matrixIndex[1]){
951  result.GetAtRef(matrixIndex) -= result[istd::CIndex2d(hhIndex, matrixIndex[1])] * reflexionFactor;
952  }
953  }
954 
955  // correct optional matrix
956  if (matrixQPtr != NULL){
957  istd::CIndex2d matrix2Index;
958  for (matrix2Index[0] = 0; matrix2Index[0] < Height; ++matrix2Index[0]){
959  matrix2Index[1] = hhIndex;
960  double dotProduct = matrixQPtr->GetAt(matrix2Index) * hhVector0;
961  for (++matrix2Index[1]; matrix2Index[1] < Height; ++matrix2Index[1]){
962  dotProduct += matrixQPtr->GetAt(matrix2Index) * result[istd::CIndex2d(hhIndex, matrix2Index[1])];
963  }
964 
965  double reflexionFactor = 2 * dotProduct / hhVectorNorm2;
966  matrix2Index[1] = hhIndex;
967  matrixQPtr->GetAtRef(matrix2Index) -= hhVector0 * reflexionFactor;
968  for (matrix2Index[1]++; matrix2Index[1] < Height; ++matrix2Index[1]){
969  matrixQPtr->GetAtRef(matrix2Index) -= result.GetAt(istd::CIndex2d(hhIndex, matrix2Index[1])) * reflexionFactor;
970  }
971  }
972  }
973 
974  // correct current column
975  result.SetAt(istd::CIndex2d(hhIndex, hhIndex), -hhLength);
976  for (int i = hhIndex + 1; i < Height; ++i){
977  result.SetAt(istd::CIndex2d(hhIndex, i), 0);
978  }
979  }
980 
981  return true;
982 }
983 
984 
985 template <int Width, int Height, typename Element>
987 {
988  bool retVal = true;
989 
990  static iser::CArchiveTag sizeTag("Size", "Size of matrix", iser::CArchiveTag::TT_GROUP);
991  static iser::CArchiveTag cellsTag("Cells", "Values of matrix cells", iser::CArchiveTag::TT_GROUP);
992 
993  retVal = retVal && archive.BeginTag(sizeTag);
994  if (archive.IsStoring()){
995  int width = Width;
996  int height = Height;
997 
998  retVal = retVal && archive.Process(width);
999  retVal = retVal && archive.Process(height);
1000  }
1001  else{
1002  int width = 0;
1003  int height = 0;
1004 
1005  retVal = retVal && archive.Process(width);
1006  retVal = retVal && archive.Process(height);
1007 
1008  if (!retVal || (width != Width) || (height != Height)){
1009  return false;
1010  }
1011  }
1012 
1013  retVal = retVal && archive.EndTag(sizeTag);
1014 
1015  retVal = retVal && archive.BeginTag(cellsTag);
1016  for (int y = 0; y < Height; ++y){
1017  for (int x = 0; x < Width; ++x){
1018  retVal = retVal && archive.Process(m_elements[x][y]);
1019  }
1020  }
1021  retVal = retVal && archive.EndTag(cellsTag);
1022 
1023  return retVal;
1024 }
1025 
1026 
1027 template <int Width, int Height, typename Element>
1029 {
1030  for (int x = 0; x < Width; ++x){
1031  for (int y = 0; y < Height; ++y){
1032  if (m_elements[x][y] != matrix.m_elements[x][y]){
1033  return false;
1034  }
1035  }
1036  }
1037 
1038  return true;
1039 }
1040 
1041 
1042 template <int Width, int Height, typename Element>
1044 {
1045  for (int x = 0; x < Width; ++x){
1046  for (int y = 0; y < Height; ++y){
1047  if (m_elements[x][y] != matrix.m_elements[x][y]){
1048  return true;
1049  }
1050  }
1051  }
1052 
1053  return false;
1054 }
1055 
1056 
1057 template <int Width, int Height, typename Element>
1059 {
1060  return m_elements[index[0]][index[1]];
1061 }
1062 
1063 
1064 template <int Width, int Height, typename Element>
1066 {
1067  return m_elements[index[0]][index[1]];
1068 }
1069 
1070 
1071 } // namespace imath
1072 
1073 
1074 #endif // !imath_TMatrix_included
1075 
1076 
const ElementType & GetAt(const IndexType &index) const
Get element stored at specified index.
Definition: TMatrix.h:623
All elements initialized to 0.
Definition: TMatrix.h:41
TMatrix< Height, Width, Element > GetTransposed() const
Get transposed matrix.
Definition: TMatrix.h:342
double GetFrobeniusNorm() const
Definition: TMatrix.h:817
bool SetSizes(const SizesType &sizes)
Set list of all sizes.
Definition: TMatrix.h:584
virtual bool IsStoring() const =0
Check if this archive is loading or storing.
void SetAt(const IndexType &index, const ElementType &value)
Set element at specified index.
Definition: TMatrix.h:651
bool SetSize(int dimension, int size)
Set size of array for specified dimension.
Definition: TMatrix.h:607
const ElementType & operator[](const IndexType &index) const
Definition: TMatrix.h:1058
void GetRowVector(int rowIndex, TVector< Width, Element > &result)
Get single row as vector.
Definition: TMatrix.h:893
Index implementation for addressing elements in 2D-space.
Definition: CIndex2d.h:20
CVarMatrix operator*(double value, const imath::CVarMatrix &matrix)
Definition: CVarMatrix.h:282
TMatrix< Width, Height, Element > & operator*=(double value)
Definition: TMatrix.h:437
virtual bool Process(bool &value)=0
Process primitive type.
virtual bool BeginTag(const CArchiveTag &tag)=0
Begin of archive tag.
TMatrix< SecondWidth, Height, Element > operator*(const TMatrix< SecondWidth, Width, Element > &matrix) const
Definition: TMatrix.h:311
void SetColumnVector(int columnIndex, const TVector< Height, Element > &columnVector)
Set a single column vector to matrix.
Definition: TMatrix.h:881
Normal tag used for grouping of tags or processed elements.
Definition: CArchiveTag.h:37
bool SetDimensionsCount(int count)
Set number of dimensions of this array.
Definition: TMatrix.h:568
const SizesType & GetSizes() const
Get list of all sizes.
Definition: TMatrix.h:575
TMatrix< Width, Height, Element > & operator-=(const TMatrix< Width, Height, Element > &matrix)
Definition: TMatrix.h:428
Represent input/output persistence archive.
Definition: IArchive.h:30
void Transpose()
Transpose matrix.
Definition: TMatrix.h:353
Implementation of fixed-size mathematical vector with specified type of elements. ...
Definition: TVector.h:27
bool GetDecompositionQDQ(TMatrix< Height, Height, Element > &matrixQ, TVector< Height, Element > &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...
Definition: TMatrix.h:824
TMatrix< Width, Height, Element > & operator+=(const TMatrix< Width, Height, Element > &matrix)
Definition: TMatrix.h:419
Upper triangle matrix.
Definition: TMatrix.h:53
Downer triangle matrix.
Definition: TMatrix.h:57
imath::TVector< Height, Element > ColumnVector
Definition: TMatrix.h:33
int GetDimensionsCount() const
Get number of dimensions of this array.
Definition: TMatrix.h:561
TMatrix< SecondWidth, Height, Element > GetMultiplied(const TMatrix< SecondWidth, Width, Element > &matrix) const
Get result of multiplication of two matrices.
Definition: TMatrix.h:213
double GetTrace() const
Get trace of this matrix.
Definition: TMatrix.h:788
TMatrix()
Create matrix without initialization.
Definition: TMatrix.h:455
#define NULL
Definition: istd.h:64
bool GetTriangleDecomposed(TMatrix< Width, Height, Element > &result, TMatrix< Height, Height, Element > *matrixQPtr=NULL, int maxColumns=-1, double minHhNorm=I_BIG_EPSILON) const
Transform matrix to upper triangle form using method of Householder reflexions.
Definition: TMatrix.h:904
void GetAdded(const TMatrix< Width, Height, Element > &matrix, TMatrix< Width, Height, Element > &result) const
Get sum of two matrices.
Definition: TMatrix.h:730
Element ElementType
Definition: TMatrix.h:32
void GetNegated(TMatrix< Width, Height, Element > &result)
Get result matrix with negated all elements.
Definition: TMatrix.h:719
void GetMultiplied(const TMatrix< SecondWidth, Width, Element > &matrix, TMatrix< SecondWidth, Height, Element > &result) const
Get result of multiplication of two matrices.
Definition: TMatrix.h:195
bool IsDimensionsCountFixed() const
Check, if number dimensions is fixed.
Definition: TMatrix.h:554
istd::CIndex2d IndexType
Definition: TMatrix.h:30
double GetFrobeniusNorm2() const
Definition: TMatrix.h:802
bool operator==(const TMatrix< Width, Height, Element > &matrix) const
Definition: TMatrix.h:1028
double GetMinElement() const
Definition: TMatrix.h:700
Definition of mathematical matrix with fixed dimensions.
Definition: TMatrix.h:27
static const double I_BIG_EPSILON
Definition: istd.h:26
void Clear()
Set all matrix cells to zero.
Definition: TMatrix.h:547
void GetSubstracted(const TMatrix< Width, Height, Element > &matrix, TMatrix< Width, Height, Element > &result) const
Get result of substraction of two matrices.
Definition: TMatrix.h:741
void InitToIdentity()
Create identity matrix.
Definition: TMatrix.h:665
Identity matrix.
Definition: TMatrix.h:49
Process tag used to group data in archive stream.
Definition: CArchiveTag.h:21
ElementType & GetAtRef(const IndexType &index)
Get reference to element stored at specified index.
Definition: TMatrix.h:637
virtual bool EndTag(const CArchiveTag &tag)=0
End of archive tag.
double GetMaxElement() const
Definition: TMatrix.h:681
void GetColumnVector(int columnIndex, TVector< Height, Element > &result)
Get single column as vector.
Definition: TMatrix.h:869
TMatrix< Width, Height, Element > operator-()
Definition: TMatrix.h:397
istd::CIndex2d SizesType
Definition: TMatrix.h:31
All elements initialized to 1.
Definition: TMatrix.h:45
int GetSize(int dimension) const
Get size of array for specified dimension.
Definition: TMatrix.h:591
bool operator!=(const TMatrix< Width, Height, Element > &matrix) const
Definition: TMatrix.h:1043
void GetScaled(double value, TMatrix< Width, Height, Element > &result) const
Get result of multiplication of this matrix with scalar value.
Definition: TMatrix.h:766
void Reset()
Set all matrix cells to zero.
Definition: TMatrix.h:536
bool Serialize(iser::IArchive &archive)
Definition: TMatrix.h:986
TMatrix< Width, Height, Element > operator+(const TMatrix< Width, Height, Element > &matrix) const
Definition: TMatrix.h:375
imath::TVector< Width, Element > RowVector
Definition: TMatrix.h:34

© 2007-2017 Witold Gantzke and Kirill Lepskiy