home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sources / misc / 4252 / newmat4.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-11  |  16.6 KB  |  645 lines

  1. //$$ newmat4.cxx       Constructors, ReDimension, basic utilities
  2.  
  3. // Copyright (C) 1991,2,3: R B Davies
  4.  
  5. #include "include.h"
  6.  
  7. #include "newmat.h"
  8. #include "newmatrc.h"
  9.  
  10. //#define REPORT { static ExeCounter ExeCount(__LINE__,4); ExeCount++; }
  11.  
  12. #define REPORT {}
  13.  
  14. //#define REPORT1 { static ExeCounter ExeCount(__LINE__,4); ExeCount++; }
  15.  
  16. // REPORT1 constructors only - doesn't work in turbo and Borland C++
  17.  
  18. #define REPORT1 {}
  19.  
  20.  
  21. /*************************** general utilities *************************/
  22.  
  23. static int tristore(int n)                      // els in triangular matrix
  24. { return (n*(n+1))/2; }
  25.  
  26.  
  27. /****************************** constructors ***************************/
  28.  
  29. GeneralMatrix::GeneralMatrix()
  30. { store=0; storage=0; nrows=0; ncols=0; tag=-1; }
  31.  
  32. GeneralMatrix::GeneralMatrix(ArrayLengthSpecifier s)
  33. {
  34.    REPORT1
  35.    storage=s.Value(); tag=-1;
  36.    if (storage)
  37.    {
  38.       store = new Real [storage]; MatrixErrorNoSpace(store);
  39.       MONITOR_REAL_NEW("Make (GenMatrix)",storage,store)
  40.    }
  41.    else store = 0;
  42. }
  43.  
  44. Matrix::Matrix(int m, int n) : GeneralMatrix(m*n)
  45. { REPORT1 nrows=m; ncols=n; }
  46.  
  47. SymmetricMatrix::SymmetricMatrix(ArrayLengthSpecifier n)
  48.    : GeneralMatrix(tristore(n.Value()))
  49. { REPORT1 nrows=n.Value(); ncols=n.Value(); }
  50.  
  51. UpperTriangularMatrix::UpperTriangularMatrix(ArrayLengthSpecifier n)
  52.    : GeneralMatrix(tristore(n.Value()))
  53. { REPORT1 nrows=n.Value(); ncols=n.Value(); }
  54.  
  55. LowerTriangularMatrix::LowerTriangularMatrix(ArrayLengthSpecifier n)
  56.    : GeneralMatrix(tristore(n.Value()))
  57. { REPORT1 nrows=n.Value(); ncols=n.Value(); }
  58.  
  59. DiagonalMatrix::DiagonalMatrix(ArrayLengthSpecifier m) : GeneralMatrix(m)
  60. { REPORT1 nrows=m.Value(); ncols=m.Value(); }
  61.  
  62. Matrix::Matrix(const BaseMatrix& M)
  63. {
  64.    REPORT1 // CheckConversion(M);
  65.    MatrixConversionCheck mcc;
  66.    GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::Rt);
  67.    GetMatrix(gmx);
  68. }
  69.  
  70. RowVector::RowVector(const BaseMatrix& M) : Matrix(M)
  71. {
  72.    if (nrows!=1)
  73.    {
  74.       Tracer tr("RowVector");
  75.       Throw(VectorException(*this));
  76.    }
  77. }
  78.  
  79. ColumnVector::ColumnVector(const BaseMatrix& M) : Matrix(M)
  80. {
  81.    if (ncols!=1)
  82.    {
  83.       Tracer tr("ColumnVector");
  84.       Throw(VectorException(*this));
  85.    }
  86. }
  87.  
  88. SymmetricMatrix::SymmetricMatrix(const BaseMatrix& M)
  89. {
  90.    REPORT1  // CheckConversion(M);
  91.    MatrixConversionCheck mcc;
  92.    GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::Sm);
  93.    GetMatrix(gmx);
  94. }
  95.  
  96. UpperTriangularMatrix::UpperTriangularMatrix(const BaseMatrix& M)
  97. {
  98.    REPORT1 // CheckConversion(M);
  99.    MatrixConversionCheck mcc;
  100.    GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::UT);
  101.    GetMatrix(gmx);
  102. }
  103.  
  104. LowerTriangularMatrix::LowerTriangularMatrix(const BaseMatrix& M)
  105. {
  106.    REPORT1 // CheckConversion(M);
  107.    MatrixConversionCheck mcc;
  108.    GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::LT);
  109.    GetMatrix(gmx);
  110. }
  111.  
  112. DiagonalMatrix::DiagonalMatrix(const BaseMatrix& M)
  113. {
  114.    REPORT1 //CheckConversion(M);
  115.    MatrixConversionCheck mcc;
  116.    GeneralMatrix* gmx=((BaseMatrix&)M).Evaluate(MatrixType::Dg);
  117.    GetMatrix(gmx);
  118. }
  119.  
  120. GeneralMatrix::~GeneralMatrix()
  121. {
  122.    if (store)
  123.    {
  124.       MONITOR_REAL_DELETE("Free (GenMatrix)",storage,store)
  125. #ifdef Version21
  126.       delete [] store;
  127. #else
  128.       delete [storage] store;
  129. #endif
  130.    }
  131. }
  132.  
  133. CroutMatrix::CroutMatrix(const BaseMatrix& m)
  134. {
  135.    REPORT1
  136.    Tracer tr("CroutMatrix");
  137.    GeneralMatrix* gm = ((BaseMatrix&)m).Evaluate(MatrixType::Rt);
  138.    GetMatrix(gm);
  139.    if (nrows!=ncols) Throw(NotSquareException(*this));
  140.    d=TRUE; sing=FALSE;
  141.    indx=new int [nrows]; MatrixErrorNoSpace(indx);
  142.    MONITOR_INT_NEW("Index (CroutMat)",nrows,indx)
  143.    ludcmp();
  144. }
  145.  
  146. CroutMatrix::~CroutMatrix()
  147. {
  148.    MONITOR_INT_DELETE("Index (CroutMat)",nrows,indx)
  149. #ifdef Version21
  150.    delete [] indx;
  151. #else
  152.    delete [nrows] indx;
  153. #endif
  154. }
  155.  
  156. //ReturnMatrixX::ReturnMatrixX(GeneralMatrix& gmx)
  157. //{
  158. //   REPORT1
  159. //   gm = gmx.Image(); gm->ReleaseAndDelete();
  160. //}
  161.  
  162. #ifndef TEMPS_DESTROYED_QUICKLY
  163.  
  164. GeneralMatrix::operator ReturnMatrixX() const
  165. {
  166.    REPORT
  167.    GeneralMatrix* gm = Image(); gm->ReleaseAndDelete(); 
  168.    return ReturnMatrixX(gm);
  169. }
  170.  
  171. #else
  172.  
  173. GeneralMatrix::operator ReturnMatrixX&() const
  174. {
  175.    REPORT
  176.    GeneralMatrix* gm = Image(); gm->ReleaseAndDelete();
  177.    ReturnMatrixX* x = new ReturnMatrixX(gm);
  178.    MatrixErrorNoSpace(x); return *x;
  179. }
  180.  
  181. #endif
  182.  
  183. /**************************** ReDimension matrices ***************************/
  184.  
  185. void GeneralMatrix::ReDimension(int nr, int nc, int s)
  186. {
  187.    REPORT 
  188.    if (store)
  189.    {
  190.       MONITOR_REAL_DELETE("Free (ReDimensi)",storage,store)
  191. #ifdef Version21
  192.       delete [] store;
  193. #else
  194.       delete [storage] store;
  195. #endif
  196.    }
  197.    storage=s; nrows=nr; ncols=nc; tag=-1;
  198.    if (s)
  199.    {
  200.       store = new Real [storage]; MatrixErrorNoSpace(store);
  201.       MONITOR_REAL_NEW("Make (ReDimensi)",storage,store)
  202.    }
  203.    else store = 0;
  204. }
  205.  
  206. void Matrix::ReDimension(int nr, int nc)
  207. { REPORT GeneralMatrix::ReDimension(nr,nc,nr*nc); }
  208.  
  209. void SymmetricMatrix::ReDimension(int nr)
  210. { REPORT GeneralMatrix::ReDimension(nr,nr,tristore(nr)); }
  211.  
  212. void UpperTriangularMatrix::ReDimension(int nr)
  213. { REPORT GeneralMatrix::ReDimension(nr,nr,tristore(nr)); }
  214.  
  215. void LowerTriangularMatrix::ReDimension(int nr)
  216. { REPORT GeneralMatrix::ReDimension(nr,nr,tristore(nr)); }
  217.  
  218. void DiagonalMatrix::ReDimension(int nr)
  219. { REPORT GeneralMatrix::ReDimension(nr,nr,nr); }
  220.  
  221. void RowVector::ReDimension(int nc)
  222. { REPORT GeneralMatrix::ReDimension(1,nc,nc); }
  223.  
  224. void ColumnVector::ReDimension(int nr)
  225. { REPORT GeneralMatrix::ReDimension(nr,1,nr); }
  226.  
  227.  
  228. /********************* manipulate types, storage **************************/
  229.  
  230. int GeneralMatrix::search(const BaseMatrix* s) const
  231. { REPORT return (s==this) ? 1 : 0; }
  232.  
  233. int MultipliedMatrix::search(const BaseMatrix* s) const
  234. { REPORT return bm1->search(s) + bm2->search(s); }
  235.  
  236. int ShiftedMatrix::search(const BaseMatrix* s) const
  237. { REPORT return bm->search(s); }
  238.  
  239. int NegatedMatrix::search(const BaseMatrix* s) const
  240. { REPORT return bm->search(s); }
  241.  
  242. int ConstMatrix::search(const BaseMatrix* s) const
  243. { REPORT return (s==cgm) ? 1 : 0; }
  244.  
  245. int ReturnMatrixX::search(const BaseMatrix* s) const
  246. { REPORT return (s==gm) ? 1 : 0; }
  247.  
  248. MatrixType Matrix::Type() const { return MatrixType::Rt; }
  249. MatrixType SymmetricMatrix::Type() const { return MatrixType::Sm; }
  250. MatrixType UpperTriangularMatrix::Type() const { return MatrixType::UT; }
  251. MatrixType LowerTriangularMatrix::Type() const { return MatrixType::LT; }
  252. MatrixType DiagonalMatrix::Type() const { return MatrixType::Dg; }
  253. MatrixType RowVector::Type() const { return MatrixType::RV; }
  254. MatrixType ColumnVector::Type() const { return MatrixType::CV; }
  255. MatrixType CroutMatrix::Type() const { return MatrixType::Ct; }
  256. MatrixType BandMatrix::Type() const { return MatrixType::BM; }
  257. MatrixType UpperBandMatrix::Type() const { return MatrixType::UB; }
  258. MatrixType LowerBandMatrix::Type() const { return MatrixType::LB; }
  259. MatrixType SymmetricBandMatrix::Type() const { return MatrixType::SB; }
  260.  
  261. MatrixBandWidth BaseMatrix::BandWidth() const { return -1; }
  262. MatrixBandWidth DiagonalMatrix::BandWidth() const { return 0; }
  263.  
  264. MatrixBandWidth BandMatrix::BandWidth() const
  265.    { return MatrixBandWidth(lower,upper); }
  266.  
  267. MatrixBandWidth AddedMatrix::BandWidth() const
  268. { return gm1->BandWidth() + gm2->BandWidth(); }
  269.  
  270. MatrixBandWidth MultipliedMatrix::BandWidth() const
  271. { return gm1->BandWidth() * gm2->BandWidth(); }
  272.  
  273. MatrixBandWidth SolvedMatrix::BandWidth() const { return -1; }
  274. MatrixBandWidth ScaledMatrix::BandWidth() const { return gm->BandWidth(); }
  275. MatrixBandWidth NegatedMatrix::BandWidth() const { return gm->BandWidth(); }
  276.  
  277. MatrixBandWidth TransposedMatrix::BandWidth() const
  278. { return gm->BandWidth().t(); }
  279.  
  280. MatrixBandWidth InvertedMatrix::BandWidth() const { return -1; }
  281. MatrixBandWidth RowedMatrix::BandWidth() const { return -1; }
  282. MatrixBandWidth ColedMatrix::BandWidth() const { return -1; }
  283. MatrixBandWidth DiagedMatrix::BandWidth() const { return 0; }
  284. MatrixBandWidth MatedMatrix::BandWidth() const { return -1; }
  285. MatrixBandWidth ConstMatrix::BandWidth() const { return cgm->BandWidth(); }
  286. MatrixBandWidth ReturnMatrixX::BandWidth() const { return gm->BandWidth(); }
  287.  
  288. MatrixBandWidth GetSubMatrix::BandWidth() const
  289. {
  290.  
  291.    if (row_skip==col_skip && row_number==col_number) return gm->BandWidth();
  292.    else return MatrixBandWidth(-1);
  293. }
  294.  
  295. /************************ the memory managment tools **********************/
  296.  
  297. //  Rules regarding tDelete, reuse, GetStore
  298. //    All matrices processed during expression evaluation must be subject
  299. //    to exactly one of reuse(), tDelete(), GetStore() or BorrowStore().
  300. //    If reuse returns TRUE the matrix must be reused.
  301. //    GetMatrix(gm) always calls gm->GetStore()
  302. //    gm->Evaluate obeys rules
  303. //    bm->Evaluate obeys rules for matrices in bm structure
  304.  
  305. void GeneralMatrix::tDelete()
  306. {
  307.    if (tag<0)
  308.    {
  309.       if (tag<-1) { REPORT store=0; delete this; return; }  // borrowed
  310.       else { REPORT return; }
  311.    }
  312.    if (tag==1)
  313.    {
  314.       REPORT  MONITOR_REAL_DELETE("Free   (tDelete)",storage,store)
  315. #ifdef Version21
  316.       if (store) delete [] store;
  317. #else
  318.       if (store) delete [storage] store;
  319. #endif
  320.       store=0; tag=-1; return;
  321.    }
  322.    if (tag==0) { REPORT delete this; return; }
  323.    REPORT tag--; return;
  324. }
  325.  
  326. static void BlockCopy(int n, Real* from, Real* to)
  327. {
  328.    REPORT
  329.    int i = (n >> 3);
  330.    while (i--)
  331.    {
  332.       *to++ = *from++; *to++ = *from++; *to++ = *from++; *to++ = *from++;
  333.       *to++ = *from++; *to++ = *from++; *to++ = *from++; *to++ = *from++;
  334.    }
  335.    i = n & 7; while (i--) *to++ = *from++;
  336. }
  337.  
  338. Boolean GeneralMatrix::reuse()
  339. {
  340.    if (tag<-1)
  341.    {
  342.       REPORT
  343.       Real* s = new Real [storage]; MatrixErrorNoSpace(s);
  344.       MONITOR_REAL_NEW("Make     (reuse)",storage,s)
  345.       BlockCopy(storage, store, s); store=s; tag=0; return TRUE;
  346.    }
  347.    if (tag<0) { REPORT return FALSE; }
  348.    if (tag<=1)  { REPORT return TRUE; }
  349.    REPORT tag--; return FALSE;
  350. }
  351.  
  352. Real* GeneralMatrix::GetStore()
  353. {
  354.    if (tag<0 || tag>1)
  355.    {
  356.       Real* s;
  357.       if (storage)
  358.       {
  359.          s = new Real [storage]; MatrixErrorNoSpace(s);
  360.          MONITOR_REAL_NEW("Make  (GetStore)",storage,s)
  361.          BlockCopy(storage, store, s);
  362.       }
  363.       else s = 0;
  364.       if (tag>1) { REPORT tag--; }
  365.       else if (tag < -1) { REPORT store=0; delete this; } // borrowed store
  366.       else { REPORT }
  367.       return s;
  368.    }
  369.    Real* s=store; store=0;
  370.    if (tag==0) { REPORT delete this; }
  371.    else { REPORT tag=-1; }
  372.    return s;
  373. }
  374.  
  375. /*
  376. #ifndef __ZTC__
  377. void GeneralMatrix::GetMatrixC(const GeneralMatrix* gmx)
  378. {
  379.    REPORT tag=-1;
  380.    nrows=gmx->nrows; ncols=gmx->ncols; storage=gmx->storage;
  381.    SetParameters(gmx); 
  382.    store = new Real [storage]; MatrixErrorNoSpace(store);
  383.    MONITOR_REAL_NEW("Make (GetMatrix)",storage,store)
  384.    BlockCopy(storage, gmx->store, store);
  385. }
  386. #endif
  387. */
  388.  
  389. void GeneralMatrix::GetMatrix(const GeneralMatrix* gmx)
  390. {
  391.    REPORT  tag=-1; nrows=gmx->Nrows(); ncols=gmx->Ncols();
  392.    storage=gmx->storage; SetParameters(gmx);
  393.    store=((GeneralMatrix*)gmx)->GetStore();
  394. }
  395.  
  396. GeneralMatrix* GeneralMatrix::BorrowStore(GeneralMatrix* gmx, MatrixType mt)
  397. // Copy storage of *this to storage of *gmx. Then convert to type mt.
  398. // If mt == 0 just let *gmx point to storage of *this if tag==-1.
  399. {
  400.    if (!mt)
  401.    {
  402.       if (tag == -1) { REPORT gmx->tag = -2; gmx->store = store; }
  403.       else { REPORT gmx->tag = 0; gmx->store = GetStore(); }
  404.    }
  405.    else if (Compare(gmx->Type(),mt))
  406.    { REPORT  gmx->tag = 0; gmx->store = GetStore(); }
  407.    else
  408.    {
  409.       REPORT gmx->tag = -2; gmx->store = store;
  410.       gmx = gmx->Evaluate(mt); gmx->tag = 0; tDelete();
  411.    }
  412.  
  413.    return gmx;
  414. }
  415.  
  416. void GeneralMatrix::Eq(const BaseMatrix& X, MatrixType mt)
  417. // Count number of references to this in X.
  418. // If zero delete storage in X;
  419. // otherwise tag X to show when storage can be deleted
  420. // evaluate X and copy to current object
  421. {
  422.    int counter=X.search(this);
  423.    if (counter==0)
  424.    {
  425.       REPORT
  426.       if (store)
  427.       {
  428.          MONITOR_REAL_DELETE("Free (operator=)",storage,store)
  429. #ifdef Version21
  430.          REPORT delete [] store; storage=0;
  431. #else
  432.          REPORT delete [storage] store; storage=0;
  433. #endif
  434.       }
  435.    }
  436.    else { REPORT Release(counter); }
  437.    GeneralMatrix* gmx = ((BaseMatrix&)X).Evaluate(mt);
  438.    if (gmx!=this) { REPORT GetMatrix(gmx); }
  439.    else { REPORT }
  440.    Protect();
  441. }
  442.  
  443. void GeneralMatrix::Inject(const GeneralMatrix& X)
  444. // copy stored values of X; otherwise leave els of *this unchanged
  445. {
  446.    REPORT
  447.    Tracer tr("Inject");
  448.    if (nrows != X.nrows || ncols != X.ncols)
  449.       Throw(IncompatibleDimensionsException());
  450.    MatrixRow mr((GeneralMatrix*)&X, LoadOnEntry);
  451.    MatrixRow mrx(this, LoadOnEntry+StoreOnExit+DirectPart);
  452.    int i=nrows;
  453.    while (i--) { mrx.Inject(mr); mrx.Next(); mr.Next(); }
  454. }  
  455.  
  456. /*************** checking for data loss during conversion *******************/
  457.  
  458. //void GeneralMatrix::CheckConversion(const BaseMatrix& M)
  459. //{
  460. //   if (!(this->Type() >= M.Type()))
  461. //      Throw(ProgramException("Illegal Conversion"));
  462. //}
  463.  
  464. Boolean MatrixConversionCheck::DoCheck = FALSE;
  465.  
  466. void MatrixConversionCheck::DataLoss()
  467.    { if (DoCheck) Throw(ProgramException("Illegal Conversion")); }
  468.  
  469. Boolean Compare(const MatrixType& source, MatrixType& destination)
  470. {
  471.    if (!destination) { destination=source; return TRUE; }
  472.    if (destination==source) return TRUE;
  473.    if (MatrixConversionCheck::IsOn() && !(destination>=source))
  474.       Throw(ProgramException("Illegal Conversion"));
  475.    return FALSE;
  476. }
  477.  
  478. /*************** Make a copy of a matrix on the heap *********************/
  479.  
  480. GeneralMatrix* Matrix::Image() const
  481. {
  482.    REPORT
  483.    GeneralMatrix* gm = new Matrix(*this); MatrixErrorNoSpace(gm);
  484.    return gm;
  485. }
  486.  
  487. GeneralMatrix* SymmetricMatrix::Image() const
  488. {
  489.    REPORT
  490.    GeneralMatrix* gm = new SymmetricMatrix(*this); MatrixErrorNoSpace(gm);
  491.    return gm;
  492. }
  493.  
  494. GeneralMatrix* UpperTriangularMatrix::Image() const
  495. {
  496.    REPORT
  497.    GeneralMatrix* gm = new UpperTriangularMatrix(*this);
  498.    MatrixErrorNoSpace(gm); return gm;
  499. }
  500.  
  501. GeneralMatrix* LowerTriangularMatrix::Image() const
  502. {
  503.    REPORT
  504.    GeneralMatrix* gm = new LowerTriangularMatrix(*this);
  505.    MatrixErrorNoSpace(gm); return gm;
  506. }
  507.  
  508. GeneralMatrix* DiagonalMatrix::Image() const
  509. {
  510.    REPORT
  511.    GeneralMatrix* gm = new DiagonalMatrix(*this); MatrixErrorNoSpace(gm);
  512.    return gm;
  513. }
  514.  
  515. GeneralMatrix* RowVector::Image() const
  516. {
  517.    REPORT
  518.    GeneralMatrix* gm = new RowVector(*this); MatrixErrorNoSpace(gm);
  519.    return gm;
  520. }
  521.  
  522. GeneralMatrix* ColumnVector::Image() const
  523. {
  524.    REPORT
  525.    GeneralMatrix* gm = new ColumnVector(*this); MatrixErrorNoSpace(gm);
  526.    return gm;
  527. }
  528.  
  529. GeneralMatrix* BandMatrix::Image() const
  530. {
  531.    REPORT
  532.    GeneralMatrix* gm = new BandMatrix(*this); MatrixErrorNoSpace(gm);
  533.    return gm;
  534. }
  535.  
  536. GeneralMatrix* UpperBandMatrix::Image() const
  537. {
  538.    REPORT
  539.    GeneralMatrix* gm = new UpperBandMatrix(*this); MatrixErrorNoSpace(gm);
  540.    return gm;
  541. }
  542.  
  543. GeneralMatrix* LowerBandMatrix::Image() const
  544. {
  545.    REPORT
  546.    GeneralMatrix* gm = new LowerBandMatrix(*this); MatrixErrorNoSpace(gm);
  547.    return gm;
  548. }
  549.  
  550. GeneralMatrix* SymmetricBandMatrix::Image() const
  551. {
  552.    REPORT
  553.    GeneralMatrix* gm = new SymmetricBandMatrix(*this); MatrixErrorNoSpace(gm);
  554.    return gm;
  555. }
  556.  
  557. GeneralMatrix* nricMatrix::Image() const
  558. {
  559.    REPORT
  560.    GeneralMatrix* gm = new nricMatrix(*this); MatrixErrorNoSpace(gm);
  561.    return gm;
  562. }
  563.  
  564. GeneralMatrix* GeneralMatrix::Image() const
  565. {
  566.    REPORT
  567.    Throw(InternalException("Cannot apply Image to this matrix type"));
  568.    return 0;
  569. }
  570.  
  571.  
  572. /************************* nricMatrix routines *****************************/
  573.  
  574. void nricMatrix::MakeRowPointer()
  575. {
  576.    row_pointer = new Real* [nrows]; MatrixErrorNoSpace(row_pointer);
  577.    Real* s = Store() - 1; int i = nrows; Real** rp = row_pointer;
  578.    while (i--) { *rp++ = s; s+=ncols; }
  579. }
  580.  
  581. void nricMatrix::DeleteRowPointer()
  582. #ifdef Version21
  583. { if (nrows) delete [] row_pointer; }
  584. #else
  585. { if (nrows) delete [nrows] row_pointer; }
  586. #endif
  587.  
  588. void GeneralMatrix::CheckStore() const
  589. {
  590.    if (!store) 
  591.       Throw(ProgramException("NRIC accessing matrix with unset dimensions"));
  592. }
  593.  
  594.  
  595. /***************************** CleanUp routines *****************************/
  596.  
  597. void GeneralMatrix::CleanUp()
  598. {
  599.    // set matrix dimensions to zero, delete storage
  600.    REPORT
  601.    if (store && storage)
  602.    {
  603.       MONITOR_REAL_DELETE("Free (CleanUp)    ",storage,store)
  604. #ifdef Version21
  605.          REPORT delete [] store;
  606. #else
  607.          REPORT delete [storage] store;
  608. #endif
  609.    }
  610.    store=0; storage=0; nrows=0; ncols=0;
  611. }
  612.  
  613. void nricMatrix::CleanUp()
  614. { DeleteRowPointer(); GeneralMatrix::CleanUp(); }
  615.  
  616. void RowVector::CleanUp()
  617. { GeneralMatrix::CleanUp(); nrows=1; }
  618.  
  619. void ColumnVector::CleanUp()
  620. { GeneralMatrix::CleanUp(); ncols=1; }
  621.  
  622. void CroutMatrix::CleanUp()
  623. #ifdef Version21
  624.    if (nrows) delete [] indx;
  625. #else
  626.    if (nrows) delete [nrows] indx;
  627. #endif
  628.    GeneralMatrix::CleanUp();
  629. }
  630.  
  631. void BandLUMatrix::CleanUp()
  632. #ifdef Version21
  633.    if (nrows) delete [] indx;
  634.    if (storage2) delete [] store2;
  635. #else
  636.    if (nrows) delete [nrows] indx;
  637.    if (storage2) delete [storage2] store2;
  638. #endif
  639.    GeneralMatrix::CleanUp();
  640. }
  641.  
  642.  
  643.