newmat.h
来自「matrix library for linux and windos」· C头文件 代码 · 共 1,758 行 · 第 1/5 页
H
1,758 行
ScaledMatrix operator*(Real t) const { return BaseMatrix::operator*(t); }#else SolvedMatrix& operator*(const BaseMatrix&); // inverse(A) * B ScaledMatrix& operator*(Real t) const { return BaseMatrix::operator*(t); }#endif friend class BaseMatrix; GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp); MatrixBandWidth BandWidth() const; NEW_DELETE(InvertedMatrix)};class RowedMatrix : public NegatedMatrix{ RowedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {} friend class BaseMatrix;public: ~RowedMatrix() {} GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp); MatrixBandWidth BandWidth() const; NEW_DELETE(RowedMatrix)};class ColedMatrix : public NegatedMatrix{ ColedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {} friend class BaseMatrix;public: ~ColedMatrix() {} GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp); MatrixBandWidth BandWidth() const; NEW_DELETE(ColedMatrix)};class DiagedMatrix : public NegatedMatrix{ DiagedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {} friend class BaseMatrix;public: ~DiagedMatrix() {} GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp); MatrixBandWidth BandWidth() const; NEW_DELETE(DiagedMatrix)};class MatedMatrix : public NegatedMatrix{ int nr, nc; MatedMatrix(const BaseMatrix* bmx, int nrx, int ncx) : NegatedMatrix(bmx), nr(nrx), nc(ncx) {} friend class BaseMatrix;public: ~MatedMatrix() {} GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp); MatrixBandWidth BandWidth() const; NEW_DELETE(MatedMatrix)};class ReturnMatrixX : public BaseMatrix // for matrix return{ GeneralMatrix* gm; int search(const BaseMatrix*) const;public: ~ReturnMatrixX() {} GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp); friend class BaseMatrix;#ifdef TEMPS_DESTROYED_QUICKLY_R ReturnMatrixX(const ReturnMatrixX& tm);#else ReturnMatrixX(const ReturnMatrixX& tm) : gm(tm.gm) {}#endif ReturnMatrixX(const GeneralMatrix* gmx) : gm((GeneralMatrix*&)gmx) {}// ReturnMatrixX(GeneralMatrix&); MatrixBandWidth BandWidth() const; NEW_DELETE(ReturnMatrixX)};// ************************** submatrices ******************************/class GetSubMatrix : public NegatedMatrix{ int row_skip; int row_number; int col_skip; int col_number; bool IsSym; GetSubMatrix (const BaseMatrix* bmx, int rs, int rn, int cs, int cn, bool is) : NegatedMatrix(bmx), row_skip(rs), row_number(rn), col_skip(cs), col_number(cn), IsSym(is) {} void SetUpLHS(); friend class BaseMatrix;public: GetSubMatrix(const GetSubMatrix& g) : NegatedMatrix(g.bm), row_skip(g.row_skip), row_number(g.row_number), col_skip(g.col_skip), col_number(g.col_number), IsSym(g.IsSym) {} ~GetSubMatrix() {} GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp); void operator=(const BaseMatrix&); void operator+=(const BaseMatrix&); void operator-=(const BaseMatrix&); void operator=(const GetSubMatrix& m) { operator=((const BaseMatrix&)m); } void operator<<(const BaseMatrix&); void operator<<(const Real*); // copy from array MatrixInput operator<<(Real); // for loading a list MatrixInput operator<<(int f); void operator=(Real); // copy from constant void operator+=(Real); // add constant void operator-=(Real r) { operator+=(-r); } // subtract constant void operator*=(Real); // multiply by constant void operator/=(Real r) { operator*=(1.0/r); } // divide by constant void Inject(const GeneralMatrix&); // copy stored els only MatrixBandWidth BandWidth() const; NEW_DELETE(GetSubMatrix)};// ******************** linear equation solving ****************************/class LinearEquationSolver : public BaseMatrix{ GeneralMatrix* gm; int search(const BaseMatrix*) const { return 0; } friend class BaseMatrix;public: LinearEquationSolver(const BaseMatrix& bm); ~LinearEquationSolver() { delete gm; } void CleanUp() { delete gm; } GeneralMatrix* Evaluate(MatrixType) { return gm; } // probably should have an error message if MatrixType != UnSp NEW_DELETE(LinearEquationSolver)};// ************************** matrix input *******************************/class MatrixInput // for reading a list of values into a matrix // the difficult part is detecting a mismatch // in the number of elements{ int n; // number values still to be read Real* r; // pointer to next location to be read topublic: MatrixInput(const MatrixInput& mi) : n(mi.n), r(mi.r) {} MatrixInput(int nx, Real* rx) : n(nx), r(rx) {} ~MatrixInput(); MatrixInput operator<<(Real); MatrixInput operator<<(int f); friend class GeneralMatrix;};// **************** a very simple integer array class ********************/// A minimal array class to imitate a C style array but giving dynamic storage// mostly intended for internal use by newmatclass SimpleIntArray : public Janitor{protected: int* a; // pointer to the array int n; // length of the arraypublic: SimpleIntArray(int xn); // build an array length xn ~SimpleIntArray(); // return the space to memory int& operator[](int i); // access element of the array - start at 0 int operator[](int i) const; // access element of constant array void operator=(int ai); // set the array equal to a constant void operator=(const SimpleIntArray& b); // copy the elements of an array SimpleIntArray(const SimpleIntArray& b); // make a new array equal to an existing one int Size() const { return n; } // return the size of the array int* Data() { return a; } // pointer to the data const int* Data() const { return a; } // pointer to the data void ReSize(int i, bool keep = false); // change length, keep data if keep = true void CleanUp() { ReSize(0); } NEW_DELETE(SimpleIntArray)};// *************************** exceptions ********************************/class NPDException : public Runtime_error // Not positive definite{public: static unsigned long Select; // for identifying exception NPDException(const GeneralMatrix&);};class ConvergenceException : public Runtime_error{public: static unsigned long Select; // for identifying exception ConvergenceException(const GeneralMatrix& A); ConvergenceException(const char* c);};class SingularException : public Runtime_error{public: static unsigned long Select; // for identifying exception SingularException(const GeneralMatrix& A);};class OverflowException : public Runtime_error{public: static unsigned long Select; // for identifying exception OverflowException(const char* c);};class ProgramException : public Logic_error{protected: ProgramException();public: static unsigned long Select; // for identifying exception ProgramException(const char* c); ProgramException(const char* c, const GeneralMatrix&); ProgramException(const char* c, const GeneralMatrix&, const GeneralMatrix&); ProgramException(const char* c, MatrixType, MatrixType);};class IndexException : public Logic_error{public: static unsigned long Select; // for identifying exception IndexException(int i, const GeneralMatrix& A); IndexException(int i, int j, const GeneralMatrix& A); // next two are for access via element function IndexException(int i, const GeneralMatrix& A, bool); IndexException(int i, int j, const GeneralMatrix& A, bool);};class VectorException : public Logic_error // cannot convert to vector{public: static unsigned long Select; // for identifying exception VectorException(); VectorException(const GeneralMatrix& A);};class NotSquareException : public Logic_error{public: static unsigned long Select; // for identifying exception NotSquareException(const GeneralMatrix& A);};class SubMatrixDimensionException : public Logic_error{public: static unsigned long Select; // for identifying exception SubMatrixDimensionException();};class IncompatibleDimensionsException : public Logic_error{public: static unsigned long Select; // for identifying exception IncompatibleDimensionsException(); IncompatibleDimensionsException(const GeneralMatrix&, const GeneralMatrix&);};class NotDefinedException : public Logic_error{public: static unsigned long Select; // for identifying exception NotDefinedException(const char* op, const char* matrix);};class CannotBuildException : public Logic_error{public: static unsigned long Select; // for identifying exception CannotBuildException(const char* matrix);};class InternalException : public Logic_error{public: static unsigned long Select; // for identifying exception InternalException(const char* c);};// ************************ functions ************************************ //bool operator==(const GeneralMatrix& A, const GeneralMatrix& B);bool operator==(const BaseMatrix& A, const BaseMatrix& B);inline bool operator!=(const GeneralMatrix& A, const GeneralMatrix& B) { return ! (A==B); }inline bool operator!=(const BaseMatrix& A, const BaseMatrix& B) { return ! (A==B); } // inequality operators are dummies included for compatibility // with STL. They throw an exception if actually called.inline bool operator<=(const BaseMatrix& A, const BaseMatrix&) { A.IEQND(); return true; }inline bool operator>=(const BaseMatrix& A, const BaseMatrix&) { A.IEQND(); return true; }inline bool operator<(const BaseMatrix& A, const BaseMatrix&) { A.IEQND(); return true; }inline bool operator>(const BaseMatrix& A, const BaseMatrix&) { A.IEQND(); return true; }bool IsZero(const BaseMatrix& A);// *********************** friend functions ****************************** //bool Rectangular(MatrixType a, MatrixType b, MatrixType c);bool Compare(const MatrixType&, MatrixType&);Real DotProduct(const Matrix& A, const Matrix& B);#ifndef TEMPS_DESTROYED_QUICKLY SPMatrix SP(const BaseMatrix&, const BaseMatrix&); KPMatrix KP(const BaseMatrix&, const BaseMatrix&); ShiftedMatrix operator+(Real f, const BaseMatrix& BM); NegShiftedMatrix operator-(Real, const BaseMatrix&); ScaledMatrix operator*(Real f, const BaseMatrix& BM);#else SPMatrix& SP(const BaseMatrix&, const BaseMatrix&); KPMatrix& KP(const BaseMatrix&, const BaseMatrix&); NegShiftedMatrix& operator-(Real, const BaseMatrix&);#endif// ********************* inline functions ******************************** //inline LogAndSign LogDeterminant(const BaseMatrix& B) { return B.LogDeterminant(); }inline Real Determinant(const BaseMatrix& B) { return B.Determinant(); }inline Real SumSquare(const BaseMatrix& B) { return B.SumSquare(); }inline Real NormFrobenius(const BaseMatrix& B) { return B.NormFrobenius(); }inline Real Trace(const BaseMatrix& B) { return B.Trace(); }inline Real SumAbsoluteValue(const BaseMatrix& B) { return B.SumAbsoluteValue(); }inline Real Sum(const BaseMatrix& B) { return B.Sum(); }inline Real MaximumAbsoluteValue(const BaseMatrix& B) { return B.MaximumAbsoluteValue(); }inline Real MinimumAbsoluteValue(const BaseMatrix& B) { return B.MinimumAbsoluteValue(); }inline Real Maximum(const BaseMatrix& B) { return B.Maximum(); }inline Real Minimum(const BaseMatrix& B) { retu
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?