quick start:g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_math_matrix.a #include <MMatrix.h> MMatrix(); MMatrix(const MMatrix& arg); MMatrix(long nrows, long ncols = DEF_SIZE, Integral::MTYPE type = Integral::DEF_MTYPE); boolean assign(TIntegral value); boolean assign(long num_rows, long num_cols, long* arg, Integral::MTYPE type = Integral::DEF_MTYPE); boolean setCapacity(const MMatrix& prototype_matrix, boolean preserve_values = true, Integral::MTYPE type = Integral::UNCHANGED); boolean setDimensions(const MMatrix& prototype_matrix, boolean preserve_values = true, Integral::MTYPE type = Integral::UNCHANGED); boolean mult(MMatrix& m1, MMatrix& m2); boolean multv(TVector& output_vector, const TVector& input_vector); boolean vmult(TVector& output_vector, const TVector& input_vector); double determinant() const; boolean inverse(); boolean transpose();
description:MMatrix<Double, double> mat0(3, 3, Integral::FULL); MMatrix<Double, double> mat2; double det; mat0.assign(3, 3, L"2.1, 8.3, 4.5, 4.6, 0, 8.1, 5.5, 3.2, 1.7"); MMatrix<Double, double> mat1(4, 4, Integral::SYMMETRIC); MVector<Double, double> vec_in; MVector<Double, double> vec_out1; MVector<Double, double> vec_out2; mat1.assign(4, 4, L"1.1, 4.5, 6.5, 3.6, 0.3, 6.7, 8.1, 2.3, 5.5, 9.2", Integral::SYMMETRIC); vec_in.assign(L"2.2, 4.3, 6.5"); mat1.setDimensions(3, 3); mat0.multv(vec_out1, vec_in); mat1.vmult(vec_out2, vec_in); mat0.transpose(); mat2.mult(mat0, mat1); det = mat2.determinant(); mat2.inverse(); mat0.setCapacity(0);
static const String CLASS_NAME = L"MMatrix";
static const String DEF_PARAM = L"";
static const String PARAM_DATA = L"values";
static const String PARAM_TYPE = L"type";
static const String PARAM_NROWS = L"num_rows";
static const String PARAM_NCOLS = L"num_cols";
static const String PARAM_ROW_IND = L"row_indices";
static const String PARAM_COL_IND = L"col_indices";
static const NameMap TYPE_MAP = L"FULL, DIAGONAL, SYMMETRIC, LOWER_TRIANGULAR, UPPER_TRIANGULAR, SPARSE";
static const double THRESH_SINGULAR = 1e-10;
static const double THRESH_SPARSE = 0.9;
static const double THRESH_BALANCE = 0.95;
static const double THRESH_STABLE = 1e-20;
static const unichar DEF_ROW_DELIM = L',';
static const unichar DEF_DELIM = DEF_ROW_DELIM;
static const TIntegral DEF_VALUE = 0;
static const long DEF_SIZE = 0;
static const long ERR = 24000;
static const long ERR_OPTYPE = 24001;
static const long ERR_DIM = 24002;
static const long ERR_UNKTYP = 24003;
static const long ERR_SINGLR = 24004;
static const long ERR_POSDEF = 24005;
Integral::MTYPE type_d;
Long nrows_d;
Long ncols_d;
TVector m_d;
MVector<Long, long> row_index_d;
MVector<Long, long> col_index_d;
static Integral::DEBUG debug_level_d;
static const String& name();
static boolean diagnose(Integral::DEBUG debug_level);
boolean setDebug(Integral::DEBUG level);
boolean debug(const unichar* message) const;
~MMatrix();
MMatrix();
MMatrix(const MMatrix& m);
boolean assign(const MMatrix<TAScalar, TAIntegral>& arg);
the operator= methods are omitted because they are defined in the classes that instantiate this template
long sofSize() const;
boolean read(Sof& sof, long tag, cons String& name);
boolean write(Sof& sof, long tag, const String& name) const;
boolean readData(Sof& sof, const String& pname, long size, boolean param, boolean nested);
boolean writeData(Sof& sof, const String& name) const;
boolean eq(const MMatrix& arg) const;
boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);
boolean debug(const String& name, const unichar* message) const;
MMatrix(long nrows, long ncols = DEF_SIZE, Integral::MTYPE type = Integral::DEF_MTYPE);
boolean eq(TIntegral value) const;
boolean assign(const MMatrix<TAScalar, TAIntegral>& arg, Integral::MTYPE type);
boolean assign(TIntegral value);
boolean assign(long num_rows, long num_cols, const TAIntegral* arg, Integral::MTYPE type = Integral::DEF_MTYPE);
boolean assign(long num_rows, long num_cols, const String* arg, Integral::MTYPE type = Integral::DEF_MTYPE);
boolean assign(long nrows, long ncols, const String& arg, Integral::MTYPE type = Integral::DEF_MTYPE, const Char delim = DEF_DELIM);
boolean assign(long nrows, long ncols, const unichar* arg, Integral::MTYPE type = Integral::DEF_MTYPE, const Char delim = DEF_DELIM);
boolean copy(const MMatrix<TAScalar, TAIntegral>& arg);
boolean swap(MMatrix& arg);
TIntegral operator()(long i, long j) const;
Integral::MTYPE getType() const;
TIntegral getValue(long row_index, long col_index) const;
boolean getValue(TScalar& value, long row_index, long col_index) const;
long getNumRows() const;
long getNumColumns() const;
boolean getRow(TVector& vector, long row_index) const;
boolean getColumn(TVector& vector, long col_index) const;
boolean getDiagonal(TVector& vector) const;
boolean getLower(MMatrix& arg) const;
boolean getUpper(MMatrix& arg) const;
boolean getMinor(const MMatrix& arg, long row_index, long col_index) const;
boolean setValue(long row_index, long col_index, TIntegral value);
boolean setValue(long row_index, long col_index, const TScalar& value);
boolean setRow(long row_index, const TVector& vector);
boolean setColumn(long col_index, const TVector& vector);
boolean setDiagonal(const TVector& values);
boolean setDiagonal(const MMatrix& source);
boolean setDiagonal(TIntegral value);
boolean setLower(const MMatrix& source);
boolean setUpper(const MMatrix& source);
boolean setBlock(long start_row, long start_col, long num_rows, long num_cols, TIntegral value);
boolean makeDiagonal(const TVector& values, Integral::MTYPE type = Integral::DIAGONAL);
boolean makeDiagonal(TIntegral value, long dim, Integral::MTYPE type = Integral::DIAGONAL);
boolean makeIdentity(long dim, Integral::MTYPE type = Integral::DIAGONAL);
boolean makeLower(const MMatrix& source, Integral::MTYPE type = Integral::LOWER_TRIANGULAR);
boolean makeUpper(const MMatrix& source, Integral::MTYPE type = Integral::UPPER_TRIANGULAR);
boolean nextZero(long& row_index, long& col_index, long row_start, long col_start) const;
boolean nextNonZero(TIntegral& value, long& row_index, long& col_index, long row_start, long col_start) const;
long findRow(const TVector& vector) const;
boolean setCapacity(long nrows, long ncols = DEF_SIZE, boolean preserve_values = true, Integral::MTYPE type = Integral::UNCHANGED);
boolean setCapacity(const MMatrix& prototype_matrix, boolean preserve_values = true, Integral::MTYPE type = Integral::UNCHANGED);
boolean setDimensions(long nrows, long ncols = DEF_SIZE, boolean preserve_values = true, Integral::MTYPE type = Integral::UNCHANGED);
boolean setDimensions(const MMatrix& prototype_matrix, boolean preserve_values = true, Integral::MTYPE type = Integral::UNCHANGED);
boolean checkDimensions(const MMatrix<TAScalar, TAIntegral>& matrix) const;
boolean changeType(Integral::MTYPE type);
boolean isTypePossible(Integral::MTYPE type) const;
boolean isFull() const;
boolean isDiagonal() const;
boolean isSymmetric() const;
boolean isLowerTriangular() const;
boolean isUpperTriangular() const;
boolean isSparse() const;
boolean isSquare() const;
boolean isSquare(const MMatrix& matrix) const;
boolean isSingular(double thresh = 0) const;
boolean isSingular(const MMatrix& matrix, double thresh = 0) const;
boolean isOrthogonal() const;
boolean isIdentity() const;
boolean ne(TIntegral value) const;
boolean ne(const MMatrix& matrix) const;
boolean lt(TIntegral value) const;
boolean le(TIntegral value) const;
boolean gt(TIntegral value) const;
boolean ge(TIntegral value) const;
boolean operator == (TIntegral arg) const;
boolean operator != (TIntegral arg) const;
boolean operator < (TIntegral arg) const;
boolean operator <= (TIntegral arg) const;
boolean operator > (TIntegral arg) const;
boolean operator >= (TIntegral arg) const;
long numEqual(TIntegral value) const;
long numNotEqual(TIntegral value);
boolean almostEqual(TIntegral value, double percent = Integral::DEF_PERCENTAGE, double bound = Integral::DEF_BOUND) const;
boolean almostEqual(const MMatrix& matrix, percent = Integral::DEF_PERCENTAGE, double bound = Integral::DEF_BOUND) const;
boolean concatByRow(const MMatrix& additional_rows);
boolean concatByRow(const MMatrix& matrix1, const MMatrix& matrix2);
boolean concatByColumn(const MMatrix& additional_cols);
boolean concatByColumn(const MMatrix& matrix1, const MMatrix& matrix2);
boolean reorderRows(const MVector<Long,long>& indexes);
boolean reorderRows(const MMatrix& matrix, const MVector<Long,long>& indexes);
boolean reorderColumns(const MVector<Long,long>& indexes);
boolean reorderColumns(const MMatrix& matrix, const MVector<Long,long>& indexes);
boolean swapRows(const MMatrix& arg, long row1, long row2);
boolean swapRows(long row1, long row2);
boolean swapColumns(const MMatrix& arg, long col1, long col2);
boolean swapColumns(long col1, long col2);
boolean add(const MMatrix<TAScalar, TAIntegral>& m1);
boolean add(const MMatrix& m1, const MMatrix<TAScalar, TAIntegral>& m2);
boolean add(TIntegral value);
boolean add(TIntegral value);
boolean sub(const MMatrix<TAScalar, TAIntegral>& m1);
boolean sub(const MMatrix& m1, const MMatrix<TAScalar, TAIntegral>& m2);
boolean sub(TIntegral value);
boolean sub(TIntegral value);
boolean mult(const MMatrix<TAScalar, TAIntegral>& m1);
boolean mult(const MMatrix& m1, const MMatrix<TAScalar, TAIntegral>& m2);
boolean mult(TIntegral value);
boolean div(TIntegral value);
boolean neg();
boolean neg(const MMatrix& m1);
TIntegral min() const;
TIntegral min(long& row_index, long& col_index) const;
TIntegral max() const;
TIntegral max(long& row_index, long& col_index) const;
double minMag() const;
double minMag(long& row_index, long& col_index) const;
double maxMag() const;
double maxMag(long& row_index, long& col_index) const;
boolean rand(Random& generator = Random::GLOBAL_UNIFORM);
boolean rand(TIntegral min_val, TIntegral max_val, Random& generator = Random::GLOBAL_UNIFORM);
boolean grand(TIntegral mean, TIntegral stdev, Random& generator = Random::GLOBAL_GAUSSIAN);
double determinant() const;
boolean inverse();
boolean inverse(const MMatrix& matrix);
boolean transpose();
boolean transpose(const MMatrix& matrix);
long rank() const;
TIntegral trace() const;
boolean decompositionLU(MMatrix& lower_trig, MMatrix& upper_trig) const;
boolean decompositionLU(MMatrix& lower_trig, MMatrix& upper_trig, MVector<Long, long>& index, long& sign, double stabilize = THRESH_STABLE) const;
boolean decompositionCholesky(MMatrix& lower_trig) const;
boolean decompositionSVD(MMatrix& u, MMatrix& w, MMatrix& v, boolean economy_mode = true) const;
boolean decompositionQR(MMatrix& q, MMatrix& r);
boolean eigen(TVector& eigvals, MMatrix& eigvects) const;
boolean luSolve(MVector<TScalar, TIntegral>& out_vec, const MMatrix& l, const MMatrix& u, const MVector<TScalar, TIntegral>& in_vec);
boolean luSolve(MVector<TScalar, TIntegral>& out_vec, const MMatrix& l, const MMatrix& u, const VectorLong& index, const MVector<TScalar, TIntegral>& in_vec);
boolean choleskySolve(MVector<TScalar, TIntegral>& out_vec, const MMatrix& l, const MVector<TScalar, TIntegral>& in_vec);
boolean svdSolve(MVector<TScalar, TIntegral>& out_vec, const MMatrix& u, const MMatrix& w, const MMatrix& v, const MVector<TScalar, TIntegral>& in_vec, boolean zero_singulars = false);
boolean multv(TVector& output_vector, const TVector& input_vector) const;
boolean vmult(TVector& output_vector, const TVector& input_vector) const;
boolean quadratic(TIntegral& output, const TVector& in_vec) const;
boolean quadratic(MMatrix& output, const MMatrix& input) const;
boolean outerProduct();
boolean outerProduct(const MMatrix& m1);
boolean outerProduct(const MMatrix& m1, const MMatrix& m2);
boolean outerProduct(const TVector& v1);
boolean outerProduct(const TVector& v1, MVector& v2);
TIntegral sum() const;
TIntegral sumSquare() const;
TIntegral sumColumn(long col_index) const;
TIntegral sumRow(long row_index) const;
TIntegral mean() const;
TIntegral rms() const;
double var() const;
long index(long row_index, long col_index) const;
long index(long row_index, long col_index, long num_rows, long num_cols, Integral::MTYPE type = Integral::UNCHANGED) const;
boolean reverseIndex(long& row_index, long& col_index, long vec_index) const;
long startRow(long row_index, Integral::MTYPE type_1, Integral::MTYPE type_2 = Integral::UNCHANGED) const;
long stopRow(long row_index, Integral::MTYPE type_1, Integral::MTYPE type_2 = Integral::UNCHANGED) const;
long startColumn(long row_index, Integral::MTYPE type_1, Integral::MTYPE type_2 = Integral::UNCHANGED) const;
long stopColumn(long row_index, Integral::MTYPE type_1, Integral::MTYPE type_2 = Integral::UNCHANGED) const;
long vecLength() const;
long vecLength(long nrows, long ncols, Integral::MTYPE type) const;
boolean vecResetCapacity(long nrows, long ncols, Integral::MTYPE type) const;
boolean vecResizeCapacity(long nrows, long ncols);
boolean vecCreateLength(long nrows, long ncols, Integral::MTYPE type);
boolean vecDimensionLength(long nrows, long ncols, boolean preserve_values);
boolean randIndicesSparse(Random& generator = Random::GLOBAL_UNIFORM);
boolean sortSparse();
TIntegral multiplyRowByColumn(const MMatrix& matrix_for_row, const MMatrix<TAScalar, TAIntegral>& matrix_for_col, long row_index, long col_index) const;
TIntegral multiplyRowByRow(const MMatrix& matrix_for_row1, const MMatrix<TAScalar, TAIntegral>& matrix_for_row2, long row1_index, row2_index) const;
double determinantLU() const;
double determinantLU(const MMatrix& matrix) const;
double determinantMinor() const;
double determinantMinor(const MMatrix& matrix) const;
boolean eigenComputeVector(MVector<TScalar,TIntegral>& eigvect, TIntegral eigval);
boolean eigenBalance();
boolean eigenEliminateHessenberg();
boolean eigenHessenbergQR(MVector<Double, double>& eigval_real, MVector<Double, double>& eigval_imag) const;
boolean checkSquare(long nrows, long ncols, Integral::MTYPE type) const;
Integral::MTYPE checkType(Integral::MTYPE type) const;
boolean assignStream(long nrows, long ncols, const TVector& vec, Integral::MTYPE type);
long data[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; MMatrix<Long, long> mat1; mat1.assign(3, 3, data); MMatrix<Long, long> mat2; String file_name(L"foo"); Sof tmp_file; tmp_file.open(file_name, File::WRITE_ONLY, File::TEXT); // write the values // mat1.write(tmp_file, (long)0); // close the files // tmp_file.close(); // open the files in read mode // tmp_file.open(file_name); // read the values back in // if (!mat2.read(tmp_file, (long)0) || (!mat2.almostEqual(mat1))) { mat1.debug(L"mat g1"); mat2.debug(L"mat2"); return Error::handle(mat2.name(), L"read-text", Error::TEST, __FILE__,__LINE__); } tmp_file.close();