📄 newmat.h
字号:
{ 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) {} 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) {} void SetUpLHS(); friend class BaseMatrix;public: ~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 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)};// ************************** 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); 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);// ********************* 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) { return B.Minimum(); }inline Real Norm1(const BaseMatrix& B) { return B.Norm1(); }inline Real Norm1(RowVector& RV) { return RV.MaximumAbsoluteValue(); }inline Real NormInfinity(const BaseMatrix& B) { return B.NormInfinity(); }inline Real NormInfinity(ColumnVector& CV) { return CV.MaximumAbsoluteValue(); }inline bool IsZero(const GeneralMatrix& A) { return A.IsZero(); }#ifdef TEMPS_DESTROYED_QUICKLYinline ShiftedMatrix& operator+(Real f, const BaseMatrix& BM) { return BM + f; }inline ScaledMatrix& operator*(Real f, const BaseMatrix& BM) { return BM * f; }#endif#ifdef use_namespace}#endif#endif// body file: newmat1.cpp// body file: newmat2.cpp// body file: newmat3.cpp// body file: newmat4.cpp// body file: newmat5.cpp// body file: newmat6.cpp// body file: newmat7.cpp// body file: newmat8.cpp// body file: newmatex.cpp// body file: bandmat.cpp// body file: submat.cpp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -