60 template<
class Type,
int DIM = 4>
64 typedef Type CStyleMatrix[ DIM ][ DIM ];
123 inline void Clear() { memset(
_data, 0,
sizeof( Type ) * DIM * DIM ); }
282 Type& operator()(
unsigned row,
unsigned col );
283 Type operator()(
unsigned row,
unsigned col )
const;
295 GlsMatrix<Type, DIM> operator-()
const;
298 GlsMatrix<Type, DIM>& operator+=(
const GlsMatrix<Type, DIM>& rhs );
299 GlsMatrix<Type, DIM>& operator-=(
const GlsMatrix<Type, DIM>& rhs );
300 GlsMatrix<Type, DIM>& operator*=(
const GlsMatrix<Type, DIM>& rhs );
301 GlsMatrix<Type, DIM>& operator*=( Type scalar );
302 GlsMatrix<Type, DIM>& operator/=( Type scalar );
305 GlsMatrix<Type, DIM> operator+(
const GlsMatrix<Type, DIM>& rhs )
const;
306 GlsMatrix<Type, DIM> operator-(
const GlsMatrix<Type, DIM>& rhs )
const;
307 GlsMatrix<Type, DIM> operator*(
const GlsMatrix<Type, DIM>& rhs )
const;
308 GlsMatrix<Type, DIM> operator*( Type scalar )
const;
309 GlsMatrix<Type, DIM> operator/( Type scalar )
const;
363 int Pivot(
unsigned row );
385 template<
class Type,
int DIM>
389 template<
class Type,
int DIM>
396 template<
class Type,
int DIM>
400 for(
int row = 0; row < DIM; ++row )
402 for(
int col = 0; col < DIM; ++col )
404 _matrix[ col ][ row ] = m[ row ][ col ];
409 template<
class Type,
int DIM>
413 memcpy( _data, m,
sizeof( Type ) * DIM * DIM );
416 template<
class Type,
int DIM>
420 memcpy( _data, m.
_data,
sizeof( Type ) * DIM * DIM );
423 template<
class Type,
int DIM>
435 result.
_matrix[ 0 ][ 0 ] = _matrix[ 0 ][ 0 ] * rhs.
_matrix[ 0 ][ 0 ] + _matrix[ 1 ][ 0 ] * rhs.
_matrix[ 0 ][ 1 ] + _matrix[ 2 ][ 0 ] * rhs.
_matrix[ 0 ][ 2 ] + _matrix[ 3 ][ 0 ] * rhs.
_matrix[ 0 ][ 3 ];
436 result.
_matrix[ 1 ][ 0 ] = _matrix[ 0 ][ 0 ] * rhs.
_matrix[ 1 ][ 0 ] + _matrix[ 1 ][ 0 ] * rhs.
_matrix[ 1 ][ 1 ] + _matrix[ 2 ][ 0 ] * rhs.
_matrix[ 1 ][ 2 ] + _matrix[ 3 ][ 0 ] * rhs.
_matrix[ 1 ][ 3 ];
437 result.
_matrix[ 2 ][ 0 ] = _matrix[ 0 ][ 0 ] * rhs.
_matrix[ 2 ][ 0 ] + _matrix[ 1 ][ 0 ] * rhs.
_matrix[ 2 ][ 1 ] + _matrix[ 2 ][ 0 ] * rhs.
_matrix[ 2 ][ 2 ] + _matrix[ 3 ][ 0 ] * rhs.
_matrix[ 2 ][ 3 ];
438 result.
_matrix[ 3 ][ 0 ] = _matrix[ 0 ][ 0 ] * rhs.
_matrix[ 3 ][ 0 ] + _matrix[ 1 ][ 0 ] * rhs.
_matrix[ 3 ][ 1 ] + _matrix[ 2 ][ 0 ] * rhs.
_matrix[ 3 ][ 2 ] + _matrix[ 3 ][ 0 ] * rhs.
_matrix[ 3 ][ 3 ];
439 result.
_matrix[ 0 ][ 1 ] = _matrix[ 0 ][ 1 ] * rhs.
_matrix[ 0 ][ 0 ] + _matrix[ 1 ][ 1 ] * rhs.
_matrix[ 0 ][ 1 ] + _matrix[ 2 ][ 1 ] * rhs.
_matrix[ 0 ][ 2 ] + _matrix[ 3 ][ 1 ] * rhs.
_matrix[ 0 ][ 3 ];
440 result.
_matrix[ 1 ][ 1 ] = _matrix[ 0 ][ 1 ] * rhs.
_matrix[ 1 ][ 0 ] + _matrix[ 1 ][ 1 ] * rhs.
_matrix[ 1 ][ 1 ] + _matrix[ 2 ][ 1 ] * rhs.
_matrix[ 1 ][ 2 ] + _matrix[ 3 ][ 1 ] * rhs.
_matrix[ 1 ][ 3 ];
441 result.
_matrix[ 2 ][ 1 ] = _matrix[ 0 ][ 1 ] * rhs.
_matrix[ 2 ][ 0 ] + _matrix[ 1 ][ 1 ] * rhs.
_matrix[ 2 ][ 1 ] + _matrix[ 2 ][ 1 ] * rhs.
_matrix[ 2 ][ 2 ] + _matrix[ 3 ][ 1 ] * rhs.
_matrix[ 2 ][ 3 ];
442 result.
_matrix[ 3 ][ 1 ] = _matrix[ 0 ][ 1 ] * rhs.
_matrix[ 3 ][ 0 ] + _matrix[ 1 ][ 1 ] * rhs.
_matrix[ 3 ][ 1 ] + _matrix[ 2 ][ 1 ] * rhs.
_matrix[ 3 ][ 2 ] + _matrix[ 3 ][ 1 ] * rhs.
_matrix[ 3 ][ 3 ];
443 result.
_matrix[ 0 ][ 2 ] = _matrix[ 0 ][ 2 ] * rhs.
_matrix[ 0 ][ 0 ] + _matrix[ 1 ][ 2 ] * rhs.
_matrix[ 0 ][ 1 ] + _matrix[ 2 ][ 2 ] * rhs.
_matrix[ 0 ][ 2 ] + _matrix[ 3 ][ 2 ] * rhs.
_matrix[ 0 ][ 3 ];
444 result.
_matrix[ 1 ][ 2 ] = _matrix[ 0 ][ 2 ] * rhs.
_matrix[ 1 ][ 0 ] + _matrix[ 1 ][ 2 ] * rhs.
_matrix[ 1 ][ 1 ] + _matrix[ 2 ][ 2 ] * rhs.
_matrix[ 1 ][ 2 ] + _matrix[ 3 ][ 2 ] * rhs.
_matrix[ 1 ][ 3 ];
445 result.
_matrix[ 2 ][ 2 ] = _matrix[ 0 ][ 2 ] * rhs.
_matrix[ 2 ][ 0 ] + _matrix[ 1 ][ 2 ] * rhs.
_matrix[ 2 ][ 1 ] + _matrix[ 2 ][ 2 ] * rhs.
_matrix[ 2 ][ 2 ] + _matrix[ 3 ][ 2 ] * rhs.
_matrix[ 2 ][ 3 ];
446 result.
_matrix[ 3 ][ 2 ] = _matrix[ 0 ][ 2 ] * rhs.
_matrix[ 3 ][ 0 ] + _matrix[ 1 ][ 2 ] * rhs.
_matrix[ 3 ][ 1 ] + _matrix[ 2 ][ 2 ] * rhs.
_matrix[ 3 ][ 2 ] + _matrix[ 3 ][ 2 ] * rhs.
_matrix[ 3 ][ 3 ];
447 result.
_matrix[ 0 ][ 3 ] = _matrix[ 0 ][ 3 ] * rhs.
_matrix[ 0 ][ 0 ] + _matrix[ 1 ][ 3 ] * rhs.
_matrix[ 0 ][ 1 ] + _matrix[ 2 ][ 3 ] * rhs.
_matrix[ 0 ][ 2 ] + _matrix[ 3 ][ 3 ] * rhs.
_matrix[ 0 ][ 3 ];
448 result.
_matrix[ 1 ][ 3 ] = _matrix[ 0 ][ 3 ] * rhs.
_matrix[ 1 ][ 0 ] + _matrix[ 1 ][ 3 ] * rhs.
_matrix[ 1 ][ 1 ] + _matrix[ 2 ][ 3 ] * rhs.
_matrix[ 1 ][ 2 ] + _matrix[ 3 ][ 3 ] * rhs.
_matrix[ 1 ][ 3 ];
449 result.
_matrix[ 2 ][ 3 ] = _matrix[ 0 ][ 3 ] * rhs.
_matrix[ 2 ][ 0 ] + _matrix[ 1 ][ 3 ] * rhs.
_matrix[ 2 ][ 1 ] + _matrix[ 2 ][ 3 ] * rhs.
_matrix[ 2 ][ 2 ] + _matrix[ 3 ][ 3 ] * rhs.
_matrix[ 2 ][ 3 ];
450 result.
_matrix[ 3 ][ 3 ] = _matrix[ 0 ][ 3 ] * rhs.
_matrix[ 3 ][ 0 ] + _matrix[ 1 ][ 3 ] * rhs.
_matrix[ 3 ][ 1 ] + _matrix[ 2 ][ 3 ] * rhs.
_matrix[ 3 ][ 2 ] + _matrix[ 3 ][ 3 ] * rhs.
_matrix[ 3 ][ 3 ];
456 inline GlsMatrix<float, 4>
457 GlsMatrix<float, 4>::operator*(
const GlsMatrix<float, 4>& rhs )
const
459 GlsMatrix<float, 4> result;
462 result.
_matrix[ 0 ][ 0 ] = _matrix[ 0 ][ 0 ] * rhs._matrix[ 0 ][ 0 ] + _matrix[ 1 ][ 0 ] * rhs._matrix[ 0 ][ 1 ] + _matrix[ 2 ][ 0 ] * rhs._matrix[ 0 ][ 2 ] + _matrix[ 3 ][ 0 ] * rhs._matrix[ 0 ][ 3 ];
463 result._matrix[ 1 ][ 0 ] = _matrix[ 0 ][ 0 ] * rhs._matrix[ 1 ][ 0 ] + _matrix[ 1 ][ 0 ] * rhs._matrix[ 1 ][ 1 ] + _matrix[ 2 ][ 0 ] * rhs._matrix[ 1 ][ 2 ] + _matrix[ 3 ][ 0 ] * rhs._matrix[ 1 ][ 3 ];
464 result._matrix[ 2 ][ 0 ] = _matrix[ 0 ][ 0 ] * rhs._matrix[ 2 ][ 0 ] + _matrix[ 1 ][ 0 ] * rhs._matrix[ 2 ][ 1 ] + _matrix[ 2 ][ 0 ] * rhs._matrix[ 2 ][ 2 ] + _matrix[ 3 ][ 0 ] * rhs._matrix[ 2 ][ 3 ];
465 result._matrix[ 3 ][ 0 ] = _matrix[ 0 ][ 0 ] * rhs._matrix[ 3 ][ 0 ] + _matrix[ 1 ][ 0 ] * rhs._matrix[ 3 ][ 1 ] + _matrix[ 2 ][ 0 ] * rhs._matrix[ 3 ][ 2 ] + _matrix[ 3 ][ 0 ] * rhs._matrix[ 3 ][ 3 ];
466 result._matrix[ 0 ][ 1 ] = _matrix[ 0 ][ 1 ] * rhs._matrix[ 0 ][ 0 ] + _matrix[ 1 ][ 1 ] * rhs._matrix[ 0 ][ 1 ] + _matrix[ 2 ][ 1 ] * rhs._matrix[ 0 ][ 2 ] + _matrix[ 3 ][ 1 ] * rhs._matrix[ 0 ][ 3 ];
467 result._matrix[ 1 ][ 1 ] = _matrix[ 0 ][ 1 ] * rhs._matrix[ 1 ][ 0 ] + _matrix[ 1 ][ 1 ] * rhs._matrix[ 1 ][ 1 ] + _matrix[ 2 ][ 1 ] * rhs._matrix[ 1 ][ 2 ] + _matrix[ 3 ][ 1 ] * rhs._matrix[ 1 ][ 3 ];
468 result._matrix[ 2 ][ 1 ] = _matrix[ 0 ][ 1 ] * rhs._matrix[ 2 ][ 0 ] + _matrix[ 1 ][ 1 ] * rhs._matrix[ 2 ][ 1 ] + _matrix[ 2 ][ 1 ] * rhs._matrix[ 2 ][ 2 ] + _matrix[ 3 ][ 1 ] * rhs._matrix[ 2 ][ 3 ];
469 result._matrix[ 3 ][ 1 ] = _matrix[ 0 ][ 1 ] * rhs._matrix[ 3 ][ 0 ] + _matrix[ 1 ][ 1 ] * rhs._matrix[ 3 ][ 1 ] + _matrix[ 2 ][ 1 ] * rhs._matrix[ 3 ][ 2 ] + _matrix[ 3 ][ 1 ] * rhs._matrix[ 3 ][ 3 ];
470 result._matrix[ 0 ][ 2 ] = _matrix[ 0 ][ 2 ] * rhs._matrix[ 0 ][ 0 ] + _matrix[ 1 ][ 2 ] * rhs._matrix[ 0 ][ 1 ] + _matrix[ 2 ][ 2 ] * rhs._matrix[ 0 ][ 2 ] + _matrix[ 3 ][ 2 ] * rhs._matrix[ 0 ][ 3 ];
471 result._matrix[ 1 ][ 2 ] = _matrix[ 0 ][ 2 ] * rhs._matrix[ 1 ][ 0 ] + _matrix[ 1 ][ 2 ] * rhs._matrix[ 1 ][ 1 ] + _matrix[ 2 ][ 2 ] * rhs._matrix[ 1 ][ 2 ] + _matrix[ 3 ][ 2 ] * rhs._matrix[ 1 ][ 3 ];
472 result._matrix[ 2 ][ 2 ] = _matrix[ 0 ][ 2 ] * rhs._matrix[ 2 ][ 0 ] + _matrix[ 1 ][ 2 ] * rhs._matrix[ 2 ][ 1 ] + _matrix[ 2 ][ 2 ] * rhs._matrix[ 2 ][ 2 ] + _matrix[ 3 ][ 2 ] * rhs._matrix[ 2 ][ 3 ];
473 result._matrix[ 3 ][ 2 ] = _matrix[ 0 ][ 2 ] * rhs._matrix[ 3 ][ 0 ] + _matrix[ 1 ][ 2 ] * rhs._matrix[ 3 ][ 1 ] + _matrix[ 2 ][ 2 ] * rhs._matrix[ 3 ][ 2 ] + _matrix[ 3 ][ 2 ] * rhs._matrix[ 3 ][ 3 ];
474 result._matrix[ 0 ][ 3 ] = _matrix[ 0 ][ 3 ] * rhs._matrix[ 0 ][ 0 ] + _matrix[ 1 ][ 3 ] * rhs._matrix[ 0 ][ 1 ] + _matrix[ 2 ][ 3 ] * rhs._matrix[ 0 ][ 2 ] + _matrix[ 3 ][ 3 ] * rhs._matrix[ 0 ][ 3 ];
475 result._matrix[ 1 ][ 3 ] = _matrix[ 0 ][ 3 ] * rhs._matrix[ 1 ][ 0 ] + _matrix[ 1 ][ 3 ] * rhs._matrix[ 1 ][ 1 ] + _matrix[ 2 ][ 3 ] * rhs._matrix[ 1 ][ 2 ] + _matrix[ 3 ][ 3 ] * rhs._matrix[ 1 ][ 3 ];
476 result._matrix[ 2 ][ 3 ] = _matrix[ 0 ][ 3 ] * rhs._matrix[ 2 ][ 0 ] + _matrix[ 1 ][ 3 ] * rhs._matrix[ 2 ][ 1 ] + _matrix[ 2 ][ 3 ] * rhs._matrix[ 2 ][ 2 ] + _matrix[ 3 ][ 3 ] * rhs._matrix[ 2 ][ 3 ];
477 result._matrix[ 3 ][ 3 ] = _matrix[ 0 ][ 3 ] * rhs._matrix[ 3 ][ 0 ] + _matrix[ 1 ][ 3 ] * rhs._matrix[ 3 ][ 1 ] + _matrix[ 2 ][ 3 ] * rhs._matrix[ 3 ][ 2 ] + _matrix[ 3 ][ 3 ] * rhs._matrix[ 3 ][ 3 ];
482 template<
class Type,
int DIM>
483 inline GlsMatrix<Type, DIM>
484 GlsMatrix<Type, DIM>::operator*(
const GlsMatrix<Type, DIM>& rhs )
const
486 GlsMatrix<Type, DIM> result;
487 memset( result._data, 0,
sizeof( Type ) * DIM * DIM );
488 for(
int row = 0; row < DIM; ++row )
490 for(
int col = 0; col < DIM; ++col )
492 for(
int i = 0; i < DIM; ++i )
494 result._matrix[ col ][ row ] += _matrix[ i ][ row ] * rhs._matrix[ col ][ i ];
501 template<
class Type,
int DIM>
502 inline GlsMatrix<Type, DIM> GlsMatrix<Type, DIM>::operator*( Type scalar )
const
504 GlsMatrix<Type, DIM> result;
505 for(
int row = 0; row < DIM; ++row )
507 for(
int col = 0; col < DIM; ++col )
509 result._matrix[ col ][ row ] = _matrix[ col ][ row ] * scalar;
515 template<
class Type,
int DIM>
518 for(
int row = 0; row < DIM; ++row )
520 for(
int col = 0; col < DIM; ++col )
522 std::cout.width( 11 );
523 std::cout << _matrix[ col ][ row ] <<
' ';
525 std::cout << std::endl;
527 std::cout << std::endl;
530 template<
class Type,
int DIM>
534 for(
int i = 0; i < DIM; ++i )
536 _matrix[ i ][ i ] = Type( 1 );
540 template<
class Type,
int DIM>
556 Type det = Type( 1 );
563 for(
int k = 0; k < DIM; ++k )
566 int index = temp.
Pivot( k );
588 for(
int i = k + 1; i < DIM; ++i )
599 for(
int j = k + 1; j < DIM; ++j )
608 template<
class Type,
int DIM>
642 for(
int k = 0; k < DIM; ++k )
645 int index = temp.
Pivot( k );
658 size_t byteCount =
sizeof( Type ) * DIM;
659 memcpy( rowptr, inverse.
_matrix[ k ], byteCount );
660 memcpy( inverse.
_matrix[ k ], inverse.
_matrix[ index ], byteCount );
661 memcpy( inverse.
_matrix[ index ], rowptr, byteCount );
667 a1_inv = ( (Type)1.0 ) / temp.
_matrix[ k ][ k ];
668 for(
int j = 0; j < DIM; ++j )
670 temp.
_matrix[ k ][ j ] *= a1_inv;
671 inverse.
_matrix[ k ][ j ] *= a1_inv;
681 for(
int i = 0; i < DIM; ++i )
686 for(
int j = 0; j < DIM; ++j )
697 template<
class Type,
int DIM>
703 template<
class Type,
int DIM>
708 for(
int row = 0; row < DIM; ++row )
710 for(
int col = 0; col < DIM; ++col )
712 result.
_matrix[ col ][ row ] = _matrix[ row ][ col ];
718 template<
class Type,
int DIM>
722 result = Transposition();
726 template<
class Type,
int DIM>
731 for(
int row = 0; row < DIM; ++row )
733 for(
int col = 0; col < DIM; ++col )
735 if( col != row && !closeValues( _matrix[ col ][ row ], Type( 0 ) ) )
742 template<
class Type,
int DIM>
748 static const GlsMatrix referenceIdentity;
749 if( 0 == memcmp( _data, referenceIdentity.
_data,
sizeof( Type ) * DIM * DIM ) )
754 if( IsScalar() && closeValues( _matrix[ 0 ][ 0 ], Type( 1 ) ) )
760 template<
class Type,
int DIM>
768 Type val = _matrix[ 0 ][ 0 ];
769 for(
int i = 0; i < DIM; ++i )
771 if( !closeValues( _matrix[ i ][ i ], val ) )
777 template<
class Type,
int DIM>
780 return Determinant() == Type( 0 );
783 template<
class Type,
int DIM>
786 return Transposition() == *
this;
789 template<
class Type,
int DIM>
792 return Transposition() == -( *this );
795 template<
class Type,
int DIM>
799 for(
int row = 0; row < DIM - 1; ++row )
801 for(
int col = row + 1; col < DIM; ++col )
803 if( !closeValues( _matrix[ col ][ row ], Type( 0 ) ) )
810 template<
class Type,
int DIM>
814 for(
int row = 1; row < DIM; ++row )
816 for(
int col = 0; col < row; ++col )
818 if( !closeValues( _matrix[ col ][ row ], Type( 0 ) ) )
825 template<
class Type,
int DIM>
830 return _matrix[ col ][ row ];
833 template<
class Type,
int DIM>
834 inline Type GlsMatrix<Type, DIM>::operator()(
unsigned row,
unsigned col )
const
838 return _matrix[ col ][ row ];
841 template<
class Type,
int DIM>
844 static const int SIZE = DIM * DIM;
845 for(
int i = 0; i < SIZE; ++i )
847 if( !closeValues( _data[ i ], rhs._data[ i ] ) )
853 template<
class Type,
int DIM>
856 return !( *
this == rhs );
859 template<
class Type,
int DIM>
860 inline GlsMatrix<Type, DIM>&
861 GlsMatrix<Type, DIM>::operator=(
const GlsMatrix<Type, DIM>& m )
866 memcpy( _data, m._data,
sizeof( Type ) * DIM * DIM );
871 template<
class Type,
int DIM>
872 inline GlsMatrix<Type, DIM>&
873 GlsMatrix<Type, DIM>::operator=(
const CStyleMatrix m )
875 for(
int row = 0; row < DIM; ++row )
877 for(
int col = 0; col < DIM; ++col )
879 _matrix[ col ][ row ] = m[ row ][ col ];
886 template<
class Type,
int DIM>
887 inline GlsMatrix<Type, DIM> GlsMatrix<Type, DIM>::operator-()
const
889 GlsMatrix<Type, DIM> temp;
891 for(
int row = 0; row < DIM; ++row )
893 for(
int col = 0; col < DIM; ++col )
895 temp._matrix[ col ][ row ] = -_matrix[ col ][ row ];
902 template<
class Type,
int DIM>
903 inline GlsMatrix<Type, DIM>&
904 GlsMatrix<Type, DIM>::operator+=(
const GlsMatrix<Type, DIM>& rhs )
906 for(
int row = 0; row < DIM; ++row )
908 for(
int col = 0; col < DIM; ++col )
910 _matrix[ col ][ row ] += rhs._matrix[ col ][ row ];
916 template<
class Type,
int DIM>
917 inline GlsMatrix<Type, DIM>&
918 GlsMatrix<Type, DIM>::operator-=(
const GlsMatrix<Type, DIM>& rhs )
920 for(
int row = 0; row < DIM; ++row )
922 for(
int col = 0; col < DIM; ++col )
924 _matrix[ col ][ row ] -= rhs._matrix[ col ][ row ];
931 inline GlsMatrix<double, 4>&
932 GlsMatrix<double, 4>::operator*=(
const GlsMatrix<double, 4>& rhs )
934 return *
this = *
this * rhs;
938 inline GlsMatrix<float, 4>&
939 GlsMatrix<float, 4>::operator*=(
const GlsMatrix<float, 4>& rhs )
941 return *
this = *
this * rhs;
944 template<
class Type,
int DIM>
945 inline GlsMatrix<Type, DIM>&
946 GlsMatrix<Type, DIM>::operator*=(
const GlsMatrix<Type, DIM>& rhs )
948 GlsMatrix<Type, DIM> result;
949 memset( result._data, 0,
sizeof( Type ) * DIM * DIM );
950 for(
int row = 0; row < DIM; ++row )
952 for(
int col = 0; col < DIM; ++col )
954 for(
int i = 0; i < DIM; ++i )
956 result._matrix[ col ][ row ] += _matrix[ i ][ row ] * rhs._matrix[ col ][ i ];
964 template<
class Type,
int DIM>
965 inline GlsMatrix<Type, DIM>&
966 GlsMatrix<Type, DIM>::operator*=( Type scalar )
968 for(
int row = 0; row < DIM; ++row )
970 for(
int col = 0; col < DIM; ++col )
972 _matrix[ col ][ row ] *= scalar;
978 template<
class Type,
int DIM>
979 inline GlsMatrix<Type, DIM>&
980 GlsMatrix<Type, DIM>::operator/=( Type scalar )
982 for(
int row = 0; row < DIM; ++row )
984 for(
int col = 0; col < DIM; ++col )
986 _matrix[ col ][ row ] /= scalar;
992 template<
class Type,
int DIM>
993 inline GlsMatrix<Type, DIM>
994 GlsMatrix<Type, DIM>::operator+(
const GlsMatrix<Type, DIM>& rhs )
const
996 GlsMatrix<Type, DIM> result;
997 for(
int row = 0; row < DIM; ++row )
999 for(
int col = 0; col < DIM; ++col )
1001 result._matrix[ col ][ row ] = _matrix[ col ][ row ] + rhs._matrix[ col ][ row ];
1007 template<
class Type,
int DIM>
1008 inline GlsMatrix<Type, DIM>
1009 GlsMatrix<Type, DIM>::operator-(
const GlsMatrix<Type, DIM>& rhs )
const
1011 GlsMatrix<Type, DIM> result;
1012 for(
int row = 0; row < DIM; ++row )
1014 for(
int col = 0; col < DIM; ++col )
1016 result._matrix[ col ][ row ] = _matrix[ col ][ row ] - rhs._matrix[ col ][ row ];
1022 template<
class Type,
int DIM>
1023 inline GlsMatrix<Type, DIM> GlsMatrix<Type, DIM>::operator/( Type scalar )
const
1025 GlsMatrix<Type, DIM> result;
1026 for(
int row = 0; row < DIM; ++row )
1028 for(
int col = 0; col < DIM; ++col )
1030 result._matrix[ col ][ row ] = _matrix[ col ][ row ] / scalar;
1036 template<
class Type,
int DIM>
1037 inline std::ostream& operator<<( std::ostream& ostrm, const GlsMatrix<Type, DIM>& m )
1039 for(
int row = 0; row < DIM; ++row )
1041 for(
int col = 0; col < DIM; ++col )
1044 ostrm << m( row, col ) <<
' ';
1050 template<
class Type,
int DIM>
1051 inline std::istream& operator>>( std::istream& istrm, GlsMatrix<Type, DIM>& m )
1054 for(
int row = 0; row < DIM; ++row )
1056 for(
int col = 0; col < DIM; ++col )
1065 template<
class Type,
int DIM>
1070 for(
int i = 0, j = 0; i < DIM; ++i, j += DIM )
1072 _matrix[ i ] = &( _data[ j ] );
1076 template<
class Type,
int DIM>
1087 for(
unsigned i = row; i < unsigned( DIM ); ++i )
1089 if( ( temp = fabs( _matrix[ i ][ row ] ) ) > amax && temp != 0.0 )
1096 if( _matrix[ k ][ row ] == Type( 0 ) )
1102 else if( k !=
int( row ) )
1108 size_t byteCount =
sizeof( Type ) * DIM;
1109 memcpy( rowptr, _matrix[ k ], byteCount );
1110 memcpy( _matrix[ k ], _matrix[ row ], byteCount );
1111 memcpy( _matrix[ row ], rowptr, byteCount );
1125 template<
class Type,
int DIM>
1128 return ( lv - PRECISION ) <= rv && rv <= ( lv + PRECISION );
bool IsScalar() const
Definition: gls_matrix.h:761
bool IsDiagonal() const
Definition: gls_matrix.h:727
GlsMatrix< Type, DIM > Transposition() const
Definition: gls_matrix.h:704
Definition: gls_matrix.h:61
bool operator!=(const AttributeName &attr1, const AttributeName &attr2)
Definition: disti_metadata.h:152
bool IsLowerTriangular() const
Definition: gls_matrix.h:796
void Initialize()
Definition: gls_matrix.h:1066
static const double PRECISION
Definition: gls_matrix.h:313
GlsMatrix< Type, DIM > Inverse() const
Definition: gls_matrix.h:609
Type * _matrix[DIM]
Definition: gls_matrix.h:334
bool IsSkewSymmetric() const
Definition: gls_matrix.h:790
GlsMatrix()
Definition: gls_matrix.h:390
Type _data[DIM *DIM]
Definition: gls_matrix.h:322
bool operator==(const AttributeName &attr1, const AttributeName &attr2)
Definition: disti_metadata.h:144
Type Determinant() const
Definition: gls_matrix.h:541
bool IsIdentity() const
Definition: gls_matrix.h:743
void Clear()
Definition: gls_matrix.h:123
Type * Data()
Definition: gls_matrix.h:131
bool closeValues(Type lv, Type rv) const
Definition: gls_matrix.h:1126
const Type * Data() const
Definition: gls_matrix.h:139
void Dump() const
Definition: gls_matrix.h:516
bool IsSingular() const
Definition: gls_matrix.h:778
void Invert()
Definition: gls_matrix.h:698
int Pivot(unsigned row)
Definition: gls_matrix.h:1077
void MakeIdentity()
Definition: gls_matrix.h:531
void Transpose()
Definition: gls_matrix.h:719
bool IsUpperTriangular() const
Definition: gls_matrix.h:811
Definition: bmpimage.h:46
virtual ~GlsMatrix()
Definition: gls_matrix.h:424
bool IsSymmetric() const
Definition: gls_matrix.h:784