00001
00002
00003
00004
00005 #ifndef NEWMAT_LIB
00006 #define NEWMAT_LIB 0
00007
00008 #include "include.h"
00009
00010 #include "boolean.h"
00011 #include "myexcept.h"
00012
00013
00014 #ifdef use_namespace
00015 namespace NEWMAT { using namespace RBD_COMMON; }
00016 namespace RBD_LIBRARIES { using namespace NEWMAT; }
00017 namespace NEWMAT {
00018 #endif
00019
00020
00021
00022 #ifdef NO_LONG_NAMES
00023 #define UpperTriangularMatrix UTMatrix
00024 #define LowerTriangularMatrix LTMatrix
00025 #define SymmetricMatrix SMatrix
00026 #define DiagonalMatrix DMatrix
00027 #define BandMatrix BMatrix
00028 #define UpperBandMatrix UBMatrix
00029 #define LowerBandMatrix LBMatrix
00030 #define SymmetricBandMatrix SBMatrix
00031 #define BandLUMatrix BLUMatrix
00032 #endif
00033
00034 #ifndef TEMPS_DESTROYED_QUICKLY_R
00035 #define ReturnMatrix ReturnMatrixX
00036 #else
00037 #define ReturnMatrix ReturnMatrixX&
00038 #endif
00039
00040
00041
00042 class GeneralMatrix;
00043
00044 void MatrixErrorNoSpace(void*);
00045
00046 class LogAndSign
00047
00048
00049 {
00050 Real log_value;
00051 int sign;
00052 public:
00053 LogAndSign() { log_value=0.0; sign=1; }
00054 LogAndSign(Real);
00055 void operator*=(Real);
00056 void PowEq(int k);
00057 void ChangeSign() { sign = -sign; }
00058 Real LogValue() const { return log_value; }
00059 int Sign() const { return sign; }
00060 Real Value() const;
00061 FREE_CHECK(LogAndSign)
00062 };
00063
00064
00065
00066
00067
00068
00069
00070
00071 #ifdef DO_REPORT
00072
00073 class ExeCounter
00074 {
00075 int line;
00076 int fileid;
00077 long nexe;
00078 static int nreports;
00079 public:
00080 ExeCounter(int,int);
00081 void operator++() { nexe++; }
00082 ~ExeCounter();
00083 };
00084
00085 #endif
00086
00087
00088
00089
00090
00091
00092
00093
00094 class GeneralMatrix;
00095 class BaseMatrix;
00096 class MatrixInput;
00097
00098 class MatrixType
00099 {
00100 public:
00101 enum Attribute { Valid = 1,
00102 Diagonal = 2,
00103 Symmetric = 4,
00104 Band = 8,
00105 Lower = 16,
00106 Upper = 32,
00107 LUDeco = 64,
00108 Ones = 128 };
00109
00110 enum { US = 0,
00111 UT = Valid + Upper,
00112 LT = Valid + Lower,
00113 Rt = Valid,
00114 Sm = Valid + Symmetric,
00115 Dg = Valid + Diagonal + Band + Lower + Upper + Symmetric,
00116 Id = Valid + Diagonal + Band + Lower + Upper + Symmetric
00117 + Ones,
00118 RV = Valid,
00119 CV = Valid,
00120 BM = Valid + Band,
00121 UB = Valid + Band + Upper,
00122 LB = Valid + Band + Lower,
00123 SB = Valid + Band + Symmetric,
00124 Ct = Valid + LUDeco,
00125 BC = Valid + Band + LUDeco
00126 };
00127
00128
00129 static int nTypes() { return 10; }
00130
00131 public:
00132 int attribute;
00133 bool DataLossOK;
00134
00135 public:
00136 MatrixType () : DataLossOK(false) {}
00137 MatrixType (int i) : attribute(i), DataLossOK(false) {}
00138 MatrixType (int i, bool dlok) : attribute(i), DataLossOK(dlok) {}
00139 MatrixType (const MatrixType& mt)
00140 : attribute(mt.attribute), DataLossOK(mt.DataLossOK) {}
00141 void operator=(const MatrixType& mt)
00142 { attribute = mt.attribute; DataLossOK = mt.DataLossOK; }
00143 void SetDataLossOK() { DataLossOK = true; }
00144 int operator+() const { return attribute; }
00145 MatrixType operator+(MatrixType mt) const
00146 { return MatrixType(attribute & mt.attribute); }
00147 MatrixType operator*(const MatrixType&) const;
00148 MatrixType SP(const MatrixType&) const;
00149 MatrixType KP(const MatrixType&) const;
00150 MatrixType operator|(const MatrixType& mt) const
00151 { return MatrixType(attribute & mt.attribute & Valid); }
00152 MatrixType operator&(const MatrixType& mt) const
00153 { return MatrixType(attribute & mt.attribute & Valid); }
00154 bool operator>=(MatrixType mt) const
00155 { return ( attribute & mt.attribute ) == attribute; }
00156 bool operator<(MatrixType mt) const
00157 { return ( attribute & mt.attribute ) != attribute; }
00158 bool operator==(MatrixType t) const
00159 { return (attribute == t.attribute); }
00160 bool operator!=(MatrixType t) const
00161 { return (attribute != t.attribute); }
00162 bool operator!() const { return (attribute & Valid) == 0; }
00163 MatrixType i() const;
00164 MatrixType t() const;
00165 MatrixType AddEqualEl() const
00166 { return MatrixType(attribute & (Valid + Symmetric)); }
00167 MatrixType MultRHS() const;
00168 MatrixType sub() const
00169 { return MatrixType(attribute & Valid); }
00170 MatrixType ssub() const
00171 { return MatrixType(attribute); }
00172 GeneralMatrix* New() const;
00173 GeneralMatrix* New(int,int,BaseMatrix*) const;
00174
00175 const char* Value() const;
00176 friend bool Rectangular(MatrixType a, MatrixType b, MatrixType c);
00177 friend bool Compare(const MatrixType&, MatrixType&);
00178
00179 bool IsBand() const { return (attribute & Band) != 0; }
00180 bool IsDiagonal() const { return (attribute & Diagonal) != 0; }
00181 bool IsSymmetric() const { return (attribute & Symmetric) != 0; }
00182 bool CannotConvert() const { return (attribute & LUDeco) != 0; }
00183
00184 FREE_CHECK(MatrixType)
00185 };
00186
00187
00188
00189
00190 class MatrixBandWidth
00191 {
00192 public:
00193 int lower;
00194 int upper;
00195 MatrixBandWidth(const int l, const int u) : lower(l), upper (u) {}
00196 MatrixBandWidth(const int i) : lower(i), upper(i) {}
00197 MatrixBandWidth operator+(const MatrixBandWidth&) const;
00198 MatrixBandWidth operator*(const MatrixBandWidth&) const;
00199 MatrixBandWidth minimum(const MatrixBandWidth&) const;
00200 MatrixBandWidth t() const { return MatrixBandWidth(upper,lower); }
00201 bool operator==(const MatrixBandWidth& bw) const
00202 { return (lower == bw.lower) && (upper == bw.upper); }
00203 bool operator!=(const MatrixBandWidth& bw) const { return !operator==(bw); }
00204 int Upper() const { return upper; }
00205 int Lower() const { return lower; }
00206 FREE_CHECK(MatrixBandWidth)
00207 };
00208
00209
00210
00211
00212
00213
00214
00215
00216 class ArrayLengthSpecifier
00217 {
00218 int value;
00219 public:
00220 int Value() const { return value; }
00221 ArrayLengthSpecifier(int l) : value(l) {}
00222 };
00223
00224
00225
00226
00227 class MatrixRowCol;
00228 class MatrixRow;
00229 class MatrixCol;
00230 class MatrixColX;
00231
00232 class GeneralMatrix;
00233 class AddedMatrix;
00234 class MultipliedMatrix;
00235 class SubtractedMatrix;
00236 class SPMatrix;
00237 class KPMatrix;
00238 class ConcatenatedMatrix;
00239 class StackedMatrix;
00240 class SolvedMatrix;
00241 class ShiftedMatrix;
00242 class NegShiftedMatrix;
00243 class ScaledMatrix;
00244 class TransposedMatrix;
00245 class ReversedMatrix;
00246 class NegatedMatrix;
00247 class InvertedMatrix;
00248 class RowedMatrix;
00249 class ColedMatrix;
00250 class DiagedMatrix;
00251 class MatedMatrix;
00252 class GetSubMatrix;
00253 class ReturnMatrixX;
00254 class Matrix;
00255 class nricMatrix;
00256 class RowVector;
00257 class ColumnVector;
00258 class SymmetricMatrix;
00259 class UpperTriangularMatrix;
00260 class LowerTriangularMatrix;
00261 class DiagonalMatrix;
00262 class CroutMatrix;
00263 class BandMatrix;
00264 class LowerBandMatrix;
00265 class UpperBandMatrix;
00266 class SymmetricBandMatrix;
00267 class LinearEquationSolver;
00268 class GenericMatrix;
00269
00270
00271 #define MatrixTypeUnSp 0
00272
00273
00274
00275 class BaseMatrix : public Janitor
00276 {
00277 protected:
00278 virtual int search(const BaseMatrix*) const = 0;
00279
00280
00281
00282 public:
00283 virtual GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp) = 0;
00284
00285
00286
00287
00288 #ifndef TEMPS_DESTROYED_QUICKLY
00289 AddedMatrix operator+(const BaseMatrix&) const;
00290 MultipliedMatrix operator*(const BaseMatrix&) const;
00291 SubtractedMatrix operator-(const BaseMatrix&) const;
00292 ConcatenatedMatrix operator|(const BaseMatrix&) const;
00293 StackedMatrix operator&(const BaseMatrix&) const;
00294 ShiftedMatrix operator+(Real) const;
00295 ScaledMatrix operator*(Real) const;
00296 ScaledMatrix operator/(Real) const;
00297 ShiftedMatrix operator-(Real) const;
00298 TransposedMatrix t() const;
00299
00300 NegatedMatrix operator-() const;
00301 ReversedMatrix Reverse() const;
00302 InvertedMatrix i() const;
00303
00304 RowedMatrix AsRow() const;
00305 ColedMatrix AsColumn() const;
00306 DiagedMatrix AsDiagonal() const;
00307 MatedMatrix AsMatrix(int,int) const;
00308 GetSubMatrix SubMatrix(int,int,int,int) const;
00309 GetSubMatrix SymSubMatrix(int,int) const;
00310 GetSubMatrix Row(int) const;
00311 GetSubMatrix Rows(int,int) const;
00312 GetSubMatrix Column(int) const;
00313 GetSubMatrix Columns(int,int) const;
00314 #else
00315 AddedMatrix& operator+(const BaseMatrix&) const;
00316 MultipliedMatrix& operator*(const BaseMatrix&) const;
00317 SubtractedMatrix& operator-(const BaseMatrix&) const;
00318 ConcatenatedMatrix& operator|(const BaseMatrix&) const;
00319 StackedMatrix& operator&(const BaseMatrix&) const;
00320 ShiftedMatrix& operator+(Real) const;
00321 ScaledMatrix& operator*(Real) const;
00322 ScaledMatrix& operator/(Real) const;
00323 ShiftedMatrix& operator-(Real) const;
00324 TransposedMatrix& t() const;
00325
00326 NegatedMatrix& operator-() const;
00327 ReversedMatrix& Reverse() const;
00328 InvertedMatrix& i() const;
00329
00330 RowedMatrix& AsRow() const;
00331 ColedMatrix& AsColumn() const;
00332 DiagedMatrix& AsDiagonal() const;
00333 MatedMatrix& AsMatrix(int,int) const;
00334 GetSubMatrix& SubMatrix(int,int,int,int) const;
00335 GetSubMatrix& SymSubMatrix(int,int) const;
00336 GetSubMatrix& Row(int) const;
00337 GetSubMatrix& Rows(int,int) const;
00338 GetSubMatrix& Column(int) const;
00339 GetSubMatrix& Columns(int,int) const;
00340 #endif
00341 Real AsScalar() const;
00342 virtual LogAndSign LogDeterminant() const;
00343 Real Determinant() const;
00344 virtual Real SumSquare() const;
00345 Real NormFrobenius() const;
00346 virtual Real SumAbsoluteValue() const;
00347 virtual Real Sum() const;
00348 virtual Real MaximumAbsoluteValue() const;
00349 virtual Real MaximumAbsoluteValue1(int& i) const;
00350 virtual Real MaximumAbsoluteValue2(int& i, int& j) const;
00351 virtual Real MinimumAbsoluteValue() const;
00352 virtual Real MinimumAbsoluteValue1(int& i) const;
00353 virtual Real MinimumAbsoluteValue2(int& i, int& j) const;
00354 virtual Real Maximum() const;
00355 virtual Real Maximum1(int& i) const;
00356 virtual Real Maximum2(int& i, int& j) const;
00357 virtual Real Minimum() const;
00358 virtual Real Minimum1(int& i) const;
00359 virtual Real Minimum2(int& i, int& j) const;
00360 virtual Real Trace() const;
00361 Real Norm1() const;
00362 Real NormInfinity() const;
00363 virtual MatrixBandWidth BandWidth() const;
00364 virtual void CleanUp() {}
00365 void IEQND() const;
00366
00367
00368
00369
00370
00371
00372 friend class GeneralMatrix;
00373 friend class Matrix;
00374 friend class nricMatrix;
00375 friend class RowVector;
00376 friend class ColumnVector;
00377 friend class SymmetricMatrix;
00378 friend class UpperTriangularMatrix;
00379 friend class LowerTriangularMatrix;
00380 friend class DiagonalMatrix;
00381 friend class CroutMatrix;
00382 friend class BandMatrix;
00383 friend class LowerBandMatrix;
00384 friend class UpperBandMatrix;
00385 friend class SymmetricBandMatrix;
00386 friend class AddedMatrix;
00387 friend class MultipliedMatrix;
00388 friend class SubtractedMatrix;
00389 friend class SPMatrix;
00390 friend class KPMatrix;
00391 friend class ConcatenatedMatrix;
00392 friend class StackedMatrix;
00393 friend class SolvedMatrix;
00394 friend class ShiftedMatrix;
00395 friend class NegShiftedMatrix;
00396 friend class ScaledMatrix;
00397 friend class TransposedMatrix;
00398 friend class ReversedMatrix;
00399 friend class NegatedMatrix;
00400 friend class InvertedMatrix;
00401 friend class RowedMatrix;
00402 friend class ColedMatrix;
00403 friend class DiagedMatrix;
00404 friend class MatedMatrix;
00405 friend class GetSubMatrix;
00406 friend class ReturnMatrixX;
00407 friend class LinearEquationSolver;
00408 friend class GenericMatrix;
00409 NEW_DELETE(BaseMatrix)
00410 };
00411
00412
00413
00414
00415 class GeneralMatrix : public BaseMatrix
00416 {
00417 virtual GeneralMatrix* Image() const;
00418 protected:
00419 int tag;
00420 int nrows, ncols;
00421 int storage;
00422 Real* store;
00423 GeneralMatrix();
00424 GeneralMatrix(ArrayLengthSpecifier);
00425 void Add(GeneralMatrix*, Real);
00426 void Add(Real);
00427 void NegAdd(GeneralMatrix*, Real);
00428 void NegAdd(Real);
00429 void Multiply(GeneralMatrix*, Real);
00430 void Multiply(Real);
00431 void Negate(GeneralMatrix*);
00432 void Negate();
00433 void ReverseElements();
00434 void ReverseElements(GeneralMatrix*);
00435 void operator=(Real);
00436 Real* GetStore();
00437 GeneralMatrix* BorrowStore(GeneralMatrix*, MatrixType);
00438
00439 void GetMatrix(const GeneralMatrix*);
00440 void Eq(const BaseMatrix&, MatrixType);
00441 void Eq(const BaseMatrix&, MatrixType, bool);
00442 void Eq2(const BaseMatrix&, MatrixType);
00443 int search(const BaseMatrix*) const;
00444 virtual GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
00445 void CheckConversion(const BaseMatrix&);
00446 void ReSize(int, int, int);
00447 virtual short SimpleAddOK(const GeneralMatrix* gm) { return 0; }
00448
00449 public:
00450 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
00451 virtual MatrixType Type() const = 0;
00452 int Nrows() const { return nrows; }
00453 int Ncols() const { return ncols; }
00454 int Storage() const { return storage; }
00455 Real* Store() const { return store; }
00456 virtual ~GeneralMatrix();
00457 void tDelete();
00458 bool reuse();
00459 void Protect() { tag=-1; }
00460 int Tag() const { return tag; }
00461 bool IsZero() const;
00462 void Release() { tag=1; }
00463 void Release(int t) { tag=t; }
00464 void ReleaseAndDelete() { tag=0; }
00465 void operator<<(const Real*);
00466 void operator<<(const BaseMatrix& X)
00467 { Eq(X,this->Type(),true); }
00468 void Inject(const GeneralMatrix&);
00469 void operator+=(const BaseMatrix&);
00470 void operator-=(const BaseMatrix&);
00471 void operator*=(const BaseMatrix&);
00472 void operator|=(const BaseMatrix&);
00473 void operator&=(const BaseMatrix&);
00474 void operator+=(Real);
00475 void operator-=(Real r) { operator+=(-r); }
00476 void operator*=(Real);
00477 void operator/=(Real r) { operator*=(1.0/r); }
00478 virtual GeneralMatrix* MakeSolver();
00479 virtual void Solver(MatrixColX&, const MatrixColX&) {}
00480 virtual void GetRow(MatrixRowCol&) = 0;
00481 virtual void RestoreRow(MatrixRowCol&) {}
00482 virtual void NextRow(MatrixRowCol&);
00483 virtual void GetCol(MatrixRowCol&) = 0;
00484 virtual void GetCol(MatrixColX&) = 0;
00485 virtual void RestoreCol(MatrixRowCol&) {}
00486 virtual void RestoreCol(MatrixColX&) {}
00487 virtual void NextCol(MatrixRowCol&);
00488 virtual void NextCol(MatrixColX&);
00489 Real SumSquare() const;
00490 Real SumAbsoluteValue() const;
00491 Real Sum() const;
00492 Real MaximumAbsoluteValue1(int& i) const;
00493 Real MinimumAbsoluteValue1(int& i) const;
00494 Real Maximum1(int& i) const;
00495 Real Minimum1(int& i) const;
00496 Real MaximumAbsoluteValue() const;
00497 Real MaximumAbsoluteValue2(int& i, int& j) const;
00498 Real MinimumAbsoluteValue() const;
00499 Real MinimumAbsoluteValue2(int& i, int& j) const;
00500 Real Maximum() const;
00501 Real Maximum2(int& i, int& j) const;
00502 Real Minimum() const;
00503 Real Minimum2(int& i, int& j) const;
00504 LogAndSign LogDeterminant() const;
00505 virtual bool IsEqual(const GeneralMatrix&) const;
00506
00507 void CheckStore() const;
00508 virtual void SetParameters(const GeneralMatrix*) {}
00509
00510 operator ReturnMatrix() const;
00511 ReturnMatrix ForReturn() const;
00512 virtual bool SameStorageType(const GeneralMatrix& A) const;
00513 virtual void ReSizeForAdd(const GeneralMatrix& A, const GeneralMatrix& B);
00514 virtual void ReSizeForSP(const GeneralMatrix& A, const GeneralMatrix& B);
00515 virtual void ReSize(const GeneralMatrix& A);
00516 MatrixInput operator<<(Real);
00517 MatrixInput operator<<(int f);
00518
00519 void CleanUp();
00520
00521 friend class Matrix;
00522 friend class nricMatrix;
00523 friend class SymmetricMatrix;
00524 friend class UpperTriangularMatrix;
00525 friend class LowerTriangularMatrix;
00526 friend class DiagonalMatrix;
00527 friend class CroutMatrix;
00528 friend class RowVector;
00529 friend class ColumnVector;
00530 friend class BandMatrix;
00531 friend class LowerBandMatrix;
00532 friend class UpperBandMatrix;
00533 friend class SymmetricBandMatrix;
00534 friend class BaseMatrix;
00535 friend class AddedMatrix;
00536 friend class MultipliedMatrix;
00537 friend class SubtractedMatrix;
00538 friend class SPMatrix;
00539 friend class KPMatrix;
00540 friend class ConcatenatedMatrix;
00541 friend class StackedMatrix;
00542 friend class SolvedMatrix;
00543 friend class ShiftedMatrix;
00544 friend class NegShiftedMatrix;
00545 friend class ScaledMatrix;
00546 friend class TransposedMatrix;
00547 friend class ReversedMatrix;
00548 friend class NegatedMatrix;
00549 friend class InvertedMatrix;
00550 friend class RowedMatrix;
00551 friend class ColedMatrix;
00552 friend class DiagedMatrix;
00553 friend class MatedMatrix;
00554 friend class GetSubMatrix;
00555 friend class ReturnMatrixX;
00556 friend class LinearEquationSolver;
00557 friend class GenericMatrix;
00558 NEW_DELETE(GeneralMatrix)
00559 };
00560
00561
00562
00563 class Matrix : public GeneralMatrix
00564 {
00565 GeneralMatrix* Image() const;
00566 public:
00567 Matrix() {}
00568 ~Matrix() {}
00569 Matrix(int, int);
00570 Matrix(const BaseMatrix&);
00571 void operator=(const BaseMatrix&);
00572 void operator=(Real f) { GeneralMatrix::operator=(f); }
00573 void operator=(const Matrix& m) { operator=((const BaseMatrix&)m); }
00574 MatrixType Type() const;
00575 Real& operator()(int, int);
00576 Real& element(int, int);
00577 Real operator()(int, int) const;
00578 Real element(int, int) const;
00579 #ifdef SETUP_C_SUBSCRIPTS
00580 Real* operator[](int m) { return store+m*ncols; }
00581 const Real* operator[](int m) const { return store+m*ncols; }
00582 #endif
00583 Matrix(const Matrix& gm) { GetMatrix(&gm); }
00584 GeneralMatrix* MakeSolver();
00585 Real Trace() const;
00586 void GetRow(MatrixRowCol&);
00587 void GetCol(MatrixRowCol&);
00588 void GetCol(MatrixColX&);
00589 void RestoreCol(MatrixRowCol&);
00590 void RestoreCol(MatrixColX&);
00591 void NextRow(MatrixRowCol&);
00592 void NextCol(MatrixRowCol&);
00593 void NextCol(MatrixColX&);
00594 virtual void ReSize(int,int);
00595
00596 void ReSize(const GeneralMatrix& A);
00597 Real MaximumAbsoluteValue2(int& i, int& j) const;
00598 Real MinimumAbsoluteValue2(int& i, int& j) const;
00599 Real Maximum2(int& i, int& j) const;
00600 Real Minimum2(int& i, int& j) const;
00601 friend Real DotProduct(const Matrix& A, const Matrix& B);
00602 NEW_DELETE(Matrix)
00603 };
00604
00605 class nricMatrix : public Matrix
00606
00607 {
00608 GeneralMatrix* Image() const;
00609 Real** row_pointer;
00610 void MakeRowPointer();
00611 void DeleteRowPointer();
00612 public:
00613 nricMatrix() {}
00614 nricMatrix(int m, int n)
00615 : Matrix(m,n) { MakeRowPointer(); }
00616 nricMatrix(const BaseMatrix& bm)
00617 : Matrix(bm) { MakeRowPointer(); }
00618 void operator=(const BaseMatrix& bm)
00619 { DeleteRowPointer(); Matrix::operator=(bm); MakeRowPointer(); }
00620 void operator=(Real f) { GeneralMatrix::operator=(f); }
00621 void operator=(const nricMatrix& m) { operator=((const BaseMatrix&)m); }
00622 void operator<<(const BaseMatrix& X)
00623 { DeleteRowPointer(); Eq(X,this->Type(),true); MakeRowPointer(); }
00624 nricMatrix(const nricMatrix& gm) { GetMatrix(&gm); MakeRowPointer(); }
00625 void ReSize(int m, int n)
00626 { DeleteRowPointer(); Matrix::ReSize(m,n); MakeRowPointer(); }
00627 void ReSize(const GeneralMatrix& A);
00628 ~nricMatrix() { DeleteRowPointer(); }
00629 Real** nric() const { CheckStore(); return row_pointer-1; }
00630 void CleanUp();
00631 NEW_DELETE(nricMatrix)
00632 };
00633
00634 class SymmetricMatrix : public GeneralMatrix
00635 {
00636 GeneralMatrix* Image() const;
00637 public:
00638 SymmetricMatrix() {}
00639 ~SymmetricMatrix() {}
00640 SymmetricMatrix(ArrayLengthSpecifier);
00641 SymmetricMatrix(const BaseMatrix&);
00642 void operator=(const BaseMatrix&);
00643 void operator=(Real f) { GeneralMatrix::operator=(f); }
00644 void operator=(const SymmetricMatrix& m) { operator=((const BaseMatrix&)m); }
00645 Real& operator()(int, int);
00646 Real& element(int, int);
00647 Real operator()(int, int) const;
00648 Real element(int, int) const;
00649 #ifdef SETUP_C_SUBSCRIPTS
00650 Real* operator[](int m) { return store+(m*(m+1))/2; }
00651 const Real* operator[](int m) const { return store+(m*(m+1))/2; }
00652 #endif
00653 MatrixType Type() const;
00654 SymmetricMatrix(const SymmetricMatrix& gm) { GetMatrix(&gm); }
00655 Real SumSquare() const;
00656 Real SumAbsoluteValue() const;
00657 Real Sum() const;
00658 Real Trace() const;
00659 void GetRow(MatrixRowCol&);
00660 void GetCol(MatrixRowCol&);
00661 void GetCol(MatrixColX&);
00662 void RestoreCol(MatrixRowCol&) {}
00663 void RestoreCol(MatrixColX&);
00664 GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
00665 void ReSize(int);
00666 void ReSize(const GeneralMatrix& A);
00667 NEW_DELETE(SymmetricMatrix)
00668 };
00669
00670 class UpperTriangularMatrix : public GeneralMatrix
00671 {
00672 GeneralMatrix* Image() const;
00673 public:
00674 UpperTriangularMatrix() {}
00675 ~UpperTriangularMatrix() {}
00676 UpperTriangularMatrix(ArrayLengthSpecifier);
00677 void operator=(const BaseMatrix&);
00678 void operator=(const UpperTriangularMatrix& m)
00679 { operator=((const BaseMatrix&)m); }
00680 UpperTriangularMatrix(const BaseMatrix&);
00681 UpperTriangularMatrix(const UpperTriangularMatrix& gm) { GetMatrix(&gm); }
00682 void operator=(Real f) { GeneralMatrix::operator=(f); }
00683 Real& operator()(int, int);
00684 Real& element(int, int);
00685 Real operator()(int, int) const;
00686 Real element(int, int) const;
00687 #ifdef SETUP_C_SUBSCRIPTS
00688 Real* operator[](int m) { return store+m*ncols-(m*(m+1))/2; }
00689 const Real* operator[](int m) const { return store+m*ncols-(m*(m+1))/2; }
00690 #endif
00691 MatrixType Type() const;
00692 GeneralMatrix* MakeSolver() { return this; }
00693 void Solver(MatrixColX&, const MatrixColX&);
00694 LogAndSign LogDeterminant() const;
00695 Real Trace() const;
00696 void GetRow(MatrixRowCol&);
00697 void GetCol(MatrixRowCol&);
00698 void GetCol(MatrixColX&);
00699 void RestoreCol(MatrixRowCol&);
00700 void RestoreCol(MatrixColX& c) { RestoreCol((MatrixRowCol&)c); }
00701 void NextRow(MatrixRowCol&);
00702 void ReSize(int);
00703 void ReSize(const GeneralMatrix& A);
00704 MatrixBandWidth BandWidth() const;
00705 NEW_DELETE(UpperTriangularMatrix)
00706 };
00707
00708 class LowerTriangularMatrix : public GeneralMatrix
00709 {
00710 GeneralMatrix* Image() const;
00711 public:
00712 LowerTriangularMatrix() {}
00713 ~LowerTriangularMatrix() {}
00714 LowerTriangularMatrix(ArrayLengthSpecifier);
00715 LowerTriangularMatrix(const LowerTriangularMatrix& gm) { GetMatrix(&gm); }
00716 LowerTriangularMatrix(const BaseMatrix& M);
00717 void operator=(const BaseMatrix&);
00718 void operator=(Real f) { GeneralMatrix::operator=(f); }
00719 void operator=(const LowerTriangularMatrix& m)
00720 { operator=((const BaseMatrix&)m); }
00721 Real& operator()(int, int);
00722 Real& element(int, int);
00723 Real operator()(int, int) const;
00724 Real element(int, int) const;
00725 #ifdef SETUP_C_SUBSCRIPTS
00726 Real* operator[](int m) { return store+(m*(m+1))/2; }
00727 const Real* operator[](int m) const { return store+(m*(m+1))/2; }
00728 #endif
00729 MatrixType Type() const;
00730 GeneralMatrix* MakeSolver() { return this; }
00731 void Solver(MatrixColX&, const MatrixColX&);
00732 LogAndSign LogDeterminant() const;
00733 Real Trace() const;
00734 void GetRow(MatrixRowCol&);
00735 void GetCol(MatrixRowCol&);
00736 void GetCol(MatrixColX&);
00737 void RestoreCol(MatrixRowCol&);
00738 void RestoreCol(MatrixColX& c) { RestoreCol((MatrixRowCol&)c); }
00739 void NextRow(MatrixRowCol&);
00740 void ReSize(int);
00741 void ReSize(const GeneralMatrix& A);
00742 MatrixBandWidth BandWidth() const;
00743 NEW_DELETE(LowerTriangularMatrix)
00744 };
00745
00746 class DiagonalMatrix : public GeneralMatrix
00747 {
00748 GeneralMatrix* Image() const;
00749 public:
00750 DiagonalMatrix() {}
00751 ~DiagonalMatrix() {}
00752 DiagonalMatrix(ArrayLengthSpecifier);
00753 DiagonalMatrix(const BaseMatrix&);
00754 DiagonalMatrix(const DiagonalMatrix& gm) { GetMatrix(&gm); }
00755 void operator=(const BaseMatrix&);
00756 void operator=(Real f) { GeneralMatrix::operator=(f); }
00757 void operator=(const DiagonalMatrix& m) { operator=((const BaseMatrix&)m); }
00758 Real& operator()(int, int);
00759 Real& operator()(int);
00760 Real operator()(int, int) const;
00761 Real operator()(int) const;
00762 Real& element(int, int);
00763 Real& element(int);
00764 Real element(int, int) const;
00765 Real element(int) const;
00766 #ifdef SETUP_C_SUBSCRIPTS
00767 Real& operator[](int m) { return store[m]; }
00768 const Real& operator[](int m) const { return store[m]; }
00769 #endif
00770 MatrixType Type() const;
00771
00772 LogAndSign LogDeterminant() const;
00773 Real Trace() const;
00774 void GetRow(MatrixRowCol&);
00775 void GetCol(MatrixRowCol&);
00776 void GetCol(MatrixColX&);
00777 void NextRow(MatrixRowCol&);
00778 void NextCol(MatrixRowCol&);
00779 void NextCol(MatrixColX&);
00780 GeneralMatrix* MakeSolver() { return this; }
00781 void Solver(MatrixColX&, const MatrixColX&);
00782 GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
00783 void ReSize(int);
00784 void ReSize(const GeneralMatrix& A);
00785 Real* nric() const
00786 { CheckStore(); return store-1; }
00787 MatrixBandWidth BandWidth() const;
00788
00789 NEW_DELETE(DiagonalMatrix)
00790 };
00791
00792 class RowVector : public Matrix
00793 {
00794 GeneralMatrix* Image() const;
00795 public:
00796 RowVector() { nrows = 1; }
00797 ~RowVector() {}
00798 RowVector(ArrayLengthSpecifier n) : Matrix(1,n.Value()) {}
00799 RowVector(const BaseMatrix&);
00800 RowVector(const RowVector& gm) { GetMatrix(&gm); }
00801 void operator=(const BaseMatrix&);
00802 void operator=(Real f) { GeneralMatrix::operator=(f); }
00803 void operator=(const RowVector& m) { operator=((const BaseMatrix&)m); }
00804 Real& operator()(int);
00805 Real& element(int);
00806 Real operator()(int) const;
00807 Real element(int) const;
00808 #ifdef SETUP_C_SUBSCRIPTS
00809 Real& operator[](int m) { return store[m]; }
00810 const Real& operator[](int m) const { return store[m]; }
00811 #endif
00812 MatrixType Type() const;
00813 void GetCol(MatrixRowCol&);
00814 void GetCol(MatrixColX&);
00815 void NextCol(MatrixRowCol&);
00816 void NextCol(MatrixColX&);
00817 void RestoreCol(MatrixRowCol&) {}
00818 void RestoreCol(MatrixColX& c);
00819 GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
00820 void ReSize(int);
00821 void ReSize(int,int);
00822 void ReSize(const GeneralMatrix& A);
00823 Real* nric() const
00824 { CheckStore(); return store-1; }
00825 void CleanUp();
00826
00827 NEW_DELETE(RowVector)
00828 };
00829
00830 class ColumnVector : public Matrix
00831 {
00832 GeneralMatrix* Image() const;
00833 public:
00834 ColumnVector() { ncols = 1; }
00835 ~ColumnVector() {}
00836 ColumnVector(ArrayLengthSpecifier n) : Matrix(n.Value(),1) {}
00837 ColumnVector(const BaseMatrix&);
00838 ColumnVector(const ColumnVector& gm) { GetMatrix(&gm); }
00839 void operator=(const BaseMatrix&);
00840 void operator=(Real f) { GeneralMatrix::operator=(f); }
00841 void operator=(const ColumnVector& m) { operator=((const BaseMatrix&)m); }
00842 Real& operator()(int);
00843 Real& element(int);
00844 Real operator()(int) const;
00845 Real element(int) const;
00846 #ifdef SETUP_C_SUBSCRIPTS
00847 Real& operator[](int m) { return store[m]; }
00848 const Real& operator[](int m) const { return store[m]; }
00849 #endif
00850 MatrixType Type() const;
00851 GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
00852 void ReSize(int);
00853 void ReSize(int,int);
00854 void ReSize(const GeneralMatrix& A);
00855 Real* nric() const
00856 { CheckStore(); return store-1; }
00857 void CleanUp();
00858
00859 NEW_DELETE(ColumnVector)
00860 };
00861
00862 class CroutMatrix : public GeneralMatrix
00863 {
00864 int* indx;
00865 bool d;
00866 bool sing;
00867 void ludcmp();
00868 public:
00869 CroutMatrix(const BaseMatrix&);
00870 MatrixType Type() const;
00871 void lubksb(Real*, int=0);
00872 ~CroutMatrix();
00873 GeneralMatrix* MakeSolver() { return this; }
00874 LogAndSign LogDeterminant() const;
00875 void Solver(MatrixColX&, const MatrixColX&);
00876 void GetRow(MatrixRowCol&);
00877 void GetCol(MatrixRowCol&);
00878 void GetCol(MatrixColX& c) { GetCol((MatrixRowCol&)c); }
00879 void operator=(const BaseMatrix&);
00880 void operator=(const CroutMatrix& m) { operator=((const BaseMatrix&)m); }
00881 void CleanUp();
00882 bool IsEqual(const GeneralMatrix&) const;
00883 bool IsSingular() const { return sing; }
00884 NEW_DELETE(CroutMatrix)
00885 };
00886
00887
00888
00889 class BandMatrix : public GeneralMatrix
00890 {
00891 GeneralMatrix* Image() const;
00892 protected:
00893 void CornerClear() const;
00894 short SimpleAddOK(const GeneralMatrix* gm);
00895 public:
00896 int lower, upper;
00897 BandMatrix() { lower=0; upper=0; CornerClear(); }
00898 ~BandMatrix() {}
00899 BandMatrix(int n,int lb,int ub) { ReSize(n,lb,ub); CornerClear(); }
00900
00901 BandMatrix(const BaseMatrix&);
00902 void operator=(const BaseMatrix&);
00903 void operator=(Real f) { GeneralMatrix::operator=(f); }
00904 void operator=(const BandMatrix& m) { operator=((const BaseMatrix&)m); }
00905 MatrixType Type() const;
00906 Real& operator()(int, int);
00907 Real& element(int, int);
00908 Real operator()(int, int) const;
00909 Real element(int, int) const;
00910 #ifdef SETUP_C_SUBSCRIPTS
00911 Real* operator[](int m) { return store+(upper+lower)*m+lower; }
00912 const Real* operator[](int m) const { return store+(upper+lower)*m+lower; }
00913 #endif
00914 BandMatrix(const BandMatrix& gm) { GetMatrix(&gm); }
00915 LogAndSign LogDeterminant() const;
00916 GeneralMatrix* MakeSolver();
00917 Real Trace() const;
00918 Real SumSquare() const { CornerClear(); return GeneralMatrix::SumSquare(); }
00919 Real SumAbsoluteValue() const
00920 { CornerClear(); return GeneralMatrix::SumAbsoluteValue(); }
00921 Real Sum() const
00922 { CornerClear(); return GeneralMatrix::Sum(); }
00923 Real MaximumAbsoluteValue() const
00924 { CornerClear(); return GeneralMatrix::MaximumAbsoluteValue(); }
00925 Real MinimumAbsoluteValue() const
00926 { int i, j; return GeneralMatrix::MinimumAbsoluteValue2(i, j); }
00927 Real Maximum() const { int i, j; return GeneralMatrix::Maximum2(i, j); }
00928 Real Minimum() const { int i, j; return GeneralMatrix::Minimum2(i, j); }
00929 void GetRow(MatrixRowCol&);
00930 void GetCol(MatrixRowCol&);
00931 void GetCol(MatrixColX&);
00932 void RestoreCol(MatrixRowCol&);
00933 void RestoreCol(MatrixColX& c) { RestoreCol((MatrixRowCol&)c); }
00934 void NextRow(MatrixRowCol&);
00935 virtual void ReSize(int, int, int);
00936 void ReSize(const GeneralMatrix& A);
00937 bool SameStorageType(const GeneralMatrix& A) const;
00938 void ReSizeForAdd(const GeneralMatrix& A, const GeneralMatrix& B);
00939 void ReSizeForSP(const GeneralMatrix& A, const GeneralMatrix& B);
00940 MatrixBandWidth BandWidth() const;
00941 void SetParameters(const GeneralMatrix*);
00942 MatrixInput operator<<(Real);
00943 MatrixInput operator<<(int f);
00944 void operator<<(const Real* r);
00945
00946
00947 void operator<<(const BaseMatrix& X) { GeneralMatrix::operator<<(X); }
00948 NEW_DELETE(BandMatrix)
00949 };
00950
00951 class UpperBandMatrix : public BandMatrix
00952 {
00953 GeneralMatrix* Image() const;
00954 public:
00955 UpperBandMatrix() {}
00956 ~UpperBandMatrix() {}
00957 UpperBandMatrix(int n, int ubw)
00958 : BandMatrix(n, 0, ubw) {}
00959 UpperBandMatrix(const BaseMatrix&);
00960 void operator=(const BaseMatrix&);
00961 void operator=(Real f) { GeneralMatrix::operator=(f); }
00962 void operator=(const UpperBandMatrix& m)
00963 { operator=((const BaseMatrix&)m); }
00964 MatrixType Type() const;
00965 UpperBandMatrix(const UpperBandMatrix& gm) { GetMatrix(&gm); }
00966 GeneralMatrix* MakeSolver() { return this; }
00967 void Solver(MatrixColX&, const MatrixColX&);
00968 LogAndSign LogDeterminant() const;
00969 void ReSize(int, int, int);
00970 void ReSize(int n,int ubw)
00971 { BandMatrix::ReSize(n,0,ubw); }
00972 void ReSize(const GeneralMatrix& A) { BandMatrix::ReSize(A); }
00973 Real& operator()(int, int);
00974 Real operator()(int, int) const;
00975 Real& element(int, int);
00976 Real element(int, int) const;
00977 #ifdef SETUP_C_SUBSCRIPTS
00978 Real* operator[](int m) { return store+upper*m; }
00979 const Real* operator[](int m) const { return store+upper*m; }
00980 #endif
00981 NEW_DELETE(UpperBandMatrix)
00982 };
00983
00984 class LowerBandMatrix : public BandMatrix
00985 {
00986 GeneralMatrix* Image() const;
00987 public:
00988 LowerBandMatrix() {}
00989 ~LowerBandMatrix() {}
00990 LowerBandMatrix(int n, int lbw)
00991 : BandMatrix(n, lbw, 0) {}
00992 LowerBandMatrix(const BaseMatrix&);
00993 void operator=(const BaseMatrix&);
00994 void operator=(Real f) { GeneralMatrix::operator=(f); }
00995 void operator=(const LowerBandMatrix& m)
00996 { operator=((const BaseMatrix&)m); }
00997 MatrixType Type() const;
00998 LowerBandMatrix(const LowerBandMatrix& gm) { GetMatrix(&gm); }
00999 GeneralMatrix* MakeSolver() { return this; }
01000 void Solver(MatrixColX&, const MatrixColX&);
01001 LogAndSign LogDeterminant() const;
01002 void ReSize(int, int, int);
01003 void ReSize(int n,int lbw)
01004 { BandMatrix::ReSize(n,lbw,0); }
01005 void ReSize(const GeneralMatrix& A) { BandMatrix::ReSize(A); }
01006 Real& operator()(int, int);
01007 Real operator()(int, int) const;
01008 Real& element(int, int);
01009 Real element(int, int) const;
01010 #ifdef SETUP_C_SUBSCRIPTS
01011 Real* operator[](int m) { return store+lower*(m+1); }
01012 const Real* operator[](int m) const { return store+lower*(m+1); }
01013 #endif
01014 NEW_DELETE(LowerBandMatrix)
01015 };
01016
01017 class SymmetricBandMatrix : public GeneralMatrix
01018 {
01019 GeneralMatrix* Image() const;
01020 void CornerClear() const;
01021 short SimpleAddOK(const GeneralMatrix* gm);
01022 public:
01023 int lower;
01024 SymmetricBandMatrix() { lower=0; CornerClear(); }
01025 ~SymmetricBandMatrix() {}
01026 SymmetricBandMatrix(int n, int lb) { ReSize(n,lb); CornerClear(); }
01027 SymmetricBandMatrix(const BaseMatrix&);
01028 void operator=(const BaseMatrix&);
01029 void operator=(Real f) { GeneralMatrix::operator=(f); }
01030 void operator=(const SymmetricBandMatrix& m)
01031 { operator=((const BaseMatrix&)m); }
01032 Real& operator()(int, int);
01033 Real& element(int, int);
01034 Real operator()(int, int) const;
01035 Real element(int, int) const;
01036 #ifdef SETUP_C_SUBSCRIPTS
01037 Real* operator[](int m) { return store+lower*(m+1); }
01038 const Real* operator[](int m) const { return store+lower*(m+1); }
01039 #endif
01040 MatrixType Type() const;
01041 SymmetricBandMatrix(const SymmetricBandMatrix& gm) { GetMatrix(&gm); }
01042 GeneralMatrix* MakeSolver();
01043 Real SumSquare() const;
01044 Real SumAbsoluteValue() const;
01045 Real Sum() const;
01046 Real MaximumAbsoluteValue() const
01047 { CornerClear(); return GeneralMatrix::MaximumAbsoluteValue(); }
01048 Real MinimumAbsoluteValue() const
01049 { int i, j; return GeneralMatrix::MinimumAbsoluteValue2(i, j); }
01050 Real Maximum() const { int i, j; return GeneralMatrix::Maximum2(i, j); }
01051 Real Minimum() const { int i, j; return GeneralMatrix::Minimum2(i, j); }
01052 Real Trace() const;
01053 LogAndSign LogDeterminant() const;
01054 void GetRow(MatrixRowCol&);
01055 void GetCol(MatrixRowCol&);
01056 void GetCol(MatrixColX&);
01057 void RestoreCol(MatrixRowCol&) {}
01058 void RestoreCol(MatrixColX&);
01059 GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
01060 void ReSize(int,int);
01061 void ReSize(const GeneralMatrix& A);
01062 bool SameStorageType(const GeneralMatrix& A) const;
01063 void ReSizeForAdd(const GeneralMatrix& A, const GeneralMatrix& B);
01064 void ReSizeForSP(const GeneralMatrix& A, const GeneralMatrix& B);
01065 MatrixBandWidth BandWidth() const;
01066 void SetParameters(const GeneralMatrix*);
01067 NEW_DELETE(SymmetricBandMatrix)
01068 };
01069
01070 class BandLUMatrix : public GeneralMatrix
01071
01072 {
01073 int* indx;
01074 bool d;
01075 bool sing;
01076 Real* store2;
01077 int storage2;
01078 void ludcmp();
01079 int m1,m2;
01080 public:
01081 BandLUMatrix(const BaseMatrix&);
01082 MatrixType Type() const;
01083 void lubksb(Real*, int=0);
01084 ~BandLUMatrix();
01085 GeneralMatrix* MakeSolver() { return this; }
01086 LogAndSign LogDeterminant() const;
01087 void Solver(MatrixColX&, const MatrixColX&);
01088 void GetRow(MatrixRowCol&);
01089 void GetCol(MatrixRowCol&);
01090 void GetCol(MatrixColX& c) { GetCol((MatrixRowCol&)c); }
01091 void operator=(const BaseMatrix&);
01092 void operator=(const BandLUMatrix& m) { operator=((const BaseMatrix&)m); }
01093 void CleanUp();
01094 bool IsEqual(const GeneralMatrix&) const;
01095 bool IsSingular() const { return sing; }
01096 NEW_DELETE(BandLUMatrix)
01097 };
01098
01099
01100
01101 class IdentityMatrix : public GeneralMatrix
01102 {
01103 GeneralMatrix* Image() const;
01104 public:
01105 IdentityMatrix() {}
01106 ~IdentityMatrix() {}
01107 IdentityMatrix(ArrayLengthSpecifier n) : GeneralMatrix(1)
01108 { nrows = ncols = n.Value(); *store = 1; }
01109 IdentityMatrix(const IdentityMatrix& gm) { GetMatrix(&gm); }
01110 IdentityMatrix(const BaseMatrix&);
01111 void operator=(const BaseMatrix&);
01112 void operator=(Real f) { GeneralMatrix::operator=(f); }
01113 MatrixType Type() const;
01114
01115 LogAndSign LogDeterminant() const;
01116 Real Trace() const;
01117 Real SumSquare() const;
01118 Real SumAbsoluteValue() const;
01119 Real Sum() const { return Trace(); }
01120 void GetRow(MatrixRowCol&);
01121 void GetCol(MatrixRowCol&);
01122 void GetCol(MatrixColX&);
01123 void NextRow(MatrixRowCol&);
01124 void NextCol(MatrixRowCol&);
01125 void NextCol(MatrixColX&);
01126 GeneralMatrix* MakeSolver() { return this; }
01127 void Solver(MatrixColX&, const MatrixColX&);
01128 GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
01129 void ReSize(int n);
01130 void ReSize(const GeneralMatrix& A);
01131 MatrixBandWidth BandWidth() const;
01132
01133 NEW_DELETE(IdentityMatrix)
01134 };
01135
01136
01137
01138
01139
01140
01141 class GenericMatrix : public BaseMatrix
01142 {
01143 GeneralMatrix* gm;
01144 int search(const BaseMatrix* bm) const;
01145 friend class BaseMatrix;
01146 public:
01147 GenericMatrix() : gm(0) {}
01148 GenericMatrix(const BaseMatrix& bm)
01149 { gm = ((BaseMatrix&)bm).Evaluate(); gm = gm->Image(); }
01150 GenericMatrix(const GenericMatrix& bm)
01151 { gm = bm.gm->Image(); }
01152 void operator=(const GenericMatrix&);
01153 void operator=(const BaseMatrix&);
01154 void operator+=(const BaseMatrix&);
01155 void operator-=(const BaseMatrix&);
01156 void operator*=(const BaseMatrix&);
01157 void operator|=(const BaseMatrix&);
01158 void operator&=(const BaseMatrix&);
01159 void operator+=(Real);
01160 void operator-=(Real r) { operator+=(-r); }
01161 void operator*=(Real);
01162 void operator/=(Real r) { operator*=(1.0/r); }
01163 ~GenericMatrix() { delete gm; }
01164 void CleanUp() { delete gm; gm = 0; }
01165 void Release() { gm->Release(); }
01166 GeneralMatrix* Evaluate(MatrixType = MatrixTypeUnSp);
01167 MatrixBandWidth BandWidth() const;
01168 NEW_DELETE(GenericMatrix)
01169 };
01170
01171
01172
01173 class MultipliedMatrix : public BaseMatrix
01174 {
01175 protected:
01176
01177
01178 union { const BaseMatrix* bm1; GeneralMatrix* gm1; };
01179
01180 union { const BaseMatrix* bm2; GeneralMatrix* gm2; };
01181 MultipliedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01182 : bm1(bm1x),bm2(bm2x) {}
01183 int search(const BaseMatrix*) const;
01184 friend class BaseMatrix;
01185 friend class GeneralMatrix;
01186 friend class GenericMatrix;
01187 public:
01188 ~MultipliedMatrix() {}
01189 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01190 MatrixBandWidth BandWidth() const;
01191 NEW_DELETE(MultipliedMatrix)
01192 };
01193
01194 class AddedMatrix : public MultipliedMatrix
01195 {
01196 protected:
01197 AddedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01198 : MultipliedMatrix(bm1x,bm2x) {}
01199
01200 friend class BaseMatrix;
01201 friend class GeneralMatrix;
01202 friend class GenericMatrix;
01203 public:
01204 ~AddedMatrix() {}
01205 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01206 MatrixBandWidth BandWidth() const;
01207 NEW_DELETE(AddedMatrix)
01208 };
01209
01210 class SPMatrix : public AddedMatrix
01211 {
01212 protected:
01213 SPMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01214 : AddedMatrix(bm1x,bm2x) {}
01215
01216 friend class BaseMatrix;
01217 friend class GeneralMatrix;
01218 friend class GenericMatrix;
01219 public:
01220 ~SPMatrix() {}
01221 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01222 MatrixBandWidth BandWidth() const;
01223
01224 #ifndef TEMPS_DESTROYED_QUICKLY
01225 friend SPMatrix SP(const BaseMatrix&, const BaseMatrix&);
01226 #else
01227 friend SPMatrix& SP(const BaseMatrix&, const BaseMatrix&);
01228 #endif
01229
01230 NEW_DELETE(SPMatrix)
01231 };
01232
01233 class KPMatrix : public MultipliedMatrix
01234 {
01235 protected:
01236 KPMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01237 : MultipliedMatrix(bm1x,bm2x) {}
01238
01239 friend class BaseMatrix;
01240 friend class GeneralMatrix;
01241 friend class GenericMatrix;
01242 public:
01243 ~KPMatrix() {}
01244 MatrixBandWidth BandWidth() const;
01245 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01246 #ifndef TEMPS_DESTROYED_QUICKLY
01247 friend KPMatrix KP(const BaseMatrix&, const BaseMatrix&);
01248 #else
01249 friend KPMatrix& KP(const BaseMatrix&, const BaseMatrix&);
01250 #endif
01251 NEW_DELETE(KPMatrix)
01252 };
01253
01254 class ConcatenatedMatrix : public MultipliedMatrix
01255 {
01256 protected:
01257 ConcatenatedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01258 : MultipliedMatrix(bm1x,bm2x) {}
01259
01260 friend class BaseMatrix;
01261 friend class GeneralMatrix;
01262 friend class GenericMatrix;
01263 public:
01264 ~ConcatenatedMatrix() {}
01265 MatrixBandWidth BandWidth() const;
01266 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01267 NEW_DELETE(ConcatenatedMatrix)
01268 };
01269
01270 class StackedMatrix : public ConcatenatedMatrix
01271 {
01272 protected:
01273 StackedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01274 : ConcatenatedMatrix(bm1x,bm2x) {}
01275
01276 friend class BaseMatrix;
01277 friend class GeneralMatrix;
01278 friend class GenericMatrix;
01279 public:
01280 ~StackedMatrix() {}
01281 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01282 NEW_DELETE(StackedMatrix)
01283 };
01284
01285 class SolvedMatrix : public MultipliedMatrix
01286 {
01287 SolvedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01288 : MultipliedMatrix(bm1x,bm2x) {}
01289 friend class BaseMatrix;
01290 friend class InvertedMatrix;
01291 public:
01292 ~SolvedMatrix() {}
01293 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01294 MatrixBandWidth BandWidth() const;
01295 NEW_DELETE(SolvedMatrix)
01296 };
01297
01298 class SubtractedMatrix : public AddedMatrix
01299 {
01300 SubtractedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01301 : AddedMatrix(bm1x,bm2x) {}
01302 friend class BaseMatrix;
01303 friend class GeneralMatrix;
01304 friend class GenericMatrix;
01305 public:
01306 ~SubtractedMatrix() {}
01307 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01308 NEW_DELETE(SubtractedMatrix)
01309 };
01310
01311 class ShiftedMatrix : public BaseMatrix
01312 {
01313 protected:
01314 union { const BaseMatrix* bm; GeneralMatrix* gm; };
01315 Real f;
01316 ShiftedMatrix(const BaseMatrix* bmx, Real fx) : bm(bmx),f(fx) {}
01317 int search(const BaseMatrix*) const;
01318 friend class BaseMatrix;
01319 friend class GeneralMatrix;
01320 friend class GenericMatrix;
01321 public:
01322 ~ShiftedMatrix() {}
01323 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01324 #ifndef TEMPS_DESTROYED_QUICKLY
01325 friend ShiftedMatrix operator+(Real f, const BaseMatrix& BM);
01326
01327 #endif
01328 NEW_DELETE(ShiftedMatrix)
01329 };
01330
01331 class NegShiftedMatrix : public ShiftedMatrix
01332 {
01333 protected:
01334 NegShiftedMatrix(Real fx, const BaseMatrix* bmx) : ShiftedMatrix(bmx,fx) {}
01335 friend class BaseMatrix;
01336 friend class GeneralMatrix;
01337 friend class GenericMatrix;
01338 public:
01339 ~NegShiftedMatrix() {}
01340 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01341 #ifndef TEMPS_DESTROYED_QUICKLY
01342 friend NegShiftedMatrix operator-(Real, const BaseMatrix&);
01343 #else
01344 friend NegShiftedMatrix& operator-(Real, const BaseMatrix&);
01345 #endif
01346 NEW_DELETE(NegShiftedMatrix)
01347 };
01348
01349 class ScaledMatrix : public ShiftedMatrix
01350 {
01351 ScaledMatrix(const BaseMatrix* bmx, Real fx) : ShiftedMatrix(bmx,fx) {}
01352 friend class BaseMatrix;
01353 friend class GeneralMatrix;
01354 friend class GenericMatrix;
01355 public:
01356 ~ScaledMatrix() {}
01357 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01358 MatrixBandWidth BandWidth() const;
01359 #ifndef TEMPS_DESTROYED_QUICKLY
01360 friend ScaledMatrix operator*(Real f, const BaseMatrix& BM);
01361
01362 #endif
01363 NEW_DELETE(ScaledMatrix)
01364 };
01365
01366 class NegatedMatrix : public BaseMatrix
01367 {
01368 protected:
01369 union { const BaseMatrix* bm; GeneralMatrix* gm; };
01370 NegatedMatrix(const BaseMatrix* bmx) : bm(bmx) {}
01371 int search(const BaseMatrix*) const;
01372 private:
01373 friend class BaseMatrix;
01374 public:
01375 ~NegatedMatrix() {}
01376 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01377 MatrixBandWidth BandWidth() const;
01378 NEW_DELETE(NegatedMatrix)
01379 };
01380
01381 class TransposedMatrix : public NegatedMatrix
01382 {
01383 TransposedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01384 friend class BaseMatrix;
01385 public:
01386 ~TransposedMatrix() {}
01387 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01388 MatrixBandWidth BandWidth() const;
01389 NEW_DELETE(TransposedMatrix)
01390 };
01391
01392 class ReversedMatrix : public NegatedMatrix
01393 {
01394 ReversedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01395 friend class BaseMatrix;
01396 public:
01397 ~ReversedMatrix() {}
01398 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01399 NEW_DELETE(ReversedMatrix)
01400 };
01401
01402 class InvertedMatrix : public NegatedMatrix
01403 {
01404 InvertedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01405 public:
01406 ~InvertedMatrix() {}
01407 #ifndef TEMPS_DESTROYED_QUICKLY
01408 SolvedMatrix operator*(const BaseMatrix&) const;
01409 ScaledMatrix operator*(Real t) const { return BaseMatrix::operator*(t); }
01410 #else
01411 SolvedMatrix& operator*(const BaseMatrix&);
01412 ScaledMatrix& operator*(Real t) const { return BaseMatrix::operator*(t); }
01413 #endif
01414 friend class BaseMatrix;
01415 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01416 MatrixBandWidth BandWidth() const;
01417 NEW_DELETE(InvertedMatrix)
01418 };
01419
01420 class RowedMatrix : public NegatedMatrix
01421 {
01422 RowedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01423 friend class BaseMatrix;
01424 public:
01425 ~RowedMatrix() {}
01426 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01427 MatrixBandWidth BandWidth() const;
01428 NEW_DELETE(RowedMatrix)
01429 };
01430
01431 class ColedMatrix : public NegatedMatrix
01432 {
01433 ColedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01434 friend class BaseMatrix;
01435 public:
01436 ~ColedMatrix() {}
01437 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01438 MatrixBandWidth BandWidth() const;
01439 NEW_DELETE(ColedMatrix)
01440 };
01441
01442 class DiagedMatrix : public NegatedMatrix
01443 {
01444 DiagedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01445 friend class BaseMatrix;
01446 public:
01447 ~DiagedMatrix() {}
01448 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01449 MatrixBandWidth BandWidth() const;
01450 NEW_DELETE(DiagedMatrix)
01451 };
01452
01453 class MatedMatrix : public NegatedMatrix
01454 {
01455 int nr, nc;
01456 MatedMatrix(const BaseMatrix* bmx, int nrx, int ncx)
01457 : NegatedMatrix(bmx), nr(nrx), nc(ncx) {}
01458 friend class BaseMatrix;
01459 public:
01460 ~MatedMatrix() {}
01461 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01462 MatrixBandWidth BandWidth() const;
01463 NEW_DELETE(MatedMatrix)
01464 };
01465
01466 class ReturnMatrixX : public BaseMatrix
01467 {
01468 GeneralMatrix* gm;
01469 int search(const BaseMatrix*) const;
01470 public:
01471 ~ReturnMatrixX() {}
01472 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01473 friend class BaseMatrix;
01474 #ifdef TEMPS_DESTROYED_QUICKLY_R
01475 ReturnMatrixX(const ReturnMatrixX& tm);
01476 #else
01477 ReturnMatrixX(const ReturnMatrixX& tm) : gm(tm.gm) {}
01478 #endif
01479 ReturnMatrixX(const GeneralMatrix* gmx) : gm((GeneralMatrix*&)gmx) {}
01480
01481 MatrixBandWidth BandWidth() const;
01482 NEW_DELETE(ReturnMatrixX)
01483 };
01484
01485
01486
01487
01488 class GetSubMatrix : public NegatedMatrix
01489 {
01490 int row_skip;
01491 int row_number;
01492 int col_skip;
01493 int col_number;
01494 bool IsSym;
01495
01496 GetSubMatrix
01497 (const BaseMatrix* bmx, int rs, int rn, int cs, int cn, bool is)
01498 : NegatedMatrix(bmx),
01499 row_skip(rs), row_number(rn), col_skip(cs), col_number(cn), IsSym(is) {}
01500 void SetUpLHS();
01501 friend class BaseMatrix;
01502 public:
01503 GetSubMatrix(const GetSubMatrix& g)
01504 : NegatedMatrix(g.bm), row_skip(g.row_skip), row_number(g.row_number),
01505 col_skip(g.col_skip), col_number(g.col_number), IsSym(g.IsSym) {}
01506 ~GetSubMatrix() {}
01507 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01508 void operator=(const BaseMatrix&);
01509 void operator+=(const BaseMatrix&);
01510 void operator-=(const BaseMatrix&);
01511 void operator=(const GetSubMatrix& m) { operator=((const BaseMatrix&)m); }
01512 void operator<<(const BaseMatrix&);
01513 void operator<<(const Real*);
01514 MatrixInput operator<<(Real);
01515 MatrixInput operator<<(int f);
01516 void operator=(Real);
01517 void operator+=(Real);
01518 void operator-=(Real r) { operator+=(-r); }
01519 void operator*=(Real);
01520 void operator/=(Real r) { operator*=(1.0/r); }
01521 void Inject(const GeneralMatrix&);
01522 MatrixBandWidth BandWidth() const;
01523 NEW_DELETE(GetSubMatrix)
01524 };
01525
01526
01527
01528 class LinearEquationSolver : public BaseMatrix
01529 {
01530 GeneralMatrix* gm;
01531 int search(const BaseMatrix*) const { return 0; }
01532 friend class BaseMatrix;
01533 public:
01534 LinearEquationSolver(const BaseMatrix& bm);
01535 ~LinearEquationSolver() { delete gm; }
01536 void CleanUp() { delete gm; }
01537 GeneralMatrix* Evaluate(MatrixType) { return gm; }
01538
01539 NEW_DELETE(LinearEquationSolver)
01540 };
01541
01542
01543
01544 class MatrixInput
01545
01546
01547 {
01548 int n;
01549 Real* r;
01550 public:
01551 MatrixInput(const MatrixInput& mi) : n(mi.n), r(mi.r) {}
01552 MatrixInput(int nx, Real* rx) : n(nx), r(rx) {}
01553 ~MatrixInput();
01554 MatrixInput operator<<(Real);
01555 MatrixInput operator<<(int f);
01556 friend class GeneralMatrix;
01557 };
01558
01559
01560
01561
01562
01563
01564
01565
01566 class SimpleIntArray : public Janitor
01567 {
01568 protected:
01569 int* a;
01570 int n;
01571 public:
01572 SimpleIntArray(int xn);
01573 ~SimpleIntArray();
01574 int& operator[](int i);
01575 int operator[](int i) const;
01576
01577 void operator=(int ai);
01578 void operator=(const SimpleIntArray& b);
01579
01580 SimpleIntArray(const SimpleIntArray& b);
01581
01582 int Size() const { return n; }
01583
01584 int* Data() { return a; }
01585 const int* Data() const { return a; }
01586
01587 void ReSize(int i, bool keep = false);
01588
01589 void CleanUp() { ReSize(0); }
01590 NEW_DELETE(SimpleIntArray)
01591 };
01592
01593
01594
01595 class NPDException : public Runtime_error
01596 {
01597 public:
01598 static unsigned long Select;
01599 NPDException(const GeneralMatrix&);
01600 };
01601
01602 class ConvergenceException : public Runtime_error
01603 {
01604 public:
01605 static unsigned long Select;
01606 ConvergenceException(const GeneralMatrix& A);
01607 ConvergenceException(const char* c);
01608 };
01609
01610 class SingularException : public Runtime_error
01611 {
01612 public:
01613 static unsigned long Select;
01614 SingularException(const GeneralMatrix& A);
01615 };
01616
01617 class OverflowException : public Runtime_error
01618 {
01619 public:
01620 static unsigned long Select;
01621 OverflowException(const char* c);
01622 };
01623
01624 class ProgramException : public Logic_error
01625 {
01626 protected:
01627 ProgramException();
01628 public:
01629 static unsigned long Select;
01630 ProgramException(const char* c);
01631 ProgramException(const char* c, const GeneralMatrix&);
01632 ProgramException(const char* c, const GeneralMatrix&, const GeneralMatrix&);
01633 ProgramException(const char* c, MatrixType, MatrixType);
01634 };
01635
01636 class IndexException : public Logic_error
01637 {
01638 public:
01639 static unsigned long Select;
01640 IndexException(int i, const GeneralMatrix& A);
01641 IndexException(int i, int j, const GeneralMatrix& A);
01642
01643 IndexException(int i, const GeneralMatrix& A, bool);
01644 IndexException(int i, int j, const GeneralMatrix& A, bool);
01645 };
01646
01647 class VectorException : public Logic_error
01648 {
01649 public:
01650 static unsigned long Select;
01651 VectorException();
01652 VectorException(const GeneralMatrix& A);
01653 };
01654
01655 class NotSquareException : public Logic_error
01656 {
01657 public:
01658 static unsigned long Select;
01659 NotSquareException(const GeneralMatrix& A);
01660 };
01661
01662 class SubMatrixDimensionException : public Logic_error
01663 {
01664 public:
01665 static unsigned long Select;
01666 SubMatrixDimensionException();
01667 };
01668
01669 class IncompatibleDimensionsException : public Logic_error
01670 {
01671 public:
01672 static unsigned long Select;
01673 IncompatibleDimensionsException();
01674 IncompatibleDimensionsException(const GeneralMatrix&, const GeneralMatrix&);
01675 };
01676
01677 class NotDefinedException : public Logic_error
01678 {
01679 public:
01680 static unsigned long Select;
01681 NotDefinedException(const char* op, const char* matrix);
01682 };
01683
01684 class CannotBuildException : public Logic_error
01685 {
01686 public:
01687 static unsigned long Select;
01688 CannotBuildException(const char* matrix);
01689 };
01690
01691
01692 class InternalException : public Logic_error
01693 {
01694 public:
01695 static unsigned long Select;
01696 InternalException(const char* c);
01697 };
01698
01699
01700
01701 bool operator==(const GeneralMatrix& A, const GeneralMatrix& B);
01702 bool operator==(const BaseMatrix& A, const BaseMatrix& B);
01703 inline bool operator!=(const GeneralMatrix& A, const GeneralMatrix& B)
01704 { return ! (A==B); }
01705 inline bool operator!=(const BaseMatrix& A, const BaseMatrix& B)
01706 { return ! (A==B); }
01707
01708
01709
01710 inline bool operator<=(const BaseMatrix& A, const BaseMatrix&)
01711 { A.IEQND(); return true; }
01712 inline bool operator>=(const BaseMatrix& A, const BaseMatrix&)
01713 { A.IEQND(); return true; }
01714 inline bool operator<(const BaseMatrix& A, const BaseMatrix&)
01715 { A.IEQND(); return true; }
01716 inline bool operator>(const BaseMatrix& A, const BaseMatrix&)
01717 { A.IEQND(); return true; }
01718
01719 bool IsZero(const BaseMatrix& A);
01720
01721
01722
01723
01724 bool Rectangular(MatrixType a, MatrixType b, MatrixType c);
01725 bool Compare(const MatrixType&, MatrixType&);
01726 Real DotProduct(const Matrix& A, const Matrix& B);
01727 #ifndef TEMPS_DESTROYED_QUICKLY
01728 SPMatrix SP(const BaseMatrix&, const BaseMatrix&);
01729 KPMatrix KP(const BaseMatrix&, const BaseMatrix&);
01730 ShiftedMatrix operator+(Real f, const BaseMatrix& BM);
01731 NegShiftedMatrix operator-(Real, const BaseMatrix&);
01732 ScaledMatrix operator*(Real f, const BaseMatrix& BM);
01733 #else
01734 SPMatrix& SP(const BaseMatrix&, const BaseMatrix&);
01735 KPMatrix& KP(const BaseMatrix&, const BaseMatrix&);
01736 NegShiftedMatrix& operator-(Real, const BaseMatrix&);
01737 #endif
01738
01739
01740
01741
01742 inline LogAndSign LogDeterminant(const BaseMatrix& B)
01743 { return B.LogDeterminant(); }
01744 inline Real Determinant(const BaseMatrix& B)
01745 { return B.Determinant(); }
01746 inline Real SumSquare(const BaseMatrix& B) { return B.SumSquare(); }
01747 inline Real NormFrobenius(const BaseMatrix& B) { return B.NormFrobenius(); }
01748 inline Real Trace(const BaseMatrix& B) { return B.Trace(); }
01749 inline Real SumAbsoluteValue(const BaseMatrix& B)
01750 { return B.SumAbsoluteValue(); }
01751 inline Real Sum(const BaseMatrix& B)
01752 { return B.Sum(); }
01753 inline Real MaximumAbsoluteValue(const BaseMatrix& B)
01754 { return B.MaximumAbsoluteValue(); }
01755 inline Real MinimumAbsoluteValue(const BaseMatrix& B)
01756 { return B.MinimumAbsoluteValue(); }
01757 inline Real Maximum(const BaseMatrix& B) { return B.Maximum(); }
01758 inline Real Minimum(const BaseMatrix& B) { return B.Minimum(); }
01759 inline Real Norm1(const BaseMatrix& B) { return B.Norm1(); }
01760 inline Real Norm1(RowVector& RV) { return RV.MaximumAbsoluteValue(); }
01761 inline Real NormInfinity(const BaseMatrix& B) { return B.NormInfinity(); }
01762 inline Real NormInfinity(ColumnVector& CV)
01763 { return CV.MaximumAbsoluteValue(); }
01764 inline bool IsZero(const GeneralMatrix& A) { return A.IsZero(); }
01765
01766 #ifdef TEMPS_DESTROYED_QUICKLY
01767 inline ShiftedMatrix& operator+(Real f, const BaseMatrix& BM)
01768 { return BM + f; }
01769 inline ScaledMatrix& operator*(Real f, const BaseMatrix& BM)
01770 { return BM * f; }
01771 #endif
01772
01773
01774
01775 #ifndef TEMPS_DESTROYED_QUICKLY
01776 inline ShiftedMatrix operator+(Real f, const BaseMatrix& BM)
01777 { return ShiftedMatrix(&BM, f); }
01778 inline ScaledMatrix operator*(Real f, const BaseMatrix& BM)
01779 { return ScaledMatrix(&BM, f); }
01780 #endif
01781
01782
01783 inline MatrixInput MatrixInput::operator<<(int f) { return *this << (Real)f; }
01784 inline MatrixInput GeneralMatrix::operator<<(int f) { return *this << (Real)f; }
01785 inline MatrixInput BandMatrix::operator<<(int f) { return *this << (Real)f; }
01786 inline MatrixInput GetSubMatrix::operator<<(int f) { return *this << (Real)f; }
01787
01788
01789
01790 #ifdef use_namespace
01791 }
01792 #endif
01793
01794
01795 #endif
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814