Subversion Repositories gelsvn

Rev

Rev 44 | Rev 89 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 44 Rev 45
Line 11... Line 11...
11
      square matrices. To express this in the class hierarchy,
11
      square matrices. To express this in the class hierarchy,
12
      ArithSqMatFloat was created. ArithSqMatFloat is derived from ArithMat
12
      ArithSqMatFloat was created. ArithSqMatFloat is derived from ArithMat
13
      and contains a few extra facilities applicable only to
13
      and contains a few extra facilities applicable only to
14
      square matrices.
14
      square matrices.
15
  */
15
  */
16
  template <class VT, class MT, int ROWS>
16
  template <class VT, class MT, unsigned int ROWS>
17
    class ArithSqMatFloat: public ArithMatFloat<VT,VT,MT,ROWS> 
17
    class ArithSqMatFloat: public ArithMatFloat<VT,VT,MT,ROWS> 
18
    { 
18
    { 
19
    public:
19
    public:
20
 
20
 
21
      /// Vector type
21
      /// Vector type
Line 61... Line 61...
61
	  return ArithMatFloat<VT,VT,MT,ROWS>::operator*=(k);
61
	  return ArithMatFloat<VT,VT,MT,ROWS>::operator*=(k);
62
	}
62
	}
63
 
63
 
64
      void identity()
64
      void identity()
65
	{
65
	{
66
	  for(int i=0;i<ROWS;++i)
66
	  for(unsigned int i=0;i<ROWS;++i)
67
	    {
67
	    {
68
	      for(int j=0;j<ROWS;++j)
68
	      for(unsigned int j=0;j<ROWS;++j)
69
		(*this)[i][j] = ScalarType(0);
69
		(*this)[i][j] = ScalarType(0);
70
	      (*this)[i][i] = ScalarType(1);
70
	      (*this)[i][i] = ScalarType(1);
71
	    }
71
	    }
72
	}
72
	}
73
 
73
 
74
		
74
		
75
    };
75
    };
76
 
76
 
77
  /** Multiply two matrices derived from same type, 
77
  /** Multiply two matrices derived from same type, 
78
      producing a new of same type */
78
      producing a new of same type */
79
  template <class VT, class MT, int ROWS>
79
  template <class VT, class MT, unsigned int ROWS>
80
    inline MT operator*(const ArithSqMatFloat<VT,MT,ROWS>& m1,
80
    inline MT operator*(const ArithSqMatFloat<VT,MT,ROWS>& m1,
81
			const ArithSqMatFloat<VT,MT,ROWS>& m2) 
81
			const ArithSqMatFloat<VT,MT,ROWS>& m2) 
82
    {
82
    {
83
      MT n;
83
      MT n;
84
      for(int i=0;i<ROWS;i++)
84
      for(unsigned int i=0;i<ROWS;i++)
85
	for(int j=0;j<ROWS;j++)
85
	for(unsigned int j=0;j<ROWS;j++)
86
	  {
86
	  {
87
	    n[i][j] = 0;
87
	    n[i][j] = 0;
88
	    for(int k=0;k<ROWS;k++)
88
	    for(unsigned int k=0;k<ROWS;k++)
89
	      n[i][j] += m1[i][k] * m2[k][j]; 
89
	      n[i][j] += m1[i][k] * m2[k][j]; 
90
	  }
90
	  }
91
      return n;
91
      return n;
92
    }
92
    }
93
 
93
 
94
  /** Compute the transpose of a square matrix. This function returns
94
  /** Compute the transpose of a square matrix. This function returns
95
      the transpose of its argument. */
95
      the transpose of its argument. */
96
  template <class VT, class MT, int ROWS>
96
  template <class VT, class MT, unsigned int ROWS>
97
    inline MT transpose(const ArithSqMatFloat<VT,MT,ROWS>& m) 
97
    inline MT transpose(const ArithSqMatFloat<VT,MT,ROWS>& m) 
98
    {
98
    {
99
      MT m_new;
99
      MT m_new;
100
      for(int i=0;i<MT::get_v_dim();i++)
100
      for(unsigned int i=0;i<MT::get_v_dim();i++)
101
	for(int j=0;j<MT::get_h_dim();j++)
101
	for(unsigned int j=0;j<MT::get_h_dim();j++)
102
	  m_new[i][j] = m[j][i];
102
	  m_new[i][j] = m[j][i];
103
      return m_new;
103
      return m_new;
104
    }
104
    }
105
 
105
 
106
  /// Compute trace. Works only for sq. matrices.
106
  /// Compute trace. Works only for sq. matrices.
107
  template <class VT, class MT, int ROWS>
107
  template <class VT, class MT, unsigned int ROWS>
108
    inline typename MT::ScalarType trace(const ArithSqMatFloat<VT,MT,ROWS>& M)
108
    inline typename MT::ScalarType trace(const ArithSqMatFloat<VT,MT,ROWS>& M)
109
    {
109
    {
110
      typename ArithSqMatFloat<VT,MT,ROWS>::ScalarType s=0;
110
      typename ArithSqMatFloat<VT,MT,ROWS>::ScalarType s=0;
111
      for(int i=0;i<ROWS;i++)
111
      for(unsigned int i=0;i<ROWS;i++)
112
	s += M[i][i];
112
	s += M[i][i];
113
      return s;
113
      return s;
114
    }
114
    }
115
 
115
 
116
}
116
}