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