1 #ifndef SELDON_FILE_TINY_MATRIX_HXX
3 #include "vector/TinyVector.hxx"
5 #include "TinyMatrixExpression.hxx"
10 template<
class T,
class Prop,
int m_,
int n_>
15 template<
class Prop,
int m,
int n,
int p>
24 template<
int p,
int q>
27 template<
int p,
int q,
int r>
36 template <
class T,
int m,
int n>
43 template<
int p,
int q>
46 template<
int p,
int q,
int r>
77 template<
class T1,
class E>
81 template<
class T1,
class E>
88 template<
class T0,
class E>
91 T& operator()(
int i,
int j);
92 const T& operator()(
int i,
int j)
const;
99 void SetDiagonal(
const T0& a);
105 void Fill(
const T0& a);
109 void Write(
const string& file_name)
const;
110 void Write(ostream& out)
const;
115 template<
int m,
int n,
int p>
119 enum{ i = p/n, j = p%n };
124 template<
int m,
int p>
142 enum { i = 0, j = 0};
150 template<
int p,
int q,
int r>
154 template<
class T,
int m>
157 template<
class T,
int m>
164 template<
int p,
int q>
168 template<
class T,
int m>
171 template<
class T,
int m>
173 T& invVal, T& vloc) {}
178 template<
int p,
int q>
182 template<
int m,
int n,
class T0,
class T1>
185 template<
int m,
int n,
class T,
class E>
188 template<
int m,
int n,
class T,
class Prop>
191 template<
int m,
int n,
class T,
class E1,
class E2>
195 template<
int m,
int n,
class T0,
class E0,
class T1,
class E1,
class T2>
200 template<
int m,
int n,
int k,
class T0,
class E0,
201 class T1,
class E1,
class T2,
class Prop2>
206 template<
int m,
int n,
class T0,
class T1,
class E1,
class T2,
class E2,
class T3>
210 template<
int m,
int n,
class T1,
class E1,
class T2,
class E2,
class T3>
214 template<
int m,
class T0,
class T1,
class E1,
class T3>
218 template<
int m,
class T1,
class E1,
class T3>
222 template<
class T,
int m>
225 template<
class T,
int m>
228 template<
class T,
int m>
231 template<
class T,
int m>
234 template<
class T,
int m>
236 const T& coef, T& val);
238 template<
class T,
int m>
241 template<
class T,
int m>
244 template<
class T,
int m>
248 template<
class T,
class T2,
int m>
253 template<
class T,
class T2,
int m>
258 template<
class T,
class T2,
int m>
263 template<
class T,
class T2,
int m>
276 template<
int m,
int n,
class T0,
class T1>
280 template<
int m,
int n,
class T,
class E>
283 template<
int m,
int n,
class T,
class Prop>
286 template<
int m,
int n,
class T,
class E1,
class E2>
290 template<
int m,
int n,
class T0,
class E0,
class T1,
class E1,
class T2>
295 template<
int m,
int n,
int k,
class T0,
class E0,
296 class T1,
class E1,
class T2,
class Prop2>
301 template<
int m,
int n,
class T0,
class T1,
class E1,
class T2,
class E2,
class T3>
307 template<
int m,
int n,
class T1,
class E1,
class T2,
class E2,
class T3>
313 template<
int m,
class T0,
class T1,
class E1,
class T3>
318 template<
int m,
class T1,
class E1,
class T3>
323 template<
class T,
int m>
326 template<
class T,
int m>
329 template<
class T,
int m>
332 template<
class T,
int m>
335 template<
class T,
int m>
337 const T& coef, T& val) {}
339 template<
class T,
int m>
342 template<
class T,
int m>
345 template<
class T,
int m>
347 T& invVal, T& vloc) {}
349 template<
class T,
class T2,
int m>
354 template<
class T,
class T2,
int m>
359 template<
class T,
class T2,
int m>
364 template<
class T,
class T2,
int m>
376 template<
int m,
int n,
class T0,
class Prop>
379 template<
int m,
int n,
class T0,
class T1>
383 template<
int m,
int n,
class T0,
class Prop,
class T1>
386 template<
int m,
int n,
class T1,
class E,
class T0,
class Prop>
390 template<
int m,
int n,
class T1,
class E,
class T0,
class Prop>
394 template<
int m,
int n,
class T1,
class E,
class T0,
class Prop>
398 template<
int m,
int n,
class T,
class Prop>
401 template<
int m,
int n,
class T,
class Prop,
class T0>
404 template<
int m,
int n,
class T,
class Prop>
407 template<
int m,
int n,
class T,
class Prop>
410 template<
int m,
int n,
class T,
class Prop,
class T0>
413 template<
int m,
int n,
class Prop,
class T>
416 template<
int m,
int n,
class T,
class E>
419 template<
int m,
int n,
class T,
class Prop>
422 template<
int m,
int n,
class T,
class E1,
class E2>
426 template<
int m,
int n,
class T0,
class E0,
class T1,
class E1,
class T2>
431 template<
int m,
int n,
class T0,
class E0,
class T1,
class E1,
class T2>
435 template<
int m,
int n,
class T0,
class E0,
class T1,
class E1,
class T2,
class T3>
439 template<
int m,
int n,
int k,
class T0,
class E0,
440 class T1,
class E1,
class T2,
class Prop2>
445 template<
int m,
int n,
class T0,
class T1,
class E1,
class T2,
class E2,
class T3>
450 template<
int m,
int n,
class T1,
class E1,
class T2,
class E2,
class T3>
455 template<
int m,
class T0,
class T1,
class E1,
class T3>
459 template<
int m,
class T1,
class E1,
class T3>
463 template<
int m,
int n,
class T1,
class E1>
467 template<
int m,
int n,
class T0,
class E0,
class T1>
471 template<
int m,
int n,
class T1,
class E1,
class Prop>
475 template<
int m,
int n,
class T1,
class E1,
class Prop>
479 template<
int m,
int n,
class T,
class Prop,
class T0>
482 template<
class T,
int m>
485 template<
class T,
int m>
488 template<
class T,
int m>
491 template<
class T,
int m>
494 template<
class T,
class T2,
int m>
499 template<
class T,
class T2,
int m>
504 template<
class T,
class T2,
int m>
509 template<
class T,
class T2,
int m>
521 template<
int m,
int n,
class T0,
class Prop>
524 template<
int m,
int n,
class T0,
class T1>
528 template<
int m,
int n,
class T0,
class Prop,
class T1>
531 template<
int m,
int n,
class T1,
class E,
class T0,
class Prop>
535 template<
int m,
int n,
class T1,
class E,
class T0,
class Prop>
539 template<
int m,
int n,
class T1,
class E,
class T0,
class Prop>
543 template<
int m,
int n,
class T,
class Prop>
546 template<
int m,
int n,
class T,
class Prop,
class T0>
549 template<
int m,
int n,
class T,
class Prop>
552 template<
int m,
int n,
class T,
class Prop>
555 template<
int m,
int n,
class T,
class Prop,
class T0>
558 template<
int m,
int n,
class Prop,
class T>
561 template<
int m,
int n,
class T,
class E>
564 template<
int m,
int n,
class T,
class Prop>
567 template<
int m,
int n,
class T,
class E1,
class E2>
572 template<
int m,
int n,
class T0,
class E0,
class T1,
class E1,
class T2>
577 template<
int m,
int n,
class T0,
class E0,
class T1,
class E1,
class T2>
581 template<
int m,
int n,
class T0,
class E0,
class T1,
class E1,
class T2,
class T3>
585 template<
int m,
int n,
int k,
class T0,
class E0,
586 class T1,
class E1,
class T2,
class Prop2>
591 template<
int m,
int n,
class T0,
class T1,
class E1,
class T2,
class E2,
class T3>
596 template<
int m,
int n,
class T1,
class E1,
class T2,
class E2,
class T3>
601 template<
int m,
class T0,
class T1,
class E1,
class T3>
605 template<
int m,
class T1,
class E1,
class T3>
609 template<
int m,
int n,
class T1,
class E1>
613 template<
int m,
int n,
class T0,
class E0,
class T1>
617 template<
int m,
int n,
class T1,
class E1,
class Prop>
621 template<
int m,
int n,
class T1,
class E1,
class Prop>
625 template<
int m,
int n,
class T,
class Prop,
class T0>
629 template<
class T,
int m>
633 template<
class T,
int m>
636 template<
class T,
int m>
640 template<
class T,
int m>
643 template<
class T,
class T2,
int m>
648 template<
class T,
class T2,
int m>
653 template<
class T,
class T2,
int m>
658 template<
class T,
class T2,
int m>
671 template <
class T,
int m>
678 template<
int p,
int q>
681 template<
int p,
int q,
int r>
689 enum{ size_ = m*(m+1)/2 };
701 static int GetSize();
709 template<
class T1,
class E>
713 template<
class T1,
class E>
720 template<
class T0,
class E>
723 T& operator()(
int i,
int j);
724 const T& operator()(
int i,
int j)
const;
731 void SetDiagonal(
const T0& alpha);
737 void Fill(
const T1& a);
741 void WriteText(
const string& file_name)
const;
742 void Write(
const string& file_name)
const;
743 void Write(ostream& out)
const;
752 template<
class T,
int m,
int n,
class E1,
class E2>
753 bool operator==(
const TinyMatrixExpression<T, m, n, E1> & u,
754 const TinyMatrixExpression<T, m, n, E2> & v);
756 template<
class T,
int m,
int n,
class E1,
class E2>
757 bool operator!=(
const TinyMatrixExpression<T, m, n, E1> & u,
758 const TinyMatrixExpression<T, m, n, E2> & v);
760 template <
class T,
int m,
int n,
class E>
761 ostream&
operator <<(ostream& out,
const TinyMatrixExpression<T, m, n, E> & A);
769 template<
class T,
int m,
int n,
class E,
class T1,
class E1> TinyVector<T1, m>
770 dot(
const TinyMatrixExpression<T, m, n, E>& A,
771 const TinyVectorExpression<T1, n, E1>& x);
774 template<
class T,
int m,
int n,
class E,
class T1,
int k,
class E1>
775 TinyMatrix<T, General, m, k>
776 dot(
const TinyMatrixExpression<T, m, n, E>& A,
777 const TinyMatrixExpression<T1, n, k, E1> & B);
780 template<
class T0,
class E0,
class T1,
class E1,
class T2,
int m,
int n>
781 void Mlt(
const TinyMatrixExpression<T0, m, n, E0>& A,
782 const TinyVectorExpression<T1, n, E1>& x, TinyVector<T2, m>& y);
785 template<
class T1,
class E1,
class T2,
class E2,
class T3,
int m,
int n>
786 void MltAdd(
const TinyMatrixExpression<T1, m, n, E1>& A,
787 const TinyVectorExpression<T2, n, E2>& x, TinyVector<T3, m>& y);
790 template<
class T0,
class T1,
class E1,
class T2,
class E2,
791 class T3,
int m,
int n>
792 void MltAdd(
const T0& alpha,
const TinyMatrixExpression<T1, m, n, E1>& A,
793 const TinyVectorExpression<T2, n, E2>& x, TinyVector<T3, m>& y);
795 template<
class T0,
class E0,
class T1,
class E1,
class T2,
int m,
int n>
796 void MltTrans(
const TinyMatrixExpression<T0, m, n, E0>& A,
797 const TinyVectorExpression<T1, m, E1>& x, TinyVector<T2, n>& y);
799 template<
class T0,
class E0,
class T1,
class E1,
class T2,
int m,
int n>
800 void Mlt(
const class_SeldonTrans&,
801 const TinyMatrixExpression<T0, m, n, E0>& A,
802 const TinyVectorExpression<T1, m, E1>& x, TinyVector<T2, n>& y);
804 template<
int m,
int n,
class T0,
class T1,
class E1,
805 class T2,
class E2,
class T3>
806 void Rank1Update(
const T0& alpha,
const TinyVectorExpression<T1, m, E1>& x,
807 const TinyVectorExpression<T2, n, E2>& y, TinyMatrix<T3, General, m, n>& A);
809 template<
int m,
int n,
class T1,
class E1,
class T2,
class E2,
class T3>
810 void Rank1Matrix(
const TinyVectorExpression<T1, m, E1>& x,
811 const TinyVectorExpression<T2, n, E2>& y, TinyMatrix<T3, General, m, n>& A);
813 template<
int m,
class T0,
class T1,
class E1,
class T3>
814 void Rank1Update(
const T0& alpha,
const TinyVectorExpression<T1, m, E1>& x,
815 TinyMatrix<T3, Symmetric, m, m>& A);
817 template<
int m,
class T1,
class E1,
class T3>
818 void Rank1Matrix(
const TinyVectorExpression<T1, m, E1>& x,
819 TinyMatrix<T3, Symmetric, m, m>& A);
821 template<
int m,
int n,
class T1,
class E1>
822 void GetCol(
const TinyMatrixExpression<T1, m, n, E1>& A,
int k, TinyVector<T1, m>& x);
824 template<
int m,
int n,
class T0,
class E0,
class T1>
825 void GetRow(
const TinyMatrixExpression<T0, m, n, E0>& A,
int k, TinyVector<T1, n>& x);
827 template<
int m,
int n,
class T1,
class E1,
class Prop>
828 void SetCol(
const TinyVectorExpression<T1, m, E1>& x,
int k, TinyMatrix<T1, Prop, m, n>& A);
830 template<
int m,
int n,
class T1,
class E1,
class Prop>
831 void SetRow(
const TinyVectorExpression<T1, n, E1>& x,
int k, TinyMatrix<T1, Prop, m, n>& A);
839 template<
class T,
int m,
int n,
class E,
class Prop>
840 void Copy(
const TinyMatrixExpression<T, m, n, E>& A, TinyMatrix<T, Prop, m, n>& B);
843 template<
class T0,
class E0,
class T1,
class E1,
844 class T2,
class Prop2,
int m,
int n>
845 void Add(
const TinyMatrixExpression<T0, m, n, E0>& A,
846 const TinyMatrixExpression<T1, m, n, E1>& B, TinyMatrix<T2, Prop2, m, n>& C);
849 template<
class T1,
class E1,
class T2,
class Prop2,
int m,
int n>
850 void Add(
const T1& alpha,
const TinyMatrixExpression<T1, m, n, E1>& A,
851 TinyMatrix<T2, Prop2, m, n>& B);
854 template<
class T0,
class E0,
class T1,
class Prop1,
int m,
int n>
855 void Add(
const TinyMatrixExpression<T0, m, n, E0>& A, TinyMatrix<T1, Prop1, m, n>& B);
858 template<
class T0,
class T1,
class Prop,
int m,
int n>
859 void Mlt(
const T0& alpha, TinyMatrix<T1, General, m, n>& A);
862 template<
class T0,
class E0,
class T1,
class E1,
863 class T2,
class Prop2,
int m,
int n,
int k>
864 void Mlt(
const TinyMatrixExpression<T0, m, n, E0>& A,
865 const TinyMatrixExpression<T1, n, k, E1>& B,
866 TinyMatrix<T2, Prop2, m, k>& C);
869 template<
class T0,
class E0,
class T1,
class E1,
870 class T2,
class Prop2,
int m,
int n,
int k>
871 void MltTrans(
const TinyMatrixExpression<T0, m, n, E0>& A,
872 const TinyMatrixExpression<T1, k, n, E1>& B, TinyMatrix<T2, Prop2, m, k>& C);
874 template<
class T3,
class T0,
class E0,
class T1,
class E1,
875 class T2,
class Prop2,
class T4,
int m,
int n,
int k>
876 void MltAdd(
const T3& alpha,
const class_SeldonTrans&,
877 const TinyMatrixExpression<T0, n, m, E0>& A,
878 const class_SeldonNoTrans&,
const TinyMatrixExpression<T1, n, k, E1>& B,
879 const T4& beta, TinyMatrix<T2, Prop2, m, k>& C);
881 template<
class T,
int m,
int n,
class E>
882 void Transpose(
const TinyMatrixExpression<T, m, n, E> & A, TinyMatrix<T, General, n, m> & B);
884 template<
class T,
int m>
885 void Transpose(TinyMatrix<T, General, m, m> & B);
887 template<
class T,
class Prop,
int m,
int n>
888 typename ClassComplexType<T>::Treal
MaxAbs(
const TinyMatrix<T, Prop, m, n>& A);
895 template<
class T,
class Prop>
896 T Det(
const TinyMatrix<T, Prop, 1, 1> & A);
899 void GetInverse(
const TinyMatrix<T, General, 1, 1> & A,
900 TinyMatrix<T, General, 1, 1> & B);
903 void GetInverse(
const TinyMatrix<T, Symmetric, 1, 1> & A,
904 TinyMatrix<T, Symmetric, 1, 1> & B);
907 void GetInverse(TinyMatrix<T, General, 1, 1> & B);
910 void GetInverse(TinyMatrix<T, Symmetric, 1, 1> & B);
912 template<
class T0,
class T1>
913 void GetNormalProjector(
const TinyVector<T0, 1>& n, TinyMatrix<T1, Symmetric, 1, 1>& P);
915 template<
class T0,
class T1>
916 void GetNormalProjector(
const T0& n, TinyMatrix<T1, Symmetric, 1, 1>& P);
925 template<
class T,
class Prop>
926 T Det(
const TinyMatrix<T, Prop, 2, 2> & A);
928 template<
class T0,
class T1>
929 void GetTangentialProjector(
const TinyVector<T0, 2>& n,
930 TinyMatrix<T1, Symmetric, 2, 2>& P);
932 template<
class T0,
class T1>
933 void GetNormalProjector(
const TinyVector<T0, 2>& n, TinyMatrix<T1, Symmetric, 2, 2>& P);
935 template<
class T0,
class T1>
936 void GetNormalProjector(
const TinyVector<T0, 2>& n, TinyMatrix<T1, General, 2, 2>& P);
940 void GetInverse(
const TinyMatrix<T, General, 2, 2> & A, TinyMatrix<T, General, 2, 2> & B);
943 void GetInverse(TinyMatrix<T, General, 2, 2> & B);
946 void GetInverse(
const TinyMatrix<T, Symmetric, 2, 2> & A,
947 TinyMatrix<T, Symmetric, 2, 2> & B);
950 void GetInverse(TinyMatrix<T, Symmetric, 2, 2> & B);
954 void GetEigenvalues(TinyMatrix<T, General, 2, 2>& A,
955 TinyVector<T, 2> & LambdaR, TinyVector<T, 2>& LambdaI);
958 void GetEigenvalues(TinyMatrix<complex<T>, General, 2, 2>& A,
959 TinyVector<complex<T>, 2> & Lambda);
971 template<
class T,
class Prop>
972 T Det(
const TinyMatrix<T, Prop, 3, 3> & A);
975 void GetInverse(
const TinyMatrix<T, General, 3, 3> & A,
976 TinyMatrix<T, General, 3, 3> & B);
979 void GetInverse(TinyMatrix<T, General, 3, 3> & B);
982 void GetInverse(
const TinyMatrix<T, Symmetric, 3, 3> & A,
983 TinyMatrix<T, Symmetric, 3, 3> & B);
986 void GetInverse(TinyMatrix<T, Symmetric, 3, 3> & B);
988 template<
class T0,
class T1>
989 void GetTangentialProjector(
const TinyVector<T0, 3>& n,
990 TinyMatrix<T1, Symmetric, 3, 3>& P);
992 template<
class T0,
class T1>
993 void GetNormalProjector(
const TinyVector<T0, 3>& n,
994 TinyMatrix<T1, Symmetric, 3, 3>& P);
996 template<
class T0,
class T1>
997 void GetNormalProjector(
const TinyVector<T0, 3>& n,
998 TinyMatrix<T1, General, 3, 3>& P);
1006 template<
class T0,
class T1,
int m>
1007 void GetTangentialProjector(
const TinyVector<T0, m>& n,
1008 TinyMatrix<T1, Symmetric, m, m>& P);
1010 template<
class T0,
class T1,
int m>
1011 void GetNormalProjector(
const TinyVector<T0, m>& n,
1012 TinyMatrix<T1, Symmetric, m, m>& P);
1014 template<
class T,
class Prop,
int m,
int n>
1015 void FillZero(TinyMatrix<T, Prop, m, n>& X);
1018 template<
class T,
int m,
int n>
1019 void DotProdCol(
const TinyMatrix<T, General, m, n>& A,
1020 const TinyMatrix<T, General, m, n>& B, TinyVector<T, n>& res);
1023 template<
class T,
class Property,
int m,
int n>
1024 typename ClassComplexType<T>::Treal
1025 Norm2_Column(
const TinyMatrix<T, Property, m, n>& A,
1026 int first_row,
int index_col);
1028 template<
class T,
class Property,
class Storage,
class Allocator>
1029 typename ClassComplexType<T>::Treal
1030 Norm2_Column(
const Matrix<T, Property, Storage, Allocator>& A,
1031 int first_row,
int index_col);
1033 template<
class T,
int m>
1034 void GetInverse(TinyMatrix<T, General, m, m>& A);
1036 template<
class T,
int m>
1037 void GetInverse(
const TinyMatrix<T, General, m, m>& A,
1038 TinyMatrix<T, General, m, m>& B);
1040 template<
class T,
int m>
1041 void GetInverse(TinyMatrix<T, Symmetric, m, m> & A);
1043 template<
class T,
int m>
1044 void GetInverse(
const TinyMatrix<T, Symmetric, m, m>& A,
1045 TinyMatrix<T, Symmetric, m, m>& B);
1047 template<
class T,
int m>
1048 void GetCholesky(TinyMatrix<T, Symmetric, m, m>& A);
1050 template<
class T,
class T2,
int m>
1051 void SolveCholesky(
const class_SeldonNoTrans& trans,
1052 const TinyMatrix<T, Symmetric, m, m>& A,
1053 TinyVector<T2, m>& x);
1055 template<
class T,
class T2,
int m>
1056 void SolveCholesky(
const class_SeldonTrans& trans,
1057 const TinyMatrix<T, Symmetric, m, m>& A,
1058 TinyVector<T2, m>& x);
1060 template<
class T,
class T2,
int m>
1061 void MltCholesky(
const class_SeldonNoTrans& trans,
1062 const TinyMatrix<T, Symmetric, m, m>& A,
1063 TinyVector<T2, m>& x);
1065 template<
class T,
class T2,
int m>
1066 void MltCholesky(
const class_SeldonTrans& trans,
1067 const TinyMatrix<T, Symmetric, m, m>& A,
1068 TinyVector<T2, m>& x);
1070 template<
int m,
class T>
1071 void GetEigenvaluesEigenvectors(TinyMatrix<T, Symmetric, m, m>& A,
1072 TinyVector<T, m>& w,
1073 TinyMatrix<T, General, m, m>& z);
1075 template<
int m,
class T>
1076 void GetEigenvalues(TinyMatrix<T, Symmetric, m, m>& A,
1077 TinyVector<T, m>& w);
1079 template<
class T,
int m>
1085 #define SELDON_FILE_TINY_MATRIX_HXX