📄 newmat.h
字号:
};
class NegatedMatrix : public BaseMatrix
{
protected:
union { const BaseMatrix* bm; GeneralMatrix* gm; };
NegatedMatrix(const BaseMatrix* bmx) : bm(bmx) {}
int search(const BaseMatrix*) const;
private:
friend class BaseMatrix;
public:
GeneralMatrix* Evaluate(MatrixType);
MatrixBandWidth BandWidth() const;
NEW_DELETE(NegatedMatrix)
};
class TransposedMatrix : public NegatedMatrix
{
TransposedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
friend class BaseMatrix;
public:
GeneralMatrix* Evaluate(MatrixType);
MatrixBandWidth BandWidth() const;
NEW_DELETE(TransposedMatrix)
};
class InvertedMatrix : public NegatedMatrix
{
InvertedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
public:
#ifndef TEMPS_DESTROYED_QUICKLY
SolvedMatrix operator*(const BaseMatrix&) const; // inverse(A) * B
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);
MatrixBandWidth BandWidth() const;
NEW_DELETE(InvertedMatrix)
};
class RowedMatrix : public NegatedMatrix
{
RowedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
friend class BaseMatrix;
public:
GeneralMatrix* Evaluate(MatrixType);
MatrixBandWidth BandWidth() const;
NEW_DELETE(RowedMatrix)
};
class ColedMatrix : public NegatedMatrix
{
ColedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
friend class BaseMatrix;
public:
GeneralMatrix* Evaluate(MatrixType);
MatrixBandWidth BandWidth() const;
NEW_DELETE(ColedMatrix)
};
class DiagedMatrix : public NegatedMatrix
{
DiagedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
friend class BaseMatrix;
public:
GeneralMatrix* Evaluate(MatrixType);
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:
GeneralMatrix* Evaluate(MatrixType);
MatrixBandWidth BandWidth() const;
NEW_DELETE(MatedMatrix)
};
class ConstMatrix : public BaseMatrix
{
const GeneralMatrix* cgm;
int search(const BaseMatrix*) const;
ConstMatrix(const GeneralMatrix* cgmx) : cgm(cgmx) {}
friend class BaseMatrix;
friend class GeneralMatrix;
public:
GeneralMatrix* Evaluate(MatrixType);
MatrixBandWidth BandWidth() const;
NEW_DELETE(ConstMatrix)
};
class ReturnMatrixX : public BaseMatrix // for matrix return
{
GeneralMatrix* gm;
int search(const BaseMatrix*) const;
public:
GeneralMatrix* Evaluate(MatrixType);
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;
Boolean IsSym;
GetSubMatrix
(const BaseMatrix* bmx, int rs, int rn, int cs, int cn, Boolean 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:
GeneralMatrix* Evaluate(MatrixType);
void operator=(const BaseMatrix&);
void operator=(const GetSubMatrix& m) { operator=((const BaseMatrix&)m); }
void operator<<(const BaseMatrix&);
void operator<<(const Real*); // copy from array
void operator=(Real); // copy from 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
{
static int n; // number values still to be read
static Real* r; // pointer to last thing read
static int depth; // number of objects of this class in existence
public:
MatrixInput() { depth++; }
MatrixInput(const MatrixInput&) { depth++; }
~MatrixInput();
MatrixInput operator<<(Real);
// could return a reference if we don't have
// TEMPS_DESTROYED_QUICKLY
friend class GeneralMatrix;
};
/***************************** exceptions ********************************/
class MatrixDetails
{
MatrixType type;
int nrows;
int ncols;
int ubw;
int lbw;
public:
MatrixDetails(const GeneralMatrix& A);
void PrintOut();
};
class SpaceException : public Exception
{
public:
static long st_type() { return 2; }
long type() const { return 2; }
static int action;
SpaceException();
static void SetAction(int a) { action=a; }
SpaceException(const SpaceException&) {}
};
class MatrixException : public Exception
{
protected:
MatrixException() {}
public:
static long st_type() { return 3; }
long type() const { return 3; }
MatrixException(int);
MatrixException(int, const GeneralMatrix&);
MatrixException(int, const GeneralMatrix&, const GeneralMatrix&);
MatrixException(const MatrixException&) {}
};
class DataException : public MatrixException
{
protected:
DataException() {}
public:
static long st_type() { return 3*53; }
long type() const { return 3*53; }
static int action;
DataException(const GeneralMatrix& A);
static void SetAction(int a) { action=a; }
DataException(const DataException&) {}
};
class SingularException : public DataException
{
public:
static long st_type() { return 3*53*109; }
long type() const { return 3*53*109; }
SingularException(const GeneralMatrix& A);
SingularException(const SingularException&) {}
};
class NPDException : public DataException // Not positive definite
{
public:
static long st_type() { return 3*53*113; }
long type() const { return 3*53*113; }
NPDException(const GeneralMatrix&);
NPDException(const NPDException&) {}
};
class ConvergenceException : public MatrixException
{
public:
static long st_type() { return 3*59; }
long type() const { return 3*59; }
static int action;
ConvergenceException(const GeneralMatrix& A);
static void SetAction(int a) { action=a; }
ConvergenceException(const ConvergenceException&) {}
};
class ProgramException : public MatrixException
{
protected:
ProgramException() {}
ProgramException(int); // int is not used
public:
static long st_type() { return 3*61; }
long type() const { return 3*61; }
static int action;
ProgramException(char* c);
ProgramException(char* c, const GeneralMatrix&);
ProgramException(char* c, const GeneralMatrix&, const GeneralMatrix&);
ProgramException(char* c, MatrixType, MatrixType);
ProgramException(const GeneralMatrix&);
static void SetAction(int a) { action=a; }
ProgramException(const ProgramException&) {}
};
class IndexException : public ProgramException
{
public:
static long st_type() { return 3*61*101; }
long type() const { return 3*61*101; }
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, Boolean);
IndexException(int i, int j, const GeneralMatrix& A, Boolean);
IndexException(const IndexException&) {}
};
class VectorException : public ProgramException // can't convert to vector
{
public:
static long st_type() { return 3*61*107; }
long type() const { return 3*61*107; }
VectorException();
VectorException(const GeneralMatrix& A);
VectorException(const VectorException&) {}
};
class NotSquareException : public ProgramException
{
public:
static long st_type() { return 3*61*109; }
long type() const { return 3*61*109; }
NotSquareException(const GeneralMatrix& A);
NotSquareException(const NotSquareException&) {}
};
class SubMatrixDimensionException : public ProgramException
{
public:
static long st_type() { return 3*61*113; }
long type() const { return 3*61*113; }
SubMatrixDimensionException();
SubMatrixDimensionException(const SubMatrixDimensionException&) {}
};
class IncompatibleDimensionsException : public ProgramException
{
public:
static long st_type() { return 3*61*127; }
long type() const { return 3*61*127; }
IncompatibleDimensionsException();
IncompatibleDimensionsException(const IncompatibleDimensionsException&) {}
};
class NotDefinedException : public ProgramException
{
public:
static long st_type() { return 3*61*131; }
long type() const { return 3*61*131; }
NotDefinedException(char* op, char* matrix);
NotDefinedException(const NotDefinedException&) {}
};
class CannotBuildException : public ProgramException
{
public:
static long st_type() { return 3*61*137; }
long type() const { return 3*61*137; }
CannotBuildException(char* matrix);
CannotBuildException(const CannotBuildException&) {}
};
class InternalException : public MatrixException
{
public:
static long st_type() { return 3*67; }
long type() const { return 3*67; }
static int action;
InternalException(char* c);
static void SetAction(int a) { action=a; }
InternalException(const InternalException&) {}
};
/***************************** functions ***********************************/
inline LogAndSign LogDeterminant(const BaseMatrix& B)
{ return B.LogDeterminant(); }
inline Real SumSquare(const BaseMatrix& B) { return B.SumSquare(); }
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 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(); }
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -