![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsMatrixp.hpp 00003 00004 Matrixp class is a class for any dimension Matrixp. 00005 00006 SUKITTI PUNAK (01/19/2006) 00007 UPDATE (01/20/2006) 00008 ******************************************************************************/ 00009 #ifndef TAPs_MATRIXP_HPP 00010 #define TAPs_MATRIXP_HPP 00011 00012 #include "TAPsMath.hpp" 00013 00014 BEGIN_NAMESPACE_TAPs 00015 //============================================================================= 00016 // class forward 00017 template <typename T> class Vectorp; 00018 //============================================================================= 00019 template <typename T> 00020 class Matrixp { 00021 //============================================================================= 00022 protected: 00023 // Data Members --------------------------------------------------------------- 00024 // Matrix Elements 00025 // -- -- 00026 // | | 00027 // | R by C | 00028 // | | 00029 // -- -- 00030 int R, C; 00031 T *e; 00032 public: 00033 //------------------------------------------------------------------------- 00034 // Output Operator << 00035 friend std::ostream &operator<<( std::ostream &output, const Matrixp<T> &M ) 00036 { 00037 /* 00038 //output << typeid(*this).name() << "( "; 00039 output << "Matrixp<" << typeid(T).name() << ">" 00040 << " a " << M.R << "-by-" << M.C << "\n"; 00041 output.precision(10); 00042 for ( int r = 0; r < M.R*M.C; r+=M.C ) { 00043 output << "| "; 00044 for ( int c = 0; c < M.C; c++ ) { 00045 output.width( 20 ); output << M.e[r + c]; 00046 } 00047 output << " |" << endl; 00048 } 00049 output.precision(6); 00050 return output; 00051 //*/ 00052 return M.Display(); 00053 } 00054 //------------------------------------------------------------------------- 00055 // Constructors and Destructor 00056 Matrixp ( int rows = 3, int cols = 3 ); // default constructor (Identity Matrix) 00057 Matrixp ( Matrixp<T> const &M ); // copy constructor 00058 Matrixp ( int rows, int cols, T val ); // constructor 00059 Matrixp ( int rows, int cols, T const a[] );// constructor from array 00060 virtual ~Matrixp (); // destructor 00061 //------------------------------------------------------------------------- 00062 // Member Access 00063 inline T & operator[] ( int i ); 00064 inline T const & operator[] ( int i ) const; 00065 inline T & operator() ( int r, int c ); 00066 inline T const & operator() ( int r, int c ) const; 00067 //------------------------------------------------------------------------- 00068 // Convert to one dimension array 00069 operator const T *() const; 00070 operator T *(); 00071 //------------------------------------------------------------------------- 00072 // Useful Functions 00073 std::ostream & Display ( int precision = 10, std::ostream &output = std::cout ) const; 00075 int GetNumOfRows () const { return R; } 00077 int GetNumOfCols () const { return C; } 00079 void SetAllElements ( T ); 00081 void SetAllElements ( T const a[] ); 00083 void MakeIdentity (); 00085 void MakeDiagonal ( T d ); 00087 void MakeDiagonal ( T const a[] ); 00089 void MakeZero (); 00091 bool IsIdentity () const; 00093 bool IsSymmetric () const; 00095 bool IsSquare () const { return R==C; } 00096 00099 void ChangeSize( int numOfRow, int numOfCol ); 00100 //------------------------------------------------------------------------- 00101 // Matrix Operations 00102 00104 Matrixp<T> & Transposed (); 00105 00107 Matrixp<T> GetTranspose () const; 00108 00109 //Matrixp<T> & Inversed (); 00110 //Matrixp<T> GetInverse () const; 00111 //T GetDeterminant () const; 00112 //------------------------------------------------------------------------- 00113 // Assignment Overloaded Operator 00114 Matrixp<T> & operator= ( Matrixp<T> const &M ); 00115 //------------------------------------------------------------------------- 00116 // Unary Overloaded Operators 00117 Matrixp<T> operator- (); // negation 00118 //------------------------------------------------------------------------- 00119 // Assign Overloaded Operators 00120 Matrixp<T> &operator+= ( Matrixp<T> const &M ); // += with matrix 00121 Matrixp<T> &operator-= ( Matrixp<T> const &M ); // -= with matrix 00122 Matrixp<T> &operator*= ( Matrixp<T> const &M ); // *= with matrix 00123 Matrixp<T> &operator*= ( T s ); // *= with scalar 00124 Matrixp<T> &operator/= ( T s ); // /= with scalar 00125 //------------------------------------------------------------------------- 00126 // Binary Overloaded Operators 00127 Matrixp<T> operator+ ( Matrixp<T> const &M ) const; // matrix + matrix 00128 Matrixp<T> operator- ( Matrixp<T> const &M ) const; // matrix - matrix 00129 Matrixp<T> operator* ( Matrixp<T> const &M ) const; // matrix * matrix 00130 Matrixp<T> operator* ( T s ) const; // matrix * scalar 00131 friend inline Matrixp<T> operator* ( T s, Matrixp<T> const &M ) // scalar * matrix 00132 { return M * s; } 00133 Matrixp<T> operator/ ( T s ) const; // matrix / scalar 00134 inline void MultLeft ( Matrixp<T> const &M ); // this matrix = matrix M * this matrix 00135 inline void MultRight ( Matrixp<T> const &M ); // this matrix = this matrix * matrix M 00136 //------------------------------------------------------------------------- 00137 // Matrixp * Vectorp 00138 //Vectorp<T> operator* ( Vectorp<T> const &V ) const; 00139 //------------------------------------------------------------------------- 00140 // Helper Fn Member --------------------------------------------- 00141 private: 00142 bool CheckRanges ( int numOfRows, int numOfCols ) const; 00143 //void DeleteMemory (); 00144 //void CopyElements ( const Matrixp< T > & ); 00145 }; // END CLASS Matrixp 00146 //============================================================================= 00147 //----------------------------------------------------------------------------- 00148 // Define Matrixps 00149 typedef Matrixp<int> Matrixpi; 00150 typedef Matrixp<float> Matrixpf; 00151 typedef Matrixp<double> Matrixpd; 00152 typedef Matrixp<long double> Matrixpld; 00153 //============================================================================= 00154 END_NAMESPACE_TAPs 00155 //----------------------------------------------------------------------------- 00156 // Include definition if TAPs_USE_EXPORT is not defined 00157 //#if !defined( TAPs_USE_EXPORT ) 00158 #include "TAPsMatrixp.cpp" 00159 //#endif 00160 //----------------------------------------------------------------------------- 00161 #endif 00162 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00163 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 /* 00174 00175 00176 //------------------------------------------------------------------------- 00177 // Friend Functions for Operator Overloading 00178 00179 //------------------------------------------------------------------------- 00180 // Operator Overloading 00181 Matrix<T,R,C> operator*( T s ) 00182 { 00183 Matrix<T,R,C> M( *this ); 00184 M *= s; 00185 return M; 00186 } 00187 00188 friend SPtMatrix< T > operator-( const SPtMatrix< T > &A, const SPtMatrix< T > &B ) 00189 { 00190 // Both matrices have to be the same order! 00191 if ( A.m_iRows != B.m_iRows || A.m_iCols != B.m_iCols ) return NULL; 00192 00193 SPtMatrix< T > temp( A ); 00194 for ( int r = 0; r < temp.m_iRows; r++ ) { 00195 for ( int c = 0; c < temp.m_iCols; c++ ) { 00196 temp.m_tElement[r][c] -= B.m_tElement[r][c]; 00197 } 00198 } 00199 00200 return temp; 00201 } 00202 friend SPtMatrix< T > operator+( const SPtMatrix< T > &A, const SPtMatrix< T > &B ) 00203 { 00204 // Both matrices have to be the same order! 00205 if ( A.m_iRows != B.m_iRows || A.m_iCols != B.m_iCols ) return NULL; 00206 00207 SPtMatrix< T > temp( A ); 00208 for ( int r = 0; r < temp.m_iRows; r++ ) { 00209 for ( int c = 0; c < temp.m_iCols; c++ ) { 00210 temp.m_tElement[r][c] += B.m_tElement[r][c]; 00211 } 00212 } 00213 00214 return temp; 00215 } 00216 friend class MatrixOperations; 00217 00218 // Member Functions ---------------------------------------------------------- 00219 public: 00220 // Constructors ------------------------------------------------ 00221 SPtMatrix( int = 3, int = 3 ); 00222 //SPtMatrix( T **e, int r, int c ) : m_tElement< T >( e ), m_iRows( r ), m_iCols( c ) { } 00223 SPtMatrix( const SPtMatrix< T > & ); 00224 SPtMatrix( const SPtVector3< T > & ); 00225 SPtMatrix( const SPtPoint3< T > & ); 00226 ~SPtMatrix(); 00227 00228 00229 // Useful Member Functions --------------------------------- 00230 // Display Elements 00231 void DisplayElements() const; 00232 T Get( int, int ) const; 00233 void Set( int, int, T ); 00234 bool SetToIdentity(); 00235 int GetNoOfRows() const; 00236 int GetNoOfCols() const; 00237 void GetNoOfRowsAndCols( int &, int & ) const; 00238 00239 00240 // Matrix Operations ------------------------------------- 00241 SPtMatrix< T > GetTranspose() const; 00242 SPtMatrix< T > &Transpose(); 00243 00244 00245 // Overloaded Operators ------------------------------------- 00246 // assign matrix 00247 SPtMatrix< T > &operator=( const SPtMatrix< T > & ); 00248 // negation 00249 SPtMatrix< T > operator-() const; 00250 // add/assign matrix 00251 SPtMatrix< T > &operator+=( const SPtMatrix< T > & ); 00252 // subtract/assign vector v 00253 SPtMatrix< T > &operator-=( const SPtMatrix< T > & ); 00254 // multiply/assign by scalar s 00255 SPtMatrix< T > &operator*=( double ); 00256 // divide/assign by scalar s 00257 SPtMatrix< T > &operator/=( double ); 00258 00259 // multiply by a matrix 00260 SPtMatrix< T > operator*( const SPtMatrix< T > & ) const; 00261 00262 00263 // Helper Fn Member --------------------------------------------- 00264 private: 00265 bool CheckRanges( int, int ) const; 00266 void DeleteMemory(); 00267 void CopyElements( const SPtMatrix< T > & ); 00268 00269 00270 }; // END: SPtMatrix 00271 //=============================================================================================== 00272 00273 00274 //=============================================================================================== 00275 // 00276 // M E M B E R F U N C T I O N D E F I N I T I O N S 00277 // 00278 //=============================================================================================== 00279 // START: SPtMatrix Member Functions ****************************************** 00280 //------------------------------------------------------------------------------------------------ 00281 // Default Constructor 00282 template< typename T > 00283 SPtMatrix< T >::SPtMatrix( int r, int c ) : m_iRows( r ), m_iCols( c ) 00284 { 00285 m_tElement = new T*[ m_iRows ]; 00286 for ( r = 0; r < m_iRows; r++ ) { 00287 m_tElement[ r ] = new T[ m_iCols ]; 00288 for ( c = 0; c < m_iCols; c++ ) { 00289 m_tElement[r][c] = T(); 00290 } 00291 } 00292 } 00293 00294 //------------------------------------------------------------------------------------------------ 00295 // Copy Constructor 00296 template< typename T > 00297 SPtMatrix< T >::SPtMatrix( const SPtMatrix< T > &M ) 00298 { 00299 CopyElements( M ); 00300 } 00301 00302 //------------------------------------------------------------------------------------------------ 00303 // Vector3-To-Matrix Constructor 00304 template< typename T > 00305 SPtMatrix< T >::SPtMatrix( const SPtVector3< T > &V ) 00306 { 00307 SPtMatrix( 3, 1 ); 00308 this->m_tElement[0] = V.GetX(); 00309 this->m_tElement[1] = V.GetY(); 00310 this->m_tElement[2] = V.GetZ(); 00311 } 00312 00313 //------------------------------------------------------------------------------------------------ 00314 // Point3-To-Matrix Constructor 00315 template< typename T > 00316 SPtMatrix< T >::SPtMatrix( const SPtPoint3< T > &P ) 00317 { 00318 SPtMatrix( 3, 1 ); 00319 this->m_tElement[0] = P.GetX(); 00320 this->m_tElement[1] = P.GetY(); 00321 this->m_tElement[2] = P.GetZ(); 00322 } 00323 00324 //------------------------------------------------------------------------------------------------ 00325 // Destructor 00326 template< typename T > 00327 SPtMatrix< T >::~SPtMatrix() 00328 { 00329 DeleteMemory(); 00330 } 00331 00332 //------------------------------------------------------------------------------------------------ 00333 // Useful Member Functions ----------------------------------------------- 00334 // Fn Member: DisplayElements() ******************************************** 00335 // Desc: Display the matrix elements 00336 template< typename T > 00337 void SPtMatrix< T >::DisplayElements() const 00338 { 00339 int r, c; 00340 00341 cout << "A(n) " << m_iRows << " x " << m_iCols << " Matrix \n"; 00342 cout.precision(10); 00343 for ( r = 0; r < m_iRows; r++ ) { 00344 cout << "| "; 00345 for ( c = 0; c < m_iCols; c++ ) { 00346 cout.width( 20 ); cout << m_tElement[r][c]; 00347 } 00348 cout << " |" << endl; 00349 } 00350 cout.precision(6); 00351 } // END Fn Member: DisplayElements() 00352 00353 //------------------------------------------------------------------------------------------------ 00354 // Fn Member: Get() *************************************************** 00355 // Desc: Get the element value at row r, and column c. 00356 template< typename T > 00357 T SPtMatrix< T >::Get( int r, int c ) const 00358 { 00359 if ( CheckRanges( r, c ) ) { 00360 return m_tElement[ r ][ c ]; 00361 } 00362 else { 00363 return -777; 00364 } 00365 00366 } // END Fn Member: Get() 00367 00368 //------------------------------------------------------------------------------------------------ 00369 // Fn Member: Set() *************************************************** 00370 // Desc: Set the element value at row r, and column c. 00371 template< typename T > 00372 void SPtMatrix< T >::Set( int r, int c, T value ) 00373 { 00374 if ( CheckRanges( r, c ) ) { 00375 m_tElement[ r ][ c ] = value; 00376 } 00377 } // END Fn Member: Set() 00378 00379 //------------------------------------------------------------------------------------------------ 00380 // Fn Member: SetToIdentity() 00381 template< typename T > 00382 bool SPtMatrix< T >::SetToIdentity() 00383 { 00384 if ( m_iRows != m_iCols ) return false; 00385 for ( int r = 0; r < m_iRows; r++ ) { 00386 for ( int c = 0; c < m_iCols; c++ ) { 00387 this->m_tElement[r][c] = T( 0 ); 00388 } 00389 } 00390 for ( int i = 0; i < m_iRows; i++ ) { 00391 this->m_tElement[i][i] = T( 1 ); 00392 } 00393 return true; 00394 } // END Fn Member: SetToIdentity() 00395 00396 //------------------------------------------------------------------------------------------------ 00397 // Fn Member: GetNoOfRows() 00398 template< typename T > 00399 int SPtMatrix< T >::GetNoOfRows() const 00400 { 00401 return m_iRows; 00402 } // END Fn Member: GetNoOfRows() 00403 00404 //------------------------------------------------------------------------------------------------ 00405 // Fn Member: GetNoOfCols() 00406 template< typename T > 00407 int SPtMatrix< T >::GetNoOfCols() const 00408 { 00409 return m_iCols; 00410 } // END Fn Member: GetNoOfCols() 00411 00412 //------------------------------------------------------------------------------------------------ 00413 // Fn Member: GetNoOfRowsAndCols() 00414 template< typename T > 00415 void SPtMatrix< T >::GetNoOfRowsAndCols( int &r, int &c ) const 00416 { 00417 r = m_iRows; 00418 c = m_iCols; 00419 } // END Fn Member: GetNoOfRowsAndCols() 00420 00421 00422 //------------------------------------------------------------------------------------------------ 00423 // Matrix Operations --------------------------------------------------- 00424 template< typename T > 00425 SPtMatrix< T > SPtMatrix< T >::GetTranspose() const 00426 { 00427 SPtMatrix< T > temp( m_iCols, m_iRows ); 00428 00429 for ( int r = 0; r < temp.m_iRows; r++ ) { 00430 for ( int c = 0; c < temp.m_iCols; c++ ) { 00431 temp.m_tElement[r][c] = this->m_tElement[c][r]; 00432 } 00433 } 00434 00435 return temp; 00436 } 00437 00438 //------------------------------------------------------------------------------------------------ 00439 template< typename T > 00440 SPtMatrix< T > &SPtMatrix< T >::Transpose() 00441 { 00442 *this = this->GetTranspose(); 00443 00444 return *this; 00445 } 00446 00447 //------------------------------------------------------------------------------------------------ 00448 // Overloaded Operators --------------------------------------------------- 00449 00450 // assign matrix 00451 template< typename T > 00452 SPtMatrix< T > &SPtMatrix< T >::operator=( const SPtMatrix< T > & M ) 00453 { 00454 // check self assignment 00455 if ( this != &M ) { 00456 DeleteMemory(); // delete the space 00457 CopyElements( M ); // copy all elements from M matrix 00458 } 00459 00460 return *this; 00461 } 00462 00463 //------------------------------------------------------------------------------------------------ 00464 // negation 00465 template< typename T > 00466 SPtMatrix< T > SPtMatrix< T >::operator-() const 00467 { 00468 SPtMatrix< T > temp( *this ); 00469 temp *= -1.0; 00470 return temp; 00471 } 00472 00473 //------------------------------------------------------------------------------------------------ 00474 // add/assign matrix 00475 template< typename T > 00476 SPtMatrix< T > &SPtMatrix< T >::operator+=( const SPtMatrix< T > & M ) 00477 { 00478 if ( m_iRows == M.m_iRows && m_iCols == M.m_iCols ) { 00479 for ( int r = 0; r < m_iRows; r++ ) { 00480 for ( int c = 0; c < m_iCols; c++ ) { 00481 this->m_tElement[r][c] += M.m_tElement[r][c]; 00482 } 00483 } 00484 } 00485 00486 return *this; 00487 } 00488 00489 //------------------------------------------------------------------------------------------------ 00490 // subtract/assign matrix 00491 template< typename T > 00492 SPtMatrix< T > &SPtMatrix< T >::operator-=( const SPtMatrix< T > & M ) 00493 { 00494 if ( m_iRows == M.m_iRows && m_iCols == M.m_iCols ) { 00495 for ( int r = 0; r < m_iRows; r++ ) { 00496 for ( int c = 0; c < m_iCols; c++ ) { 00497 this->m_tElement[r][c] -= M.m_tElement[r][c]; 00498 } 00499 } 00500 } 00501 00502 return *this; 00503 } 00504 00505 //------------------------------------------------------------------------------------------------ 00506 // multiply/assign by scalar s 00507 template< typename T > 00508 SPtMatrix< T > &SPtMatrix< T >::operator*=( double s ) 00509 { 00510 for ( int r = 0; r < m_iRows; r++ ) { 00511 for ( int c = 0; c < m_iCols; c++ ) { 00512 this->m_tElement[r][c] *= s; 00513 } 00514 } 00515 00516 return *this; 00517 } 00518 00519 //------------------------------------------------------------------------------------------------ 00520 // divide/assign by scalar s 00521 template< typename T > 00522 SPtMatrix< T > &SPtMatrix< T >::operator/=( double s ) 00523 { 00524 for ( int r = 0; r < m_iRows; r++ ) { 00525 for ( int c = 0; c < m_iCols; c++ ) { 00526 this->m_tElement[r][c] /= s; 00527 } 00528 } 00529 00530 return *this; 00531 } 00532 00533 //------------------------------------------------------------------------------------------------ 00534 // multiply by a matrix 00535 template< typename T > 00536 SPtMatrix< T > SPtMatrix< T >::operator*( const SPtMatrix< T > &M ) const 00537 { 00538 // The rows# of the first matrix must equals the cols# of the second matrix 00539 if ( this->m_iCols == M.m_iRows ) { 00540 SPtMatrix< T > temp( this->m_iRows, M.m_iCols ); 00541 if ( temp.m_iRows < temp.m_iCols ) { 00542 for ( int r = 0; r < temp.m_iRows; r++ ) { 00543 for ( int c = 0; c < temp.m_iCols; c++ ) { 00544 for ( int k = 0; k < M.m_iRows; k++ ) { 00545 temp.m_tElement[r][c] += this->m_tElement[r][k] * M.m_tElement[k][c]; 00546 } 00547 //if ( fabs(temp.m_tElement[r][c]) < 5E-20 ) temp.m_tElement[r][c] = 0; 00548 } 00549 } 00550 } 00551 else { 00552 for ( int c = 0; c < temp.m_iCols; c++ ) { 00553 for ( int r = 0; r < temp.m_iRows; r++ ) { 00554 for ( int k = 0; k < M.m_iRows; k++ ) { 00555 temp.m_tElement[r][c] += this->m_tElement[r][k] * M.m_tElement[k][c]; 00556 } 00557 //if ( fabs(temp.m_tElement[r][c]) < 5E-20 ) temp.m_tElement[r][c] = 0; 00558 } 00559 } 00560 } 00561 00562 return temp; 00563 } 00564 00565 else return NULL; 00566 } 00567 00568 00569 00570 00571 //------------------------------------------------------------------------------------------------ 00572 // Helper Fn Member ------------------------------------------------------- 00573 // Check that row and column numbers are in the valid ranges. 00574 template< typename T > 00575 bool SPtMatrix< T >::CheckRanges( int r, int c ) const 00576 { 00577 assert( 0 <= r && r < m_iRows ); 00578 assert( 0 <= c && c < m_iCols ); 00579 00580 return true; 00581 } 00582 00583 //------------------------------------------------------------------------------------------------ 00584 // Deallocate memory held by the matrix 00585 template< typename T > 00586 void SPtMatrix< T >::DeleteMemory() 00587 { 00588 for ( int r = 0; r < m_iRows; r++ ) { 00589 delete [] m_tElement[ r ]; 00590 } 00591 delete [] m_tElement; 00592 } 00593 00594 //------------------------------------------------------------------------------------------------ 00595 // Copy all elements from M to this matrix 00596 template< typename T > 00597 void SPtMatrix< T >::CopyElements( const SPtMatrix< T > & M ) 00598 { 00599 int r, c; 00600 00601 // copy the data members from M 00602 m_iRows = M.m_iRows; 00603 m_iCols = M.m_iCols; 00604 m_tElement = new T*[ m_iRows ]; 00605 for ( r = 0; r < m_iRows; r++ ) { 00606 m_tElement[ r ] = new T[ m_iCols ]; 00607 for ( c = 0; c < m_iCols; c++ ) { 00608 m_tElement[ r ][ c ] = M.m_tElement[ r ][ c ]; 00609 } 00610 } 00611 } 00612 // END: SPtMatrix Member Functions *************************************** 00613 00614 00615 /* 00616 //------------------------------------------------------------------------------------------------ 00617 // Friend Functions for Operator Overloading *************************** 00618 template< typename T > 00619 ostream &operator<<( ostream &output, const SPtMatrix< T > &M ) 00620 { 00621 int r, c; 00622 00623 output << "A(n) " << m_iRows << " x " << m_iCols << " Matrix \n"; 00624 output.precision(10); 00625 for ( r = 0; r < m_iRows; r++ ) { 00626 output << "| "; 00627 for ( c = 0; c < m_iCols; c++ ) { 00628 output.width( 20 ); output << m_tElement[r][c]; 00629 } 00630 output << " |" << endl; 00631 } 00632 output.precision(6); 00633 00634 return output; 00635 } 00636 00637 //------------------------------------------------------------------------------------------------ 00638 template< typename T > 00639 SPtMatrix< T > operator*( double s, const SPtMatrix< T > &M ) 00640 { 00641 SPtMatrix< double > temp( M ); 00642 temp *= s; 00643 return temp; 00644 } 00645 00646 //------------------------------------------------------------------------------------------------ 00647 template< typename T > 00648 SPtMatrix< T > operator+( const SPtMatrix< T > &A, const SPtMatrix< T > &B ) 00649 { 00650 // Both matrices have to be the same order! 00651 if ( A.m_iRows != B.m_iRows || A.m_iCols != B.m_iCols ) return NULL; 00652 00653 SPtMatrix< T > temp( A ); 00654 for ( int r = 0; r < temp.m_iRows; r++ ) { 00655 for ( int c = 0; c < temp.m_iCols; c++ ) { 00656 temp.m_tElement[r][c] += B.m_tElement[r][c]; 00657 } 00658 } 00659 00660 return temp; 00661 } 00662 00663 //------------------------------------------------------------------------------------------------ 00664 template< typename T > 00665 SPtMatrix< T > operator-( const SPtMatrix< T > &A, const SPtMatrix< T > &B ) 00666 { 00667 // Both matrices have to be the same order! 00668 if ( A.m_iRows != B.m_iRows || A.m_iCols != B.m_iCols ) return NULL; 00669 00670 SPtMatrix< T > temp( A ); 00671 for ( int r = 0; r < temp.m_iRows; r++ ) { 00672 for ( int c = 0; c < temp.m_iCols; c++ ) { 00673 temp.m_tElement[r][c] -= B.m_tElement[r][c]; 00674 } 00675 } 00676 00677 return temp; 00678 } 00679 */