GEL
2
GEL is a library for Geometry and Linear Algebra
|
00001 #ifndef __CGLA_ARITHSQMATFLOAT_H__ 00002 #define __CGLA_ARITHSQMATFLOAT_H__ 00003 00004 #include "ArithMatFloat.h" 00005 00006 namespace CGLA 00007 { 00008 00017 template <class VT, class MT, unsigned int ROWS> 00018 class ArithSqMatFloat: public ArithMatFloat<VT,VT,MT,ROWS> 00019 { 00020 public: 00021 00023 typedef VT VectorType; 00024 00026 typedef typename VT::ScalarType ScalarType; 00027 00028 protected: 00029 00031 ArithSqMatFloat() {} 00032 00034 explicit ArithSqMatFloat(ScalarType _a): 00035 ArithMatFloat<VT,VT,MT,ROWS>(_a) {} 00036 00038 ArithSqMatFloat(VT _a, VT _b): 00039 ArithMatFloat<VT,VT,MT,ROWS>(_a,_b) {} 00040 00042 ArithSqMatFloat(VT _a, VT _b, VT _c): 00043 ArithMatFloat<VT,VT,MT,ROWS>(_a,_b,_c) {} 00044 00046 ArithSqMatFloat(VT _a, VT _b, VT _c, VT _d): 00047 ArithMatFloat<VT,VT,MT,ROWS>(_a,_b,_c,_d) {} 00048 00049 public: 00050 00054 const MT& operator*=(const MT& m2) 00055 { 00056 (*this) = (*this) * m2; 00057 return static_cast<const MT&>(*this); 00058 } 00059 00060 const MT& operator *=(ScalarType k) 00061 { 00062 return ArithMatFloat<VT,VT,MT,ROWS>::operator*=(k); 00063 } 00064 00065 void identity() 00066 { 00067 for(unsigned int i=0;i<ROWS;++i) 00068 { 00069 for(unsigned int j=0;j<ROWS;++j) 00070 (*this)[i][j] = ScalarType(0); 00071 (*this)[i][i] = ScalarType(1); 00072 } 00073 } 00074 00075 00076 }; 00077 00080 template <class VT, class MT, unsigned int ROWS> 00081 inline MT operator*(const ArithSqMatFloat<VT,MT,ROWS>& m1, 00082 const ArithSqMatFloat<VT,MT,ROWS>& m2) 00083 { 00084 MT n; 00085 for(unsigned int i=0;i<ROWS;i++) 00086 for(unsigned int j=0;j<ROWS;j++) 00087 { 00088 n[i][j] = 0; 00089 for(unsigned int k=0;k<ROWS;k++) 00090 n[i][j] += m1[i][k] * m2[k][j]; 00091 } 00092 return n; 00093 } 00094 00097 template <class VT, class MT, unsigned int ROWS> 00098 inline MT transpose(const ArithSqMatFloat<VT,MT,ROWS>& m) 00099 { 00100 MT m_new; 00101 for(unsigned int i=0;i<MT::get_v_dim();i++) 00102 for(unsigned int j=0;j<MT::get_h_dim();j++) 00103 m_new[i][j] = m[j][i]; 00104 return m_new; 00105 } 00106 00108 template <class VT, class MT, unsigned int ROWS> 00109 inline typename MT::ScalarType trace(const ArithSqMatFloat<VT,MT,ROWS>& M) 00110 { 00111 typename ArithSqMatFloat<VT,MT,ROWS>::ScalarType s=0; 00112 for(unsigned int i=0;i<ROWS;i++) 00113 s += M[i][i]; 00114 return s; 00115 } 00116 00117 } 00118 #endif