newmat6.cc
Go to the documentation of this file.
00001 //$$ newmat6.cpp            Operators, element access, submatrices
00002 
00003 // Copyright (C) 1991,2,3,4: R B Davies
00004 
00005 #include "include.h"
00006 
00007 #include "newmat.h"
00008 #include "newmatrc.h"
00009 
00010 #ifdef use_namespace
00011 namespace NEWMAT {
00012 #endif
00013 
00014 
00015 
00016 #ifdef DO_REPORT
00017 #define REPORT { static ExeCounter ExeCount(__LINE__,6); ++ExeCount; }
00018 #else
00019 #define REPORT {}
00020 #endif
00021 
00022 /*************************** general utilities *************************/
00023 
00024 static int tristore(int n)                      // els in triangular matrix
00025 { return (n*(n+1))/2; }
00026 
00027 
00028 /****************************** operators *******************************/
00029 
00030 Real& Matrix::operator()(int m, int n)
00031 {
00032    REPORT
00033    if (m<=0 || m>nrows || n<=0 || n>ncols)
00034       Throw(IndexException(m,n,*this));
00035    return store[(m-1)*ncols+n-1];
00036 }
00037 
00038 Real& SymmetricMatrix::operator()(int m, int n)
00039 {
00040    REPORT
00041    if (m<=0 || n<=0 || m>nrows || n>ncols)
00042       Throw(IndexException(m,n,*this));
00043    if (m>=n) return store[tristore(m-1)+n-1];
00044    else return store[tristore(n-1)+m-1];
00045 }
00046 
00047 Real& UpperTriangularMatrix::operator()(int m, int n)
00048 {
00049    REPORT
00050    if (m<=0 || n<m || n>ncols)
00051       Throw(IndexException(m,n,*this));
00052    return store[(m-1)*ncols+n-1-tristore(m-1)];
00053 }
00054 
00055 Real& LowerTriangularMatrix::operator()(int m, int n)
00056 {
00057    REPORT
00058    if (n<=0 || m<n || m>nrows)
00059       Throw(IndexException(m,n,*this));
00060    return store[tristore(m-1)+n-1];
00061 }
00062 
00063 Real& DiagonalMatrix::operator()(int m, int n)
00064 {
00065    REPORT
00066    if (n<=0 || m!=n || m>nrows || n>ncols)
00067       Throw(IndexException(m,n,*this));
00068    return store[n-1];
00069 }
00070 
00071 Real& DiagonalMatrix::operator()(int m)
00072 {
00073    REPORT
00074    if (m<=0 || m>nrows) Throw(IndexException(m,*this));
00075    return store[m-1];
00076 }
00077 
00078 Real& ColumnVector::operator()(int m)
00079 {
00080    REPORT
00081    if (m<=0 || m> nrows) Throw(IndexException(m,*this));
00082    return store[m-1];
00083 }
00084 
00085 Real& RowVector::operator()(int n)
00086 {
00087    REPORT
00088    if (n<=0 || n> ncols) Throw(IndexException(n,*this));
00089    return store[n-1];
00090 }
00091 
00092 Real& BandMatrix::operator()(int m, int n)
00093 {
00094    REPORT
00095    int w = upper+lower+1; int i = lower+n-m;
00096    if (m<=0 || m>nrows || n<=0 || n>ncols || i<0 || i>=w)
00097       Throw(IndexException(m,n,*this));
00098    return store[w*(m-1)+i];
00099 }
00100 
00101 Real& UpperBandMatrix::operator()(int m, int n)
00102 {
00103    REPORT
00104    int w = upper+1; int i = n-m;
00105    if (m<=0 || m>nrows || n<=0 || n>ncols || i<0 || i>=w)
00106       Throw(IndexException(m,n,*this));
00107    return store[w*(m-1)+i];
00108 }
00109 
00110 Real& LowerBandMatrix::operator()(int m, int n)
00111 {
00112    REPORT
00113    int w = lower+1; int i = lower+n-m;
00114    if (m<=0 || m>nrows || n<=0 || n>ncols || i<0 || i>=w)
00115       Throw(IndexException(m,n,*this));
00116    return store[w*(m-1)+i];
00117 }
00118 
00119 Real& SymmetricBandMatrix::operator()(int m, int n)
00120 {
00121    REPORT
00122    int w = lower+1;
00123    if (m>=n)
00124    {
00125       REPORT
00126       int i = lower+n-m;
00127       if ( m>nrows || n<=0 || i<0 )
00128          Throw(IndexException(m,n,*this));
00129       return store[w*(m-1)+i];
00130    }
00131    else
00132    {
00133       REPORT
00134       int i = lower+m-n;
00135       if ( n>nrows || m<=0 || i<0 )
00136          Throw(IndexException(m,n,*this));
00137       return store[w*(n-1)+i];
00138    }
00139 }
00140 
00141 
00142 Real Matrix::operator()(int m, int n) const
00143 {
00144    REPORT
00145    if (m<=0 || m>nrows || n<=0 || n>ncols)
00146       Throw(IndexException(m,n,*this));
00147    return store[(m-1)*ncols+n-1];
00148 }
00149 
00150 Real SymmetricMatrix::operator()(int m, int n) const
00151 {
00152    REPORT
00153    if (m<=0 || n<=0 || m>nrows || n>ncols)
00154       Throw(IndexException(m,n,*this));
00155    if (m>=n) return store[tristore(m-1)+n-1];
00156    else return store[tristore(n-1)+m-1];
00157 }
00158 
00159 Real UpperTriangularMatrix::operator()(int m, int n) const
00160 {
00161    REPORT
00162    if (m<=0 || n<m || n>ncols)
00163       Throw(IndexException(m,n,*this));
00164    return store[(m-1)*ncols+n-1-tristore(m-1)];
00165 }
00166 
00167 Real LowerTriangularMatrix::operator()(int m, int n) const
00168 {
00169    REPORT
00170    if (n<=0 || m<n || m>nrows)
00171       Throw(IndexException(m,n,*this));
00172    return store[tristore(m-1)+n-1];
00173 }
00174 
00175 Real DiagonalMatrix::operator()(int m, int n) const
00176 {
00177    REPORT
00178    if (n<=0 || m!=n || m>nrows || n>ncols)
00179       Throw(IndexException(m,n,*this));
00180    return store[n-1];
00181 }
00182 
00183 Real DiagonalMatrix::operator()(int m) const
00184 {
00185    REPORT
00186    if (m<=0 || m>nrows) Throw(IndexException(m,*this));
00187    return store[m-1];
00188 }
00189 
00190 Real ColumnVector::operator()(int m) const
00191 {
00192    REPORT
00193    if (m<=0 || m> nrows) Throw(IndexException(m,*this));
00194    return store[m-1];
00195 }
00196 
00197 Real RowVector::operator()(int n) const
00198 {
00199    REPORT
00200    if (n<=0 || n> ncols) Throw(IndexException(n,*this));
00201    return store[n-1];
00202 }
00203 
00204 Real BandMatrix::operator()(int m, int n) const
00205 {
00206    REPORT
00207    int w = upper+lower+1; int i = lower+n-m;
00208    if (m<=0 || m>nrows || n<=0 || n>ncols || i<0 || i>=w)
00209       Throw(IndexException(m,n,*this));
00210    return store[w*(m-1)+i];
00211 }
00212 
00213 Real UpperBandMatrix::operator()(int m, int n) const
00214 {
00215    REPORT
00216    int w = upper+1; int i = n-m;
00217    if (m<=0 || m>nrows || n<=0 || n>ncols || i<0 || i>=w)
00218       Throw(IndexException(m,n,*this));
00219    return store[w*(m-1)+i];
00220 }
00221 
00222 Real LowerBandMatrix::operator()(int m, int n) const
00223 {
00224    REPORT
00225    int w = lower+1; int i = lower+n-m;
00226    if (m<=0 || m>nrows || n<=0 || n>ncols || i<0 || i>=w)
00227       Throw(IndexException(m,n,*this));
00228    return store[w*(m-1)+i];
00229 }
00230 
00231 Real SymmetricBandMatrix::operator()(int m, int n) const
00232 {
00233    REPORT
00234    int w = lower+1;
00235    if (m>=n)
00236    {
00237       REPORT
00238       int i = lower+n-m;
00239       if ( m>nrows || n<=0 || i<0 )
00240          Throw(IndexException(m,n,*this));
00241       return store[w*(m-1)+i];
00242    }
00243    else
00244    {
00245       REPORT
00246       int i = lower+m-n;
00247       if ( n>nrows || m<=0 || i<0 )
00248          Throw(IndexException(m,n,*this));
00249       return store[w*(n-1)+i];
00250    }
00251 }
00252 
00253 
00254 Real BaseMatrix::AsScalar() const
00255 {
00256    REPORT
00257    GeneralMatrix* gm = ((BaseMatrix&)*this).Evaluate();
00258 
00259    if (gm->nrows!=1 || gm->ncols!=1)
00260    {
00261       Tracer tr("AsScalar");
00262       Try
00263          { Throw(ProgramException("Cannot convert to scalar", *gm)); }
00264       CatchAll { gm->tDelete(); ReThrow; }
00265    }
00266 
00267    Real x = *(gm->store); gm->tDelete(); return x;
00268 }
00269 
00270 #ifdef TEMPS_DESTROYED_QUICKLY
00271 
00272 AddedMatrix& BaseMatrix::operator+(const BaseMatrix& bm) const
00273 {
00274    REPORT
00275    AddedMatrix* x = new AddedMatrix(this, &bm);
00276    MatrixErrorNoSpace(x);
00277    return *x;
00278 }
00279 
00280 SPMatrix& SP(const BaseMatrix& bm1,const BaseMatrix& bm2)
00281 {
00282    REPORT
00283    SPMatrix* x = new SPMatrix(&bm1, &bm2);
00284    MatrixErrorNoSpace(x);
00285    return *x;
00286 }
00287 
00288 KPMatrix& KP(const BaseMatrix& bm1,const BaseMatrix& bm2)
00289 {
00290    REPORT
00291    KPMatrix* x = new KPMatrix(&bm1, &bm2);
00292    MatrixErrorNoSpace(x);
00293    return *x;
00294 }
00295 
00296 MultipliedMatrix& BaseMatrix::operator*(const BaseMatrix& bm) const
00297 {
00298    REPORT
00299    MultipliedMatrix* x = new MultipliedMatrix(this, &bm);
00300    MatrixErrorNoSpace(x);
00301    return *x;
00302 }
00303 
00304 ConcatenatedMatrix& BaseMatrix::operator|(const BaseMatrix& bm) const
00305 {
00306    REPORT
00307    ConcatenatedMatrix* x = new ConcatenatedMatrix(this, &bm);
00308    MatrixErrorNoSpace(x);
00309    return *x;
00310 }
00311 
00312 StackedMatrix& BaseMatrix::operator&(const BaseMatrix& bm) const
00313 {
00314    REPORT
00315    StackedMatrix* x = new StackedMatrix(this, &bm);
00316    MatrixErrorNoSpace(x);
00317    return *x;
00318 }
00319 
00320 //SolvedMatrix& InvertedMatrix::operator*(const BaseMatrix& bmx) const
00321 SolvedMatrix& InvertedMatrix::operator*(const BaseMatrix& bmx)
00322 {
00323    REPORT
00324    SolvedMatrix* x;
00325    Try { x = new SolvedMatrix(bm, &bmx); MatrixErrorNoSpace(x); }
00326    CatchAll { delete this; ReThrow; }
00327    delete this;                // since we are using bm rather than this
00328    return *x;
00329 }
00330 
00331 SubtractedMatrix& BaseMatrix::operator-(const BaseMatrix& bm) const
00332 {
00333    REPORT
00334    SubtractedMatrix* x = new SubtractedMatrix(this, &bm);
00335    MatrixErrorNoSpace(x);
00336    return *x;
00337 }
00338 
00339 ShiftedMatrix& BaseMatrix::operator+(Real f) const
00340 {
00341    REPORT
00342    ShiftedMatrix* x = new ShiftedMatrix(this, f);
00343    MatrixErrorNoSpace(x);
00344    return *x;
00345 }
00346 
00347 NegShiftedMatrix& operator-(Real f,const BaseMatrix& bm1)
00348 {
00349    REPORT
00350    NegShiftedMatrix* x = new NegShiftedMatrix(f, &bm1);
00351    MatrixErrorNoSpace(x);
00352    return *x;
00353 }
00354 
00355 ScaledMatrix& BaseMatrix::operator*(Real f) const
00356 {
00357    REPORT
00358    ScaledMatrix* x = new ScaledMatrix(this, f);
00359    MatrixErrorNoSpace(x);
00360    return *x;
00361 }
00362 
00363 ScaledMatrix& BaseMatrix::operator/(Real f) const
00364 {
00365    REPORT
00366    ScaledMatrix* x = new ScaledMatrix(this, 1.0/f);
00367    MatrixErrorNoSpace(x);
00368    return *x;
00369 }
00370 
00371 ShiftedMatrix& BaseMatrix::operator-(Real f) const
00372 {
00373    REPORT
00374    ShiftedMatrix* x = new ShiftedMatrix(this, -f);
00375    MatrixErrorNoSpace(x);
00376    return *x;
00377 }
00378 
00379 TransposedMatrix& BaseMatrix::t() const
00380 {
00381    REPORT
00382    TransposedMatrix* x = new TransposedMatrix(this);
00383    MatrixErrorNoSpace(x);
00384    return *x;
00385 }
00386 
00387 NegatedMatrix& BaseMatrix::operator-() const
00388 {
00389    REPORT
00390    NegatedMatrix* x = new NegatedMatrix(this);
00391    MatrixErrorNoSpace(x);
00392    return *x;
00393 }
00394 
00395 ReversedMatrix& BaseMatrix::Reverse() const
00396 {
00397    REPORT
00398    ReversedMatrix* x = new ReversedMatrix(this);
00399    MatrixErrorNoSpace(x);
00400    return *x;
00401 }
00402 
00403 InvertedMatrix& BaseMatrix::i() const
00404 {
00405    REPORT
00406    InvertedMatrix* x = new InvertedMatrix(this);
00407    MatrixErrorNoSpace(x);
00408    return *x;
00409 }
00410 
00411 RowedMatrix& BaseMatrix::AsRow() const
00412 {
00413    REPORT
00414    RowedMatrix* x = new RowedMatrix(this);
00415    MatrixErrorNoSpace(x);
00416    return *x;
00417 }
00418 
00419 ColedMatrix& BaseMatrix::AsColumn() const
00420 {
00421    REPORT
00422    ColedMatrix* x = new ColedMatrix(this);
00423    MatrixErrorNoSpace(x);
00424    return *x;
00425 }
00426 
00427 DiagedMatrix& BaseMatrix::AsDiagonal() const
00428 {
00429    REPORT
00430    DiagedMatrix* x = new DiagedMatrix(this);
00431    MatrixErrorNoSpace(x);
00432    return *x;
00433 }
00434 
00435 MatedMatrix& BaseMatrix::AsMatrix(int nrx, int ncx) const
00436 {
00437    REPORT
00438    MatedMatrix* x = new MatedMatrix(this,nrx,ncx);
00439    MatrixErrorNoSpace(x);
00440    return *x;
00441 }
00442 
00443 #else
00444 
00445 AddedMatrix BaseMatrix::operator+(const BaseMatrix& bm) const
00446 { REPORT return AddedMatrix(this, &bm); }
00447 
00448 SPMatrix SP(const BaseMatrix& bm1,const BaseMatrix& bm2)
00449 { REPORT return SPMatrix(&bm1, &bm2); }
00450 
00451 KPMatrix KP(const BaseMatrix& bm1,const BaseMatrix& bm2)
00452 { REPORT return KPMatrix(&bm1, &bm2); }
00453 
00454 MultipliedMatrix BaseMatrix::operator*(const BaseMatrix& bm) const
00455 { REPORT return MultipliedMatrix(this, &bm); }
00456 
00457 ConcatenatedMatrix BaseMatrix::operator|(const BaseMatrix& bm) const
00458 { REPORT return ConcatenatedMatrix(this, &bm); }
00459 
00460 StackedMatrix BaseMatrix::operator&(const BaseMatrix& bm) const
00461 { REPORT return StackedMatrix(this, &bm); }
00462 
00463 SolvedMatrix InvertedMatrix::operator*(const BaseMatrix& bmx) const
00464 { REPORT return SolvedMatrix(bm, &bmx); }
00465 
00466 SubtractedMatrix BaseMatrix::operator-(const BaseMatrix& bm) const
00467 { REPORT return SubtractedMatrix(this, &bm); }
00468 
00469 ShiftedMatrix BaseMatrix::operator+(Real f) const
00470 { REPORT return ShiftedMatrix(this, f); }
00471 
00472 NegShiftedMatrix operator-(Real f, const BaseMatrix& bm)
00473 { REPORT return NegShiftedMatrix(f, &bm); }
00474 
00475 ScaledMatrix BaseMatrix::operator*(Real f) const
00476 { REPORT return ScaledMatrix(this, f); }
00477 
00478 ScaledMatrix BaseMatrix::operator/(Real f) const
00479 { REPORT return ScaledMatrix(this, 1.0/f); }
00480 
00481 ShiftedMatrix BaseMatrix::operator-(Real f) const
00482 { REPORT return ShiftedMatrix(this, -f); }
00483 
00484 TransposedMatrix BaseMatrix::t() const
00485 { REPORT return TransposedMatrix(this); }
00486 
00487 NegatedMatrix BaseMatrix::operator-() const
00488 { REPORT return NegatedMatrix(this); }
00489 
00490 ReversedMatrix BaseMatrix::Reverse() const
00491 { REPORT return ReversedMatrix(this); }
00492 
00493 InvertedMatrix BaseMatrix::i() const
00494 { REPORT return InvertedMatrix(this); }
00495 
00496 
00497 RowedMatrix BaseMatrix::AsRow() const
00498 { REPORT return RowedMatrix(this); }
00499 
00500 ColedMatrix BaseMatrix::AsColumn() const
00501 { REPORT return ColedMatrix(this); }
00502 
00503 DiagedMatrix BaseMatrix::AsDiagonal() const
00504 { REPORT return DiagedMatrix(this); }
00505 
00506 MatedMatrix BaseMatrix::AsMatrix(int nrx, int ncx) const
00507 { REPORT return MatedMatrix(this,nrx,ncx); }
00508 
00509 #endif
00510 
00511 void GeneralMatrix::operator=(Real f)
00512 { REPORT int i=storage; Real* s=store; while (i--) { *s++ = f; } }
00513 
00514 void Matrix::operator=(const BaseMatrix& X)
00515 {
00516    REPORT //CheckConversion(X);
00517    // MatrixConversionCheck mcc;
00518    Eq(X,MatrixType::Rt);
00519 } 
00520 
00521 void RowVector::operator=(const BaseMatrix& X)
00522 {
00523    REPORT  // CheckConversion(X);
00524    // MatrixConversionCheck mcc;
00525    Eq(X,MatrixType::RV);
00526    if (nrows!=1)
00527       { Tracer tr("RowVector(=)"); Throw(VectorException(*this)); }
00528 }
00529 
00530 void ColumnVector::operator=(const BaseMatrix& X)
00531 {
00532    REPORT //CheckConversion(X);
00533    // MatrixConversionCheck mcc;
00534    Eq(X,MatrixType::CV);
00535    if (ncols!=1)
00536       { Tracer tr("ColumnVector(=)"); Throw(VectorException(*this)); }
00537 }
00538 
00539 void SymmetricMatrix::operator=(const BaseMatrix& X)
00540 {
00541    REPORT // CheckConversion(X);
00542    // MatrixConversionCheck mcc;
00543    Eq(X,MatrixType::Sm);
00544 }
00545 
00546 void UpperTriangularMatrix::operator=(const BaseMatrix& X)
00547 {
00548    REPORT //CheckConversion(X);
00549    // MatrixConversionCheck mcc;
00550    Eq(X,MatrixType::UT);
00551 }
00552 
00553 void LowerTriangularMatrix::operator=(const BaseMatrix& X)
00554 {
00555    REPORT //CheckConversion(X);
00556    // MatrixConversionCheck mcc;
00557    Eq(X,MatrixType::LT);
00558 }
00559 
00560 void DiagonalMatrix::operator=(const BaseMatrix& X)
00561 {
00562    REPORT // CheckConversion(X);
00563    // MatrixConversionCheck mcc;
00564    Eq(X,MatrixType::Dg);
00565 }
00566 
00567 void IdentityMatrix::operator=(const BaseMatrix& X)
00568 {
00569    REPORT // CheckConversion(X);
00570    // MatrixConversionCheck mcc;
00571    Eq(X,MatrixType::Id);
00572 }
00573 
00574 void GeneralMatrix::operator<<(const Real* r)
00575 {
00576    REPORT
00577    int i = storage; Real* s=store;
00578    while(i--) *s++ = *r++;
00579 }
00580 
00581 
00582 void GenericMatrix::operator=(const GenericMatrix& bmx)
00583 {
00584    if (&bmx != this) { REPORT if (gm) delete gm; gm = bmx.gm->Image();}
00585    else { REPORT }
00586    gm->Protect();
00587 }
00588 
00589 void GenericMatrix::operator=(const BaseMatrix& bmx)
00590 {
00591    if (gm)
00592    {
00593       int counter=bmx.search(gm);
00594       if (counter==0) { REPORT delete gm; gm=0; }
00595       else { REPORT gm->Release(counter); }
00596    }
00597    else { REPORT }
00598    GeneralMatrix* gmx = ((BaseMatrix&)bmx).Evaluate();
00599    if (gmx != gm) { REPORT if (gm) delete gm; gm = gmx->Image(); }
00600    else { REPORT }
00601    gm->Protect();
00602 }
00603 
00604 
00605 /*************************** += etc ***************************************/
00606 
00607 // will also need versions for SubMatrix
00608 
00609 
00610 
00611 // GeneralMatrix operators
00612 
00613 void GeneralMatrix::operator+=(const BaseMatrix& X)
00614 {
00615    REPORT
00616    Tracer tr("GeneralMatrix::operator+=");
00617    // MatrixConversionCheck mcc;
00618    Protect();                                   // so it cannot get deleted
00619                                                 // during Evaluate
00620    GeneralMatrix* gm = ((BaseMatrix&)X).Evaluate();
00621 #ifdef TEMPS_DESTROYED_QUICKLY
00622    AddedMatrix* am = new AddedMatrix(this,gm);
00623    MatrixErrorNoSpace(am);
00624    if (gm==this) Release(2); else Release();
00625    Eq2(*am,Type());
00626 #else
00627    AddedMatrix am(this,gm);
00628    if (gm==this) Release(2); else Release();
00629    Eq2(am,Type());
00630 #endif
00631 }
00632 
00633 void GeneralMatrix::operator-=(const BaseMatrix& X)
00634 {
00635    REPORT
00636    Tracer tr("GeneralMatrix::operator-=");
00637    // MatrixConversionCheck mcc;
00638    Protect();                                   // so it cannot get deleted
00639                                                 // during Evaluate
00640    GeneralMatrix* gm = ((BaseMatrix&)X).Evaluate();
00641 #ifdef TEMPS_DESTROYED_QUICKLY
00642    SubtractedMatrix* am = new SubtractedMatrix(this,gm);
00643    MatrixErrorNoSpace(am);
00644    if (gm==this) Release(2); else Release();
00645    Eq2(*am,Type());
00646 #else
00647    SubtractedMatrix am(this,gm);
00648    if (gm==this) Release(2); else Release();
00649    Eq2(am,Type());
00650 #endif
00651 }
00652 
00653 void GeneralMatrix::operator*=(const BaseMatrix& X)
00654 {
00655    REPORT
00656    Tracer tr("GeneralMatrix::operator*=");
00657    // MatrixConversionCheck mcc;
00658    Protect();                                   // so it cannot get deleted
00659                                                 // during Evaluate
00660    GeneralMatrix* gm = ((BaseMatrix&)X).Evaluate();
00661 #ifdef TEMPS_DESTROYED_QUICKLY
00662    MultipliedMatrix* am = new MultipliedMatrix(this,gm);
00663    MatrixErrorNoSpace(am);
00664    if (gm==this) Release(2); else Release();
00665    Eq2(*am,Type());
00666 #else
00667    MultipliedMatrix am(this,gm);
00668    if (gm==this) Release(2); else Release();
00669    Eq2(am,Type());
00670 #endif
00671 }
00672 
00673 void GeneralMatrix::operator|=(const BaseMatrix& X)
00674 {
00675    REPORT
00676    Tracer tr("GeneralMatrix::operator|=");
00677    // MatrixConversionCheck mcc;
00678    Protect();                                   // so it cannot get deleted
00679                                                 // during Evaluate
00680    GeneralMatrix* gm = ((BaseMatrix&)X).Evaluate();
00681 #ifdef TEMPS_DESTROYED_QUICKLY
00682    ConcatenatedMatrix* am = new ConcatenatedMatrix(this,gm);
00683    MatrixErrorNoSpace(am);
00684    if (gm==this) Release(2); else Release();
00685    Eq2(*am,Type());
00686 #else
00687    ConcatenatedMatrix am(this,gm);
00688    if (gm==this) Release(2); else Release();
00689    Eq2(am,Type());
00690 #endif
00691 }
00692 
00693 void GeneralMatrix::operator&=(const BaseMatrix& X)
00694 {
00695    REPORT
00696    Tracer tr("GeneralMatrix::operator&=");
00697    // MatrixConversionCheck mcc;
00698    Protect();                                   // so it cannot get deleted
00699                                                 // during Evaluate
00700    GeneralMatrix* gm = ((BaseMatrix&)X).Evaluate();
00701 #ifdef TEMPS_DESTROYED_QUICKLY
00702    StackedMatrix* am = new StackedMatrix(this,gm);
00703    MatrixErrorNoSpace(am);
00704    if (gm==this) Release(2); else Release();
00705    Eq2(*am,Type());
00706 #else
00707    StackedMatrix am(this,gm);
00708    if (gm==this) Release(2); else Release();
00709    Eq2(am,Type());
00710 #endif
00711 }
00712 
00713 void GeneralMatrix::operator+=(Real r)
00714 {
00715    REPORT
00716    Tracer tr("GeneralMatrix::operator+=(Real)");
00717    // MatrixConversionCheck mcc;
00718 #ifdef TEMPS_DESTROYED_QUICKLY
00719    ShiftedMatrix* am = new ShiftedMatrix(this,r);
00720    MatrixErrorNoSpace(am);
00721    Release(); Eq2(*am,Type());
00722 #else
00723    ShiftedMatrix am(this,r);
00724    Release(); Eq2(am,Type());
00725 #endif
00726 }
00727 
00728 void GeneralMatrix::operator*=(Real r)
00729 {
00730    REPORT
00731    Tracer tr("GeneralMatrix::operator*=(Real)");
00732    // MatrixConversionCheck mcc;
00733 #ifdef TEMPS_DESTROYED_QUICKLY
00734    ScaledMatrix* am = new ScaledMatrix(this,r);
00735    MatrixErrorNoSpace(am);
00736    Release(); Eq2(*am,Type());
00737 #else
00738    ScaledMatrix am(this,r);
00739    Release(); Eq2(am,Type());
00740 #endif
00741 }
00742 
00743 
00744 // Generic matrix operators
00745 
00746 void GenericMatrix::operator+=(const BaseMatrix& X)
00747 {
00748    REPORT
00749    Tracer tr("GenericMatrix::operator+=");
00750    if (!gm) Throw(ProgramException("GenericMatrix is null"));
00751    gm->Protect();            // so it cannot get deleted during Evaluate
00752    GeneralMatrix* gmx = ((BaseMatrix&)X).Evaluate();
00753 #ifdef TEMPS_DESTROYED_QUICKLY
00754    AddedMatrix* am = new AddedMatrix(gm,gmx);
00755    MatrixErrorNoSpace(am);
00756    if (gmx==gm) gm->Release(2); else gm->Release();
00757    GeneralMatrix* gmy = am->Evaluate();
00758 #else
00759    AddedMatrix am(gm,gmx);
00760    if (gmx==gm) gm->Release(2); else gm->Release();
00761    GeneralMatrix* gmy = am.Evaluate();
00762 #endif
00763    if (gmy != gm) { REPORT delete gm; gm = gmy->Image(); }
00764    else { REPORT }
00765    gm->Protect();
00766 }
00767 
00768 void GenericMatrix::operator-=(const BaseMatrix& X)
00769 {
00770    REPORT
00771    Tracer tr("GenericMatrix::operator-=");
00772    if (!gm) Throw(ProgramException("GenericMatrix is null"));
00773    gm->Protect();            // so it cannot get deleted during Evaluate
00774    GeneralMatrix* gmx = ((BaseMatrix&)X).Evaluate();
00775 #ifdef TEMPS_DESTROYED_QUICKLY
00776    SubtractedMatrix* am = new SubtractedMatrix(gm,gmx);
00777    MatrixErrorNoSpace(am);
00778    if (gmx==gm) gm->Release(2); else gm->Release();
00779    GeneralMatrix* gmy = am->Evaluate();
00780 #else
00781    SubtractedMatrix am(gm,gmx);
00782    if (gmx==gm) gm->Release(2); else gm->Release();
00783    GeneralMatrix* gmy = am.Evaluate();
00784 #endif
00785    if (gmy != gm) { REPORT delete gm; gm = gmy->Image(); }
00786    else { REPORT }
00787    gm->Protect();
00788 }
00789 
00790 void GenericMatrix::operator*=(const BaseMatrix& X)
00791 {
00792    REPORT
00793    Tracer tr("GenericMatrix::operator*=");
00794    if (!gm) Throw(ProgramException("GenericMatrix is null"));
00795    gm->Protect();            // so it cannot get deleted during Evaluate
00796    GeneralMatrix* gmx = ((BaseMatrix&)X).Evaluate();
00797 #ifdef TEMPS_DESTROYED_QUICKLY
00798    MultipliedMatrix* am = new MultipliedMatrix(gm,gmx);
00799    MatrixErrorNoSpace(am);
00800    if (gmx==gm) gm->Release(2); else gm->Release();
00801    GeneralMatrix* gmy = am->Evaluate();
00802 #else
00803    MultipliedMatrix am(gm,gmx);
00804    if (gmx==gm) gm->Release(2); else gm->Release();
00805    GeneralMatrix* gmy = am.Evaluate();
00806 #endif
00807    if (gmy != gm) { REPORT delete gm; gm = gmy->Image(); }
00808    else { REPORT }
00809    gm->Protect();
00810 }
00811 
00812 void GenericMatrix::operator|=(const BaseMatrix& X)
00813 {
00814    REPORT
00815    Tracer tr("GenericMatrix::operator|=");
00816    if (!gm) Throw(ProgramException("GenericMatrix is null"));
00817    gm->Protect();            // so it cannot get deleted during Evaluate
00818    GeneralMatrix* gmx = ((BaseMatrix&)X).Evaluate();
00819 #ifdef TEMPS_DESTROYED_QUICKLY
00820    ConcatenatedMatrix* am = new ConcatenatedMatrix(gm,gmx);
00821    MatrixErrorNoSpace(am);
00822    if (gmx==gm) gm->Release(2); else gm->Release();
00823    GeneralMatrix* gmy = am->Evaluate();
00824 #else
00825    ConcatenatedMatrix am(gm,gmx);
00826    if (gmx==gm) gm->Release(2); else gm->Release();
00827    GeneralMatrix* gmy = am.Evaluate();
00828 #endif
00829    if (gmy != gm) { REPORT delete gm; gm = gmy->Image(); }
00830    else { REPORT }
00831    gm->Protect();
00832 }
00833 
00834 void GenericMatrix::operator&=(const BaseMatrix& X)
00835 {
00836    REPORT
00837    Tracer tr("GenericMatrix::operator&=");
00838    if (!gm) Throw(ProgramException("GenericMatrix is null"));
00839    gm->Protect();            // so it cannot get deleted during Evaluate
00840    GeneralMatrix* gmx = ((BaseMatrix&)X).Evaluate();
00841 #ifdef TEMPS_DESTROYED_QUICKLY
00842    StackedMatrix* am = new StackedMatrix(gm,gmx);
00843    MatrixErrorNoSpace(am);
00844    if (gmx==gm) gm->Release(2); else gm->Release();
00845    GeneralMatrix* gmy = am->Evaluate();
00846 #else
00847    StackedMatrix am(gm,gmx);
00848    if (gmx==gm) gm->Release(2); else gm->Release();
00849    GeneralMatrix* gmy = am.Evaluate();
00850 #endif
00851    if (gmy != gm) { REPORT delete gm; gm = gmy->Image(); }
00852    else { REPORT }
00853    gm->Protect();
00854 }
00855 
00856 void GenericMatrix::operator+=(Real r)
00857 {
00858    REPORT
00859    Tracer tr("GenericMatrix::operator+= (Real)");
00860    if (!gm) Throw(ProgramException("GenericMatrix is null"));
00861 #ifdef TEMPS_DESTROYED_QUICKLY
00862    ShiftedMatrix* am = new ShiftedMatrix(gm,r);
00863    MatrixErrorNoSpace(am);
00864    gm->Release();
00865    GeneralMatrix* gmy = am->Evaluate();
00866 #else
00867    ShiftedMatrix am(gm,r);
00868    gm->Release();
00869    GeneralMatrix* gmy = am.Evaluate();
00870 #endif
00871    if (gmy != gm) { REPORT delete gm; gm = gmy->Image(); }
00872    else { REPORT }
00873    gm->Protect();
00874 }
00875 
00876 void GenericMatrix::operator*=(Real r)
00877 {
00878    REPORT
00879    Tracer tr("GenericMatrix::operator*= (Real)");
00880    if (!gm) Throw(ProgramException("GenericMatrix is null"));
00881 #ifdef TEMPS_DESTROYED_QUICKLY
00882    ScaledMatrix* am = new ScaledMatrix(gm,r);
00883    MatrixErrorNoSpace(am);
00884    gm->Release();
00885    GeneralMatrix* gmy = am->Evaluate();
00886 #else
00887    ScaledMatrix am(gm,r);
00888    gm->Release();
00889    GeneralMatrix* gmy = am.Evaluate();
00890 #endif
00891    if (gmy != gm) { REPORT delete gm; gm = gmy->Image(); }
00892    else { REPORT }
00893    gm->Protect();
00894 }
00895 
00896 
00897 /************************* element access *********************************/
00898 
00899 Real& Matrix::element(int m, int n)
00900 {
00901    REPORT
00902    if (m<0 || m>= nrows || n<0 || n>= ncols)
00903       Throw(IndexException(m,n,*this,true));
00904    return store[m*ncols+n];
00905 }
00906 
00907 Real Matrix::element(int m, int n) const
00908 {
00909    REPORT
00910    if (m<0 || m>= nrows || n<0 || n>= ncols)
00911       Throw(IndexException(m,n,*this,true));
00912    return store[m*ncols+n];
00913 }
00914 
00915 Real& SymmetricMatrix::element(int m, int n)
00916 {
00917    REPORT
00918    if (m<0 || n<0 || m >= nrows || n>=ncols)
00919       Throw(IndexException(m,n,*this,true));
00920    if (m>=n) return store[tristore(m)+n];
00921    else return store[tristore(n)+m];
00922 }
00923 
00924 Real SymmetricMatrix::element(int m, int n) const
00925 {
00926    REPORT
00927    if (m<0 || n<0 || m >= nrows || n>=ncols)
00928       Throw(IndexException(m,n,*this,true));
00929    if (m>=n) return store[tristore(m)+n];
00930    else return store[tristore(n)+m];
00931 }
00932 
00933 Real& UpperTriangularMatrix::element(int m, int n)
00934 {
00935    REPORT
00936    if (m<0 || n<m || n>=ncols)
00937       Throw(IndexException(m,n,*this,true));
00938    return store[m*ncols+n-tristore(m)];
00939 }
00940 
00941 Real UpperTriangularMatrix::element(int m, int n) const
00942 {
00943    REPORT
00944    if (m<0 || n<m || n>=ncols)
00945       Throw(IndexException(m,n,*this,true));
00946    return store[m*ncols+n-tristore(m)];
00947 }
00948 
00949 Real& LowerTriangularMatrix::element(int m, int n)
00950 {
00951    REPORT
00952    if (n<0 || m<n || m>=nrows)
00953       Throw(IndexException(m,n,*this,true));
00954    return store[tristore(m)+n];
00955 }
00956 
00957 Real LowerTriangularMatrix::element(int m, int n) const
00958 {
00959    REPORT
00960    if (n<0 || m<n || m>=nrows)
00961       Throw(IndexException(m,n,*this,true));
00962    return store[tristore(m)+n];
00963 }
00964 
00965 Real& DiagonalMatrix::element(int m, int n)
00966 {
00967    REPORT
00968    if (n<0 || m!=n || m>=nrows || n>=ncols)
00969       Throw(IndexException(m,n,*this,true));
00970    return store[n];
00971 }
00972 
00973 Real DiagonalMatrix::element(int m, int n) const
00974 {
00975    REPORT
00976    if (n<0 || m!=n || m>=nrows || n>=ncols)
00977       Throw(IndexException(m,n,*this,true));
00978    return store[n];
00979 }
00980 
00981 Real& DiagonalMatrix::element(int m)
00982 {
00983    REPORT
00984    if (m<0 || m>=nrows) Throw(IndexException(m,*this,true));
00985    return store[m];
00986 }
00987 
00988 Real DiagonalMatrix::element(int m) const
00989 {
00990    REPORT
00991    if (m<0 || m>=nrows) Throw(IndexException(m,*this,true));
00992    return store[m];
00993 }
00994 
00995 Real& ColumnVector::element(int m)
00996 {
00997    REPORT
00998    if (m<0 || m>= nrows) Throw(IndexException(m,*this,true));
00999    return store[m];
01000 }
01001 
01002 Real ColumnVector::element(int m) const
01003 {
01004    REPORT
01005    if (m<0 || m>= nrows) Throw(IndexException(m,*this,true));
01006    return store[m];
01007 }
01008 
01009 Real& RowVector::element(int n)
01010 {
01011    REPORT
01012    if (n<0 || n>= ncols)  Throw(IndexException(n,*this,true));
01013    return store[n];
01014 }
01015 
01016 Real RowVector::element(int n) const
01017 {
01018    REPORT
01019    if (n<0 || n>= ncols)  Throw(IndexException(n,*this,true));
01020    return store[n];
01021 }
01022 
01023 Real& BandMatrix::element(int m, int n)
01024 {
01025    REPORT
01026    int w = upper+lower+1; int i = lower+n-m;
01027    if (m<0 || m>= nrows || n<0 || n>= ncols || i<0 || i>=w)
01028       Throw(IndexException(m,n,*this,true));
01029    return store[w*m+i];
01030 }
01031 
01032 Real BandMatrix::element(int m, int n) const
01033 {
01034    REPORT
01035    int w = upper+lower+1; int i = lower+n-m;
01036    if (m<0 || m>= nrows || n<0 || n>= ncols || i<0 || i>=w)
01037       Throw(IndexException(m,n,*this,true));
01038    return store[w*m+i];
01039 }
01040 
01041 Real& UpperBandMatrix::element(int m, int n)
01042 {
01043    REPORT
01044    int w = upper+1; int i = n-m;
01045    if (m<0 || m>= nrows || n<0 || n>= ncols || i<0 || i>=w)
01046       Throw(IndexException(m,n,*this,true));
01047    return store[w*m+i];
01048 }
01049 
01050 Real UpperBandMatrix::element(int m, int n) const
01051 {
01052    REPORT
01053    int w = upper+1; int i = n-m;
01054    if (m<0 || m>= nrows || n<0 || n>= ncols || i<0 || i>=w)
01055       Throw(IndexException(m,n,*this,true));
01056    return store[w*m+i];
01057 }
01058 
01059 Real& LowerBandMatrix::element(int m, int n)
01060 {
01061    REPORT
01062    int w = lower+1; int i = lower+n-m;
01063    if (m<0 || m>= nrows || n<0 || n>= ncols || i<0 || i>=w)
01064       Throw(IndexException(m,n,*this,true));
01065    return store[w*m+i];
01066 }
01067 
01068 Real LowerBandMatrix::element(int m, int n) const
01069 {
01070    REPORT
01071    int w = lower+1; int i = lower+n-m;
01072    if (m<0 || m>= nrows || n<0 || n>= ncols || i<0 || i>=w)
01073       Throw(IndexException(m,n,*this,true));
01074    return store[w*m+i];
01075 }
01076 
01077 Real& SymmetricBandMatrix::element(int m, int n)
01078 {
01079    REPORT
01080    int w = lower+1;
01081    if (m>=n)
01082    {
01083       REPORT
01084       int i = lower+n-m;
01085       if ( m>=nrows || n<0 || i<0 )
01086          Throw(IndexException(m,n,*this,true));
01087       return store[w*m+i];
01088    }
01089    else
01090    {
01091       REPORT
01092       int i = lower+m-n;
01093       if ( n>=nrows || m<0 || i<0 )
01094          Throw(IndexException(m,n,*this,true));
01095       return store[w*n+i];
01096    }
01097 }
01098 
01099 Real SymmetricBandMatrix::element(int m, int n) const
01100 {
01101    REPORT
01102    int w = lower+1;
01103    if (m>=n)
01104    {
01105       REPORT
01106       int i = lower+n-m;
01107       if ( m>=nrows || n<0 || i<0 )
01108          Throw(IndexException(m,n,*this,true));
01109       return store[w*m+i];
01110    }
01111    else
01112    {
01113       REPORT
01114       int i = lower+m-n;
01115       if ( n>=nrows || m<0 || i<0 )
01116          Throw(IndexException(m,n,*this,true));
01117       return store[w*n+i];
01118    }
01119 }
01120 
01121 #ifdef use_namespace
01122 }
01123 #endif
01124 


rl_agent
Author(s): Todd Hester
autogenerated on Thu Jun 6 2019 22:00:13