// file: $isip/class/math/matrix/MMatrix/MMatrixMethods.h // version: $Id: MMatrixMethods.h 10304 2005-12-14 06:25:15Z srinivas $ // // make sure definitions are only made once // #ifndef ISIP_MMATRIX_METHODS #define ISIP_MMATRIX_METHODS // isip include files // #ifndef ISIP_MVECTOR #include #endif #ifndef ISIP_MSCALAR #include #endif #ifndef ISIP_LONG #include #endif #ifndef ISIP_CHAR #include #endif // forward class definitions // template class MMatrix; class VectorLong; // MMatrixMethods: a friend class to the MMatrix template. // its purpose is mainly to provide a mechanism to get source code // out of the header file and into implementation files. // class MMatrixMethods { //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // static methods // template static bool8 diagnose(Integral::DEBUG debug_level); // assign methods // template static bool8 assign(MMatrix& obj, const MMatrix& arg); // i/o methods // template static int32 sofSize(const MMatrix& obj); template static bool8 read(MMatrix& obj, Sof& sof, int32 tag, const String& name); template static bool8 write(const MMatrix& obj, Sof& sof, int32 tag, const String& name); template static bool8 readData(MMatrix& obj, Sof& sof, const String& pname, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); template static bool8 writeData(const MMatrix& obj, Sof& sof, const String& name); //--------------------------------------------------------------------------- // // class-specific public methods: // extensions to required methods // //--------------------------------------------------------------------------- // method: eq // template static bool8 eq(const MMatrix& obj, TIntegral value); // array conversion methods // template static bool8 assign(MMatrix& obj, int32 nrows, int32 ncols, const TAIntegral* arg, Integral::MTYPE type); template static bool8 assignComplexDiagnose(MMatrix& obj, int32 nrows, int32 ncols, const float64* arg, Integral::MTYPE type); // conversion from string methods // template static bool8 assign(MMatrix& obj, int32 nrows, int32 ncols, const String* arg, Integral::MTYPE type); template static bool8 assign(MMatrix& obj, int32 nrows, int32 ncols, const String& arg, Integral::MTYPE type, const Char delim); // copy methods // template static bool8 copy(MMatrix& obj, const MMatrix& arg); // swap methods // template static bool8 swap(MMatrix& obj, MMatrix& matrix); //--------------------------------------------------------------------------- // // class-specific public methods: // operator overloads, get, find, and set methods // //--------------------------------------------------------------------------- // methods to get values from a matrix // template static TIntegral getValue(const MMatrix& obj, int32 row_index, int32 col_index); template static bool8 getValue(const MMatrix& obj, TScalar& value, int32 row_index, int32 col_index); template static bool8 getRow(const MMatrix& obj, MVector& vector, int32 row_index); template static bool8 getColumn(const MMatrix& obj, MVector& vector, int32 col_index); template static bool8 getDiagonal(const MMatrix& obj, MVector& vector); template static bool8 getLower(const MMatrix& obj, MMatrix& arg); template static bool8 getUpper(const MMatrix& obj, MMatrix& arg); template static bool8 getMinor(const MMatrix& obj, MMatrix& arg, int32 row_index, int32 col_index); // methods to set values // template static bool8 setValue(MMatrix& obj, int32 row_index, int32 col_index, TIntegral value); template static bool8 setRow(MMatrix& obj, int32 row_index, const MVector& vector); template static bool8 setColumn(MMatrix& obj, int32 col_index, const MVector& vector); template static bool8 setDiagonal(MMatrix& obj, const MVector& values); template static bool8 setLower(MMatrix& obj, const MMatrix& source); template static bool8 setUpper(MMatrix& obj, const MMatrix& source); template static bool8 setBlock(MMatrix& obj, int32 start_row, int32 start_col, int32 num_rows, int32 num_cols, TIntegral value); // methods to make matrices // template static bool8 makeDiagonal(MMatrix& obj, const MVector& values, Integral::MTYPE type); template static bool8 makeLower(MMatrix& obj, const MMatrix& source, Integral::MTYPE type); template static bool8 makeUpper(MMatrix& obj, const MMatrix& source, Integral::MTYPE type); // methods to find values // template static bool8 nextZero(const MMatrix& obj, int32& row_index, int32& col_index, int32 row_start, int32 col_start); template static bool8 nextNonZero(const MMatrix& obj, TIntegral& value, int32& row_index, int32& col_index, int32 row_start, int32 col_start); template static int32 findRow(const MMatrix& obj, const MVector& vector); //--------------------------------------------------------------------------- // // class-specific public methods: // property checking methods // //--------------------------------------------------------------------------- // change/get type methods // template static bool8 isTypePossible(const MMatrix& obj, Integral::MTYPE type); template static bool8 isSquare(const MMatrix& obj, const MMatrix& matrix); template static bool8 isOrthogonal(const MMatrix& obj); template static bool8 isIdentity(const MMatrix& obj); //--------------------------------------------------------------------------- // // class-specific public methods: // relational and logical methods // //--------------------------------------------------------------------------- // relational and bool8 methods // template static bool8 gt(const MMatrix& obj, TIntegral value); template static bool8 lt(const MMatrix& obj, TIntegral value); template static bool8 ge(const MMatrix& obj, TIntegral value); template static bool8 le(const MMatrix& obj, TIntegral value); template static int32 numEqual(const MMatrix& obj, TIntegral value); //--------------------------------------------------------------------------- // // class-specific public methods: // concatenation methods // //-------------------------------------------------------------------------- // concatenation methods // template static bool8 concatByRow(MMatrix& obj, const MMatrix& additional_rows); template static bool8 concatByColumn(MMatrix& obj, const MMatrix& additional_cols); //--------------------------------------------------------------------------- // // class-specific public methods: // ordering methods // //-------------------------------------------------------------------------- // ordering methods // template static bool8 reorderRows(MMatrix& obj, const MVector& indexes); template static bool8 reorderColumns(MMatrix& obj, const MVector& indexes); template static bool8 swapRows(MMatrix& obj, const MMatrix& arg, int32 row1, int32 row2); template static bool8 swapColumns(MMatrix& obj, const MMatrix& arg, int32 col1, int32 col2); //--------------------------------------------------------------------------- // // class-specific public methods: // basic mathematical methods // //--------------------------------------------------------------------------- template static bool8 add(MMatrix& obj, TIntegral value); template static bool8 add(MMatrix& obj, const MMatrix& m1); template static bool8 add(MMatrix& obj, const MMatrix& m1, const MMatrix& m2); template static bool8 add(MMatrix& obj, const MMatrix& source_matrix, TIntegral value); template static bool8 sub(MMatrix& obj, TIntegral value); template static bool8 sub(MMatrix& obj, const MMatrix& m1); template static bool8 sub(MMatrix& obj, const MMatrix& m1, const MMatrix& m2); template static bool8 sub(MMatrix& obj, const MMatrix& source_matrix, TIntegral value); template static bool8 mult(MMatrix& obj, const MMatrix& m1, const MMatrix& m2); //--------------------------------------------------------------------------- // // class-specific public methods: // other mathematical methods // //-------------------------------------------------------------------------- template static TIntegral min(const MMatrix& obj); template static TIntegral min(const MMatrix& obj, int32& row_index, int32& col_index); template static TIntegral max(const MMatrix& obj); template static TIntegral max(const MMatrix& obj, int32& row_index, int32& col_index); template static float64 minMag(const MMatrix& obj); template static float64 minMag(const MMatrix& obj, int32& row_index, int32& col_index); template static float64 maxMag(const MMatrix& obj); template static float64 maxMag(const MMatrix& obj, int32& row_index, int32& col_index); // random number generation methods // template static bool8 rand(MMatrix& obj, Random& generator); template static bool8 rand(MMatrix& obj, TIntegral min_val, TIntegral max_val, Random& generator); template static bool8 grand(MMatrix& obj, TIntegral mean, TIntegral stdev, Random& generator); template static bool8 randIndicesSparse(MMatrix& obj, Random& generator); //--------------------------------------------------------------------------- // // class-specific public methods: // linear algebra related methods // //-------------------------------------------------------------------------- // determinant and inverse methods // template static TIntegral determinant(const MMatrix& obj); template static TIntegral determinantLU(const MMatrix& obj); template static TIntegral determinantMinor(const MMatrix& obj); template static bool8 inverse(MMatrix& obj, const MMatrix& matrix); template static bool8 transpose(MMatrix& obj, const MMatrix& matrix); template static int32 rank(const MMatrix& obj); template static TIntegral trace(const MMatrix& obj); // decomposition methods // template static bool8 decompositionLU(const MMatrix& input, MMatrix& l, MMatrix& u, MVector& index, int32& sign, float64 stabilize); template static bool8 decompositionCholesky(const MMatrix& input, MMatrix& l); template static bool8 decompositionSVD(const MMatrix& input, MMatrix& u, MMatrix& w, MMatrix& v, bool8); template static bool8 decompositionQR(const MMatrix& input, MMatrix& q, MMatrix& r); // methods to compute eigenvalues and eigenvectors // template static bool8 eigen(const MMatrix& obj, MVector& eigvals, MMatrix& eigvects); template static bool8 eigenComputeVector(MMatrix& obj, MVector& eigvect, TIntegral eigval); template static bool8 eigenBalance(MMatrix& obj); template static bool8 eigenEliminateHessenberg(MMatrix& obj); template static bool8 eigenHessenbergQR(MMatrix& obj, MVector& eig_val_real, MVector& eig_val_imag); template static bool8 luSolve(MVector& out_vec, const MMatrix& l, const MMatrix& u, const VectorLong& index, const MVector& in_vec); template static bool8 choleskySolve(MVector& out_vec, const MMatrix& l, const MVector& in_vec); template static bool8 svdSolve(MVector& out_vec, const MMatrix& u, const MMatrix& w, const MMatrix& v, const MVector& in_vec, bool8 zero_singulars); template static bool8 multv(const MMatrix& obj, MVector& output_vector, const MVector& input_vector); template static bool8 vmult(const MMatrix& obj, MVector& output_vector, const MVector& input_vector); template static bool8 quadratic(TIntegral& output, const MMatrix& obj, const MVector& input_vector); template static bool8 quadratic(MMatrix& output, const MMatrix& input_mat1, const MMatrix& input_mat2); template static bool8 outerProduct(MMatrix& out_matrix, const MMatrix& input_mat1, const MMatrix& input_mat2); template static bool8 outerProduct(MMatrix& out_matrix, const MVector& input_vec1, const MVector& input_vec2); //--------------------------------------------------------------------------- // // class-specific public methods: // summation methods // //-------------------------------------------------------------------------- template static TIntegral sum(const MMatrix& obj); template static TIntegral sumSquare(const MMatrix& obj); template static TIntegral sumColumn(const MMatrix& obj, int32 col_index); template static TIntegral sumRow(const MMatrix& obj, int32 row_index); template static TIntegral var(const MMatrix& obj); //--------------------------------------------------------------------------- // // class-specific public methods: // methods that are private in MMatrix // //-------------------------------------------------------------------------- template static bool8 reverseIndex(const MMatrix& obj, int32& row, int32& col, int32 vec_index); template static TIntegral multiplyRowByColumn(const MMatrix& obj, const MMatrix& matrix_for_row, const MMatrix& matrix_for_col, int32 row_index, int32 col_index); template static TIntegral multiplyRowByRow(const MMatrix& obj, const MMatrix& m1, const MMatrix& m2, int32 row_m1, int32 row_m2); template static bool8 assignStream(MMatrix& obj, int32 nrows, int32 ncols, const MVector& vec, Integral::MTYPE type); //--------------------------------------------------------------------------- // // class-specific public methods: // diagnostic methods // //-------------------------------------------------------------------------- // test general methods template static bool8 diagnose0(Integral::DEBUG level); // test single matrix->scalar methods // template static bool8 diagnose1(Integral::DEBUG level); // test single matrix->vector methods // template static bool8 diagnose2(Integral::DEBUG level); // test single matrix->matrix methods // template static bool8 diagnose3(Integral::DEBUG level); // test (matrix, matrix)->matrix methods (real) // template static bool8 diagnose4(Integral::DEBUG level); // test (matrix, matrix)->matrix methods (complex) // template static bool8 diagnose5(Integral::DEBUG level); //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // destructor/constructor(s): // the constructors and destructors are declared private so that a // compilation error will be generated if the user tries to construct an // object of this type // ~MMatrixMethods(); MMatrixMethods(); MMatrixMethods(const MMatrixMethods& arg); // method: name // make this method private so it is never called outside this class // static const String& name(); }; // end of include file // #endif