OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
newmat4.cpp
Go to the documentation of this file.
1 //$$ newmat4.cpp Constructors, ReSize, basic utilities
2 
3 // Copyright (C) 1991,2,3,4,8,9: R B Davies
4 
5 #include <ossim/matrix/include.h>
6 
7 #include <ossim/matrix/newmat.h>
9 
10 #ifdef use_namespace
11 namespace NEWMAT {
12 #endif
13 
14 
15 
16 #ifdef DO_REPORT
17 #define REPORT { static ExeCounter ExeCount(__LINE__,4); ++ExeCount; }
18 #else
19 #define REPORT {}
20 #endif
21 
22 
23 #define DO_SEARCH // search for LHS of = in RHS
24 
25 // ************************* general utilities *************************/
26 
27 static int tristore(int n) // elements in triangular matrix
28 { return (n*(n+1))/2; }
29 
30 
31 // **************************** constructors ***************************/
32 
34 { store=0; storage=0; nrows=0; ncols=0; tag=-1; }
35 
37 {
38  REPORT
39  storage=s.Value(); tag=-1;
40  if (storage)
41  {
42  store = new Real [storage]; MatrixErrorNoSpace(store);
43  MONITOR_REAL_NEW("Make (GenMatrix)",storage,store)
44  }
45  else store = 0;
46 }
47 
48 Matrix::Matrix(int m, int n) : GeneralMatrix(m*n)
49 { REPORT nrows=m; ncols=n; }
50 
52  : Matrix(n.Value(),n.Value())
53 { REPORT }
54 
56  : GeneralMatrix(tristore(n.Value()))
57 { REPORT nrows=n.Value(); ncols=n.Value(); }
58 
60  : GeneralMatrix(tristore(n.Value()))
61 { REPORT nrows=n.Value(); ncols=n.Value(); }
62 
64  : GeneralMatrix(tristore(n.Value()))
65 { REPORT nrows=n.Value(); ncols=n.Value(); }
66 
68 { REPORT nrows=m.Value(); ncols=m.Value(); }
69 
71 {
72  REPORT // CheckConversion(M);
73  // MatrixConversionCheck mcc;
75  GetMatrix(gmx);
76 }
77 
79 {
80  REPORT
81  if (ncols != nrows)
82  {
83  Tracer tr("SquareMatrix");
84  Throw(NotSquareException(*this));
85  }
86 }
87 
88 
90 {
91  REPORT
92  if (gm.ncols != gm.nrows)
93  {
94  Tracer tr("SquareMatrix(Matrix)");
95  Throw(NotSquareException(gm));
96  }
97  GetMatrix(&gm);
98 }
99 
100 
102 {
103  REPORT
104  if (nrows!=1)
105  {
106  Tracer tr("RowVector");
107  Throw(VectorException(*this));
108  }
109 }
110 
112 {
113  REPORT
114  if (ncols!=1)
115  {
116  Tracer tr("ColumnVector");
117  Throw(VectorException(*this));
118  }
119 }
120 
122 {
123  REPORT // CheckConversion(M);
124  // MatrixConversionCheck mcc;
126  GetMatrix(gmx);
127 }
128 
130 {
131  REPORT // CheckConversion(M);
132  // MatrixConversionCheck mcc;
134  GetMatrix(gmx);
135 }
136 
138 {
139  REPORT // CheckConversion(M);
140  // MatrixConversionCheck mcc;
142  GetMatrix(gmx);
143 }
144 
146 {
147  REPORT //CheckConversion(M);
148  // MatrixConversionCheck mcc;
150  GetMatrix(gmx);
151 }
152 
154 {
155  REPORT //CheckConversion(M);
156  // MatrixConversionCheck mcc;
158  GetMatrix(gmx);
159 }
160 
162 {
163  if (store)
164  {
165  MONITOR_REAL_DELETE("Free (GenMatrix)",storage,store)
166  delete [] store;
167  }
168 }
169 
171 {
172  REPORT
173  Tracer tr("CroutMatrix");
174  indx = 0; // in case of exception at next line
176  GetMatrix(gm);
177  if (nrows!=ncols) { CleanUp(); Throw(NotSquareException(*gm)); }
178  d=true; sing=false;
179  indx=new int [nrows]; MatrixErrorNoSpace(indx);
180  MONITOR_INT_NEW("Index (CroutMat)",nrows,indx)
181  ludcmp();
182 }
183 
185 {
186  MONITOR_INT_DELETE("Index (CroutMat)",nrows,indx)
187  delete [] indx;
188 }
189 
190 //ReturnMatrix::ReturnMatrix(GeneralMatrix& gmx)
191 //{
192 // REPORT
193 // gm = gmx.Image(); gm->ReleaseAndDelete();
194 //}
195 
196 
197 GeneralMatrix::operator ReturnMatrix() const
198 {
199  REPORT
200  GeneralMatrix* gm = Image(); gm->ReleaseAndDelete();
201  return ReturnMatrix(gm);
202 }
203 
204 
205 
207 {
208  REPORT
209  GeneralMatrix* gm = Image(); gm->ReleaseAndDelete();
210  return ReturnMatrix(gm);
211 }
212 
213 
214 // ************************** ReSize matrices ***************************/
215 
216 void GeneralMatrix::ReSize(int nr, int nc, int s)
217 {
218  REPORT
219  if (store)
220  {
221  MONITOR_REAL_DELETE("Free (ReDimensi)",storage,store)
222  delete [] store;
223  }
224  storage=s; nrows=nr; ncols=nc; tag=-1;
225  if (s)
226  {
228  MONITOR_REAL_NEW("Make (ReDimensi)",storage,store)
229  }
230  else store = 0;
231 }
232 
233 void Matrix::ReSize(int nr, int nc)
234 { REPORT GeneralMatrix::ReSize(nr,nc,nr*nc); }
235 
238 
239 void SquareMatrix::ReSize(int nr, int nc)
240 {
241  REPORT
242  Tracer tr("SquareMatrix::ReSize");
243  if (nc != nr) Throw(NotSquareException(*this));
244  GeneralMatrix::ReSize(nr,nc,nr*nc);
245 }
246 
248 { REPORT GeneralMatrix::ReSize(nr,nr,tristore(nr)); }
249 
251 { REPORT GeneralMatrix::ReSize(nr,nr,tristore(nr)); }
252 
254 { REPORT GeneralMatrix::ReSize(nr,nr,tristore(nr)); }
255 
257 { REPORT GeneralMatrix::ReSize(nr,nr,nr); }
258 
259 void RowVector::ReSize(int nc)
260 { REPORT GeneralMatrix::ReSize(1,nc,nc); }
261 
263 { REPORT GeneralMatrix::ReSize(nr,1,nr); }
264 
265 void RowVector::ReSize(int nr, int nc)
266 {
267  Tracer tr("RowVector::ReSize");
268  if (nr != 1) Throw(VectorException(*this));
269  REPORT GeneralMatrix::ReSize(1,nc,nc);
270 }
271 
272 void ColumnVector::ReSize(int nr, int nc)
273 {
274  Tracer tr("ColumnVector::ReSize");
275  if (nc != 1) Throw(VectorException(*this));
276  REPORT GeneralMatrix::ReSize(nr,1,nr);
277 }
278 
280 { REPORT GeneralMatrix::ReSize(nr,nr,1); *store = 1; }
281 
282 
284 { REPORT ReSize(A.Nrows(), A.Ncols()); }
285 
287 {
288  REPORT
289  int n = A.Nrows();
290  if (n != A.Ncols())
291  {
292  Tracer tr("SquareMatrix::ReSize(GM)");
293  Throw(NotSquareException(*this));
294  }
295  ReSize(n);
296 }
297 
299 { REPORT ReSize(A.Nrows(), A.Ncols()); }
300 
302 { REPORT ReSize(A.Nrows(), A.Ncols()); }
303 
305 { REPORT ReSize(A.Nrows(), A.Ncols()); }
306 
308 {
309  REPORT
310  int n = A.Nrows();
311  if (n != A.Ncols())
312  {
313  Tracer tr("SymmetricMatrix::ReSize(GM)");
314  Throw(NotSquareException(*this));
315  }
316  ReSize(n);
317 }
318 
320 {
321  REPORT
322  int n = A.Nrows();
323  if (n != A.Ncols())
324  {
325  Tracer tr("DiagonalMatrix::ReSize(GM)");
326  Throw(NotSquareException(*this));
327  }
328  ReSize(n);
329 }
330 
332 {
333  REPORT
334  int n = A.Nrows();
335  if (n != A.Ncols())
336  {
337  Tracer tr("UpperTriangularMatrix::ReSize(GM)");
338  Throw(NotSquareException(*this));
339  }
340  ReSize(n);
341 }
342 
344 {
345  REPORT
346  int n = A.Nrows();
347  if (n != A.Ncols())
348  {
349  Tracer tr("LowerTriangularMatrix::ReSize(GM)");
350  Throw(NotSquareException(*this));
351  }
352  ReSize(n);
353 }
354 
356 {
357  REPORT
358  int n = A.Nrows();
359  if (n != A.Ncols())
360  {
361  Tracer tr("IdentityMatrix::ReSize(GM)");
362  Throw(NotSquareException(*this));
363  }
364  ReSize(n);
365 }
366 
368 {
369  REPORT
370  Tracer tr("GeneralMatrix::ReSize(GM)");
371  Throw(NotDefinedException("ReSize", "this type of matrix"));
372 }
373 
375 { REPORT ReSize(A); }
376 
378 { REPORT ReSize(A); }
379 
380 
381 // ************************* SameStorageType ******************************/
382 
383 // SameStorageType checks A and B have same storage type including bandwidth
384 // It does not check same dimensions since we assume this is already done
385 
387 {
388  REPORT
389  return Type() == A.Type();
390 }
391 
392 
393 // ******************* manipulate types, storage **************************/
394 
396 { REPORT return (s==this) ? 1 : 0; }
397 
399 { REPORT return gm->search(s); }
400 
402 { REPORT return bm1->search(s) + bm2->search(s); }
403 
405 { REPORT return bm->search(s); }
406 
408 { REPORT return bm->search(s); }
409 
410 int ReturnMatrix::search(const BaseMatrix* s) const
411 { REPORT return (s==gm) ? 1 : 0; }
412 
426 
428 
429 
430 
434 
436  { REPORT return MatrixBandWidth(0,-1); }
437 
439  { REPORT return MatrixBandWidth(-1,0); }
440 
442  { REPORT return MatrixBandWidth(lower,upper); }
443 
445  { REPORT return gm->BandWidth(); }
446 
448  { REPORT return gm1->BandWidth() + gm2->BandWidth(); }
449 
451  { REPORT return gm1->BandWidth().minimum(gm2->BandWidth()); }
452 
454 {
455  int lower, upper;
456  MatrixBandWidth bw1 = gm1->BandWidth(), bw2 = gm2->BandWidth();
457  if (bw1.Lower() < 0)
458  {
459  if (bw2.Lower() < 0) { REPORT lower = -1; }
460  else { REPORT lower = bw2.Lower() + (gm1->Nrows() - 1) * gm2->Nrows(); }
461  }
462  else
463  {
464  if (bw2.Lower() < 0)
465  { REPORT lower = (1 + bw1.Lower()) * gm2->Nrows() - 1; }
466  else { REPORT lower = bw2.Lower() + bw1.Lower() * gm2->Nrows(); }
467  }
468  if (bw1.Upper() < 0)
469  {
470  if (bw2.Upper() < 0) { REPORT upper = -1; }
471  else { REPORT upper = bw2.Upper() + (gm1->Nrows() - 1) * gm2->Nrows(); }
472  }
473  else
474  {
475  if (bw2.Upper() < 0)
476  { REPORT upper = (1 + bw1.Upper()) * gm2->Nrows() - 1; }
477  else { REPORT upper = bw2.Upper() + bw1.Upper() * gm2->Nrows(); }
478  }
479  return MatrixBandWidth(lower, upper);
480 }
481 
483 { REPORT return gm1->BandWidth() * gm2->BandWidth(); }
484 
486 
488 {
489  if (+gm1->Type() & MatrixType::Diagonal)
490  { REPORT return gm2->BandWidth(); }
491  else { REPORT return -1; }
492 }
493 
495  { REPORT return gm->BandWidth(); }
496 
498  { REPORT return gm->BandWidth(); }
499 
501  { REPORT return gm->BandWidth().t(); }
502 
504 {
505  if (+gm->Type() & MatrixType::Diagonal)
506  { REPORT return MatrixBandWidth(0,0); }
507  else { REPORT return -1; }
508 }
509 
515  { REPORT return gm->BandWidth(); }
516 
518 {
519 
521  { REPORT return gm->BandWidth(); }
522  else { REPORT return MatrixBandWidth(-1); }
523 }
524 
525 // ********************** the memory managment tools **********************/
526 
527 // Rules regarding tDelete, reuse, GetStore, BorrowStore
528 // All matrices processed during expression evaluation must be subject
529 // to exactly one of reuse(), tDelete(), GetStore() or BorrowStore().
530 // If reuse returns true the matrix must be reused.
531 // GetMatrix(gm) always calls gm->GetStore()
532 // gm->Evaluate obeys rules
533 // bm->Evaluate obeys rules for matrices in bm structure
534 
536 {
537  if (tag<0)
538  {
539  if (tag<-1) { REPORT store = 0; delete this; return; } // borrowed
540  else { REPORT return; } // not a temporary matrix - leave alone
541  }
542  if (tag==1)
543  {
544  if (store)
545  {
546  REPORT MONITOR_REAL_DELETE("Free (tDelete)",storage,store)
547  delete [] store;
548  }
549  MiniCleanUp(); return; // CleanUp
550  }
551  if (tag==0) { REPORT delete this; return; }
552 
553  REPORT tag--; return;
554 }
555 
556 static void BlockCopy(int n, Real* from, Real* to)
557 {
558  REPORT
559  int i = (n >> 3);
560  while (i--)
561  {
562  *to++ = *from++; *to++ = *from++; *to++ = *from++; *to++ = *from++;
563  *to++ = *from++; *to++ = *from++; *to++ = *from++; *to++ = *from++;
564  }
565  i = n & 7; while (i--) *to++ = *from++;
566 }
567 
569 {
570  if (tag < -1) // borrowed storage
571  {
572  if (storage)
573  {
574  REPORT
575  Real* s = new Real [storage]; MatrixErrorNoSpace(s);
576  MONITOR_REAL_NEW("Make (reuse)",storage,s)
577  BlockCopy(storage, store, s); store = s;
578  }
579  else { REPORT MiniCleanUp(); } // CleanUp
580  tag = 0; return true;
581  }
582  if (tag < 0 ) { REPORT return false; }
583  if (tag <= 1 ) { REPORT return true; }
584  REPORT tag--; return false;
585 }
586 
588 {
589  if (tag<0 || tag>1)
590  {
591  Real* s;
592  if (storage)
593  {
594  s = new Real [storage]; MatrixErrorNoSpace(s);
595  MONITOR_REAL_NEW("Make (GetStore)",storage,s)
596  BlockCopy(storage, store, s);
597  }
598  else s = 0;
599  if (tag > 1) { REPORT tag--; }
600  else if (tag < -1) { REPORT store = 0; delete this; } // borrowed store
601  else { REPORT }
602  return s;
603  }
604  Real* s = store; // CleanUp - done later
605  if (tag==0) { REPORT store = 0; delete this; }
606  else { REPORT MiniCleanUp(); }
607  return s;
608 }
609 
611 {
612  REPORT tag=-1; nrows=gmx->Nrows(); ncols=gmx->Ncols();
613  storage=gmx->storage; SetParameters(gmx);
614  store=((GeneralMatrix*)gmx)->GetStore();
615 }
616 
618 // Copy storage of *this to storage of *gmx. Then convert to type mt.
619 // If mt == 0 just let *gmx point to storage of *this if tag==-1.
620 {
621  if (!mt)
622  {
623  if (tag == -1) { REPORT gmx->tag = -2; gmx->store = store; }
624  else { REPORT gmx->tag = 0; gmx->store = GetStore(); }
625  }
626  else if (Compare(gmx->Type(),mt))
627  { REPORT gmx->tag = 0; gmx->store = GetStore(); }
628  else
629  {
630  REPORT gmx->tag = -2; gmx->store = store;
631  gmx = gmx->Evaluate(mt); gmx->tag = 0; tDelete();
632  }
633 
634  return gmx;
635 }
636 
638 // Count number of references to this in X.
639 // If zero delete storage in this;
640 // otherwise tag this to show when storage can be deleted
641 // evaluate X and copy to this
642 {
643 #ifdef DO_SEARCH
644  int counter=X.search(this);
645  if (counter==0)
646  {
647  REPORT
648  if (store)
649  {
650  MONITOR_REAL_DELETE("Free (operator=)",storage,store)
651  REPORT delete [] store; storage = 0; store = 0;
652  }
653  }
654  else { REPORT Release(counter); }
655  GeneralMatrix* gmx = ((BaseMatrix&)X).Evaluate(mt);
656  if (gmx!=this) { REPORT GetMatrix(gmx); }
657  else { REPORT }
658  Protect();
659 #else
660  GeneralMatrix* gmx = ((BaseMatrix&)X).Evaluate(mt);
661  if (gmx!=this)
662  {
663  REPORT
664  if (store)
665  {
666  MONITOR_REAL_DELETE("Free (operator=)",storage,store)
667  REPORT delete [] store; storage = 0; store = 0;
668  }
669  GetMatrix(gmx);
670  }
671  else { REPORT }
672  Protect();
673 #endif
674 }
675 
676 // version with no conversion
678 {
679  GeneralMatrix* gmx = (GeneralMatrix*)&X;
680  if (gmx!=this)
681  {
682  REPORT
683  if (store)
684  {
685  MONITOR_REAL_DELETE("Free (operator=)",storage,store)
686  REPORT delete [] store; storage = 0; store = 0;
687  }
688  GetMatrix(gmx);
689  }
690  else { REPORT }
691  Protect();
692 }
693 
694 // version to work with operator<<
695 void GeneralMatrix::Eq(const BaseMatrix& X, MatrixType mt, bool ldok)
696 {
697  REPORT
698  if (ldok) mt.SetDataLossOK();
699  Eq(X, mt);
700 }
701 
703 // a cut down version of Eq for use with += etc.
704 // we know BaseMatrix points to two GeneralMatrix objects,
705 // the first being this (may be the same).
706 // we know tag has been set correctly in each.
707 {
708  GeneralMatrix* gmx = ((BaseMatrix&)X).Evaluate(mt);
709  if (gmx!=this) { REPORT GetMatrix(gmx); } // simplify GetMatrix ?
710  else { REPORT }
711  Protect();
712 }
713 
715 // copy stored values of X; otherwise leave els of *this unchanged
716 {
717  REPORT
718  Tracer tr("Inject");
719  if (nrows != X.nrows || ncols != X.ncols)
723  int i=nrows;
724  while (i--) { mrx.Inject(mr); mrx.Next(); mr.Next(); }
725 }
726 
727 // ************* checking for data loss during conversion *******************/
728 
729 bool Compare(const MatrixType& source, MatrixType& destination)
730 {
731  if (!destination) { destination=source; return true; }
732  if (destination==source) return true;
733  if (!destination.DataLossOK && !(destination>=source))
734  Throw(ProgramException("Illegal Conversion", source, destination));
735  return false;
736 }
737 
738 // ************* Make a copy of a matrix on the heap *********************/
739 
741 {
742  REPORT
743  GeneralMatrix* gm = new Matrix(*this); MatrixErrorNoSpace(gm);
744  return gm;
745 }
746 
748 {
749  REPORT
750  GeneralMatrix* gm = new SquareMatrix(*this); MatrixErrorNoSpace(gm);
751  return gm;
752 }
753 
755 {
756  REPORT
757  GeneralMatrix* gm = new SymmetricMatrix(*this); MatrixErrorNoSpace(gm);
758  return gm;
759 }
760 
762 {
763  REPORT
764  GeneralMatrix* gm = new UpperTriangularMatrix(*this);
765  MatrixErrorNoSpace(gm); return gm;
766 }
767 
769 {
770  REPORT
771  GeneralMatrix* gm = new LowerTriangularMatrix(*this);
772  MatrixErrorNoSpace(gm); return gm;
773 }
774 
776 {
777  REPORT
778  GeneralMatrix* gm = new DiagonalMatrix(*this); MatrixErrorNoSpace(gm);
779  return gm;
780 }
781 
783 {
784  REPORT
785  GeneralMatrix* gm = new RowVector(*this); MatrixErrorNoSpace(gm);
786  return gm;
787 }
788 
790 {
791  REPORT
792  GeneralMatrix* gm = new ColumnVector(*this); MatrixErrorNoSpace(gm);
793  return gm;
794 }
795 
797 {
798  REPORT
799  GeneralMatrix* gm = new BandMatrix(*this); MatrixErrorNoSpace(gm);
800  return gm;
801 }
802 
804 {
805  REPORT
806  GeneralMatrix* gm = new UpperBandMatrix(*this); MatrixErrorNoSpace(gm);
807  return gm;
808 }
809 
811 {
812  REPORT
813  GeneralMatrix* gm = new LowerBandMatrix(*this); MatrixErrorNoSpace(gm);
814  return gm;
815 }
816 
818 {
819  REPORT
821  return gm;
822 }
823 
825 {
826  REPORT
827  GeneralMatrix* gm = new nricMatrix(*this); MatrixErrorNoSpace(gm);
828  return gm;
829 }
830 
832 {
833  REPORT
834  GeneralMatrix* gm = new IdentityMatrix(*this); MatrixErrorNoSpace(gm);
835  return gm;
836 }
837 
839 {
840  // bool dummy = true;
841  // if (dummy) // get rid of warning message
842  Throw(InternalException("Cannot apply Image to this matrix type"));
843  return 0;
844 }
845 
846 
847 // *********************** nricMatrix routines *****************************/
848 
850 {
851  REPORT
852  if (nrows > 0)
853  {
855  Real* s = Store() - 1; int i = nrows; Real** rp = row_pointer;
856  if (i) for (;;) { *rp++ = s; if (!(--i)) break; s+=ncols; }
857  }
858  else row_pointer = 0;
859 }
860 
862  { REPORT if (nrows) delete [] row_pointer; }
863 
865 {
866  REPORT
867  if (!store)
868  Throw(ProgramException("NRIC accessing matrix with unset dimensions"));
869 }
870 
871 
872 // *************************** CleanUp routines *****************************/
873 
875 {
876  // set matrix dimensions to zero, delete storage
877  REPORT
878  if (store && storage)
879  {
880  MONITOR_REAL_DELETE("Free (CleanUp) ",storage,store)
881  REPORT delete [] store;
882  }
883  store=0; storage=0; nrows=0; ncols=0; tag = -1;
884 }
885 
888 
891 
894 
897 
899 {
900  REPORT
901  if (nrows) delete [] indx;
903 }
904 
906 {
907  REPORT
908  if (nrows) delete [] indx;
910 }
911 
913 {
914  REPORT
915  if (nrows) delete [] indx;
916  if (storage2) delete [] store2;
918 }
919 
921 {
922  REPORT
923  if (nrows) delete [] indx;
924  if (storage2) delete [] store2;
926 }
927 
928 // ************************ simple integer array class ***********************
929 
930 // construct a new array of length xn. Check that xn is non-negative and
931 // that space is available
932 
934 {
935  if (n < 0) Throw(Logic_error("invalid array length"));
936  else if (n == 0) { REPORT a = 0; }
937  else { REPORT a = new int [n]; if (!a) Throw(Bad_alloc()); }
938 }
939 
940 // destroy an array - return its space to memory
941 
943 
944 // access an element of an array; return a "reference" so elements
945 // can be modified.
946 // check index is within range
947 // in this array class the index runs from 0 to n-1
948 
950 {
951  REPORT
952  if (i < 0 || i >= n) Throw(Logic_error("array index out of range"));
953  return a[i];
954 }
955 
956 // same thing again but for arrays declared constant so we can't
957 // modify its elements
958 
960 {
961  REPORT
962  if (i < 0 || i >= n) Throw(Logic_error("array index out of range"));
963  return a[i];
964 }
965 
966 // set all the elements equal to a given value
967 
969  { REPORT for (int i = 0; i < n; i++) a[i] = ai; }
970 
971 // set the elements equal to those of another array.
972 // check the arrays are of the same length
973 
975 {
976  REPORT
977  if (b.n != n) Throw(Logic_error("array lengths differ in copy"));
978  for (int i = 0; i < n; i++) a[i] = b.a[i];
979 }
980 
981 // construct a new array equal to an existing array
982 // check that space is available
983 
985 {
986  if (n == 0) { REPORT a = 0; }
987  else
988  {
989  REPORT
990  a = new int [n]; if (!a) Throw(Bad_alloc());
991  for (int i = 0; i < n; i++) a[i] = b.a[i];
992  }
993 }
994 
995 // change the size of an array; optionally copy data from old array to
996 // new array
997 
998 void SimpleIntArray::ReSize(int n1, bool keep)
999 {
1000  if (n1 == n) { REPORT return; }
1001  else if (n1 == 0) { REPORT n = 0; delete [] a; a = 0; }
1002  else if (n == 0)
1003  { REPORT a = new int [n1]; if (!a) Throw(Bad_alloc()); n = n1; }
1004  else
1005  {
1006  int* a1 = a;
1007  if (keep)
1008  {
1009  REPORT
1010  a = new int [n1]; if (!a) Throw(Bad_alloc());
1011  if (n > n1) n = n1;
1012  for (int i = 0; i < n; i++) a[i] = a1[i];
1013  n = n1; delete [] a1;
1014  }
1015  else
1016  {
1017  REPORT n = n1; delete [] a1;
1018  a = new int [n]; if (!a) Throw(Bad_alloc());
1019  }
1020  }
1021 }
1022 
1023 
1024 #ifdef use_namespace
1025 }
1026 #endif
1027 
GeneralMatrix * Image() const
Definition: newmat4.cpp:775
const BaseMatrix * bm
Definition: newmat.h:1393
MatrixType Type() const
Definition: newmat4.cpp:420
double Real
Definition: include.h:57
MatrixType Type() const
Definition: newmat4.cpp:424
void MakeRowPointer()
Definition: newmat4.cpp:849
Real * GetStore()
Definition: newmat4.cpp:587
void ludcmp()
Definition: newmat8.cpp:27
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:487
MatrixType Type() const
Definition: newmat4.cpp:421
void ReSize(int)
Definition: newmat4.cpp:259
GeneralMatrix * Image() const
Definition: newmat4.cpp:796
void Release()
Definition: newmat.h:440
void tDelete()
Definition: newmat4.cpp:535
int lower
Definition: newmat.h:936
void MiniCleanUp()
Definition: newmat4.cpp:920
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:511
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:450
void operator=(int ai)
Definition: newmat4.cpp:968
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:485
#define MONITOR_INT_DELETE(Operation, Size, Pointer)
Definition: myexcept.h:320
void CheckStore() const
Definition: newmat4.cpp:864
ReturnMatrix ForReturn() const
Definition: newmat4.cpp:206
MatrixBandWidth t() const
Definition: newmat.h:199
Matrix()
Definition: newmat.h:547
void ReSize(int)
Definition: newmat4.cpp:236
GeneralMatrix * Image() const
Definition: newmat4.cpp:754
MatrixType Type() const
Definition: newmat4.cpp:419
GeneralMatrix * Image() const
Definition: newmat4.cpp:803
const BaseMatrix * bm2
Definition: newmat.h:1222
GeneralMatrix * Image() const
Definition: newmat4.cpp:768
virtual int search(const BaseMatrix *) const =0
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:435
InvertedMatrix i() const
Definition: newmat6.cpp:325
int search(const BaseMatrix *) const
Definition: newmat4.cpp:401
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:494
virtual void ReSizeForSP(const GeneralMatrix &A, const GeneralMatrix &B)
Definition: newmat4.cpp:377
GeneralMatrix * Image() const
Definition: newmat4.cpp:817
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:438
int search(const BaseMatrix *) const
Definition: newmat4.cpp:404
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:513
ColumnVector()
Definition: newmat.h:869
nricMatrix()
Definition: newmat.h:623
void DeleteRowPointer()
Definition: newmat4.cpp:861
GeneralMatrix * gm
Definition: newmat.h:1185
MatrixType Type() const
Definition: newmat4.cpp:427
virtual bool SameStorageType(const GeneralMatrix &A) const
Definition: newmat4.cpp:386
SimpleIntArray(int xn)
Definition: newmat4.cpp:933
virtual MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:431
virtual void MiniCleanUp()
Definition: newmat.h:421
int search(const BaseMatrix *) const
Definition: newmat4.cpp:395
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:433
MatrixType Type() const
Definition: newmat4.cpp:415
int Ncols() const
Definition: newmat.h:431
void MiniCleanUp()
Definition: newmat4.cpp:905
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:514
GeneralMatrix * Evaluate(MatrixType mt=MatrixTypeUnSp)
Definition: newmat5.cpp:79
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:497
void Eq2(const BaseMatrix &, MatrixType)
Definition: newmat4.cpp:702
void CleanUp()
Definition: newmat4.cpp:874
#define A(r, c)
BandMatrix()
Definition: newmat.h:937
bool sing
Definition: newmat.h:906
bool Compare(const MatrixType &source, MatrixType &destination)
Definition: newmat4.cpp:729
void ReSize(int)
Definition: newmat4.cpp:247
int search(const BaseMatrix *bm) const
Definition: newmat4.cpp:398
GeneralMatrix * gm
Definition: newmat.h:1393
const BaseMatrix * bm
Definition: newmat.h:1348
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:444
int col_number
Definition: newmat.h:1508
#define MONITOR_INT_NEW(Operation, Size, Pointer)
Definition: myexcept.h:318
int row_skip
Definition: newmat.h:1505
SquareMatrix()
Definition: newmat.h:593
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:500
int row_number
Definition: newmat.h:1506
void MatrixErrorNoSpace(const void *)
Definition: newmatex.cpp:292
virtual void ReSize(int, int)
Definition: newmat4.cpp:233
MatrixType Type() const
Definition: newmat4.cpp:418
GeneralMatrix * Image() const
Definition: newmat4.cpp:747
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:512
int Lower() const
Definition: newmat.h:204
MatrixType Type() const
Definition: newmat4.cpp:414
#define REPORT
Definition: newmat4.cpp:19
bool reuse()
Definition: newmat4.cpp:568
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:432
void CleanUp()
Definition: newmat4.cpp:886
CroutMatrix(const BaseMatrix &)
Definition: newmat4.cpp:170
GeneralMatrix * Image() const
Definition: newmat4.cpp:824
os2<< "> n<< " > nendobj n
int storage2
Definition: newmat.h:1118
GeneralMatrix * Image() const
Definition: newmat4.cpp:782
#define MONITOR_REAL_DELETE(Operation, Size, Pointer)
Definition: myexcept.h:319
void MiniCleanUp()
Definition: newmat4.cpp:889
int Value() const
Definition: newmat.h:219
GeneralMatrix * gm
Definition: newmat.h:1487
MatrixType Type() const
Definition: newmat4.cpp:416
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:517
MatrixType Type() const
Definition: newmat4.cpp:422
int search(const BaseMatrix *) const
Definition: newmat4.cpp:407
virtual void ReSizeForAdd(const GeneralMatrix &A, const GeneralMatrix &B)
Definition: newmat4.cpp:374
int * indx
Definition: newmat.h:1114
bool DataLossOK
Definition: newmat.h:132
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:441
void CleanUp()
Definition: newmat4.cpp:912
void Eq(const BaseMatrix &, MatrixType)
Definition: newmat4.cpp:637
Definition: newmat.h:543
Real * store
Definition: newmat.h:393
#define MONITOR_REAL_NEW(Operation, Size, Pointer)
Definition: myexcept.h:317
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:453
Real ** row_pointer
Definition: newmat.h:619
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:503
int search(const BaseMatrix *) const
Definition: newmat4.cpp:410
virtual GeneralMatrix * Image() const
Definition: newmat4.cpp:838
MatrixBandWidth minimum(const MatrixBandWidth &) const
Definition: bandmat.cpp:187
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:447
Real * store2
Definition: newmat.h:1117
void ReSize(int)
Definition: newmat4.cpp:256
MatrixType Type() const
Definition: newmat4.cpp:425
bool d
Definition: newmat.h:905
void CleanUp()
Definition: newmat4.cpp:892
void ReSize(int, int, int)
Definition: newmat4.cpp:216
virtual MatrixType Type() const =0
GeneralMatrix * Image() const
Definition: newmat4.cpp:789
const BaseMatrix * bm1
Definition: newmat.h:1220
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:482
int Nrows() const
Definition: newmat.h:430
void ReSize(int m, int n)
Definition: newmat.h:636
GeneralMatrix * Image() const
Definition: newmat4.cpp:810
int Upper() const
Definition: newmat.h:203
MatrixType Type() const
Definition: newmat4.cpp:417
int & operator[](int i)
Definition: newmat4.cpp:949
void CleanUp()
Definition: newmat4.cpp:898
void SetDataLossOK()
Definition: newmat.h:142
GeneralMatrix * BorrowStore(GeneralMatrix *, MatrixType)
Definition: newmat4.cpp:617
MatrixBandWidth BandWidth() const
Definition: newmat4.cpp:510
GeneralMatrix * gm2
Definition: newmat.h:1222
int upper
Definition: newmat.h:936
DiagonalMatrix()
Definition: newmat.h:776
Real * Store() const
Definition: newmat.h:433
GeneralMatrix * Image() const
Definition: newmat4.cpp:740
void Protect()
Definition: newmat.h:437
int storage
Definition: newmat.h:392
int * indx
Definition: newmat.h:904
RowVector()
Definition: newmat.h:826
GeneralMatrix * gm1
Definition: newmat.h:1220
GeneralMatrix * Image() const
Definition: newmat4.cpp:761
void Inject(const MatrixRowCol &)
Definition: newmat2.cpp:63
void Inject(const GeneralMatrix &)
Definition: newmat4.cpp:714
GeneralMatrix * Image() const
Definition: newmat4.cpp:831
void CleanUp()
Definition: newmat4.cpp:895
int col_skip
Definition: newmat.h:1507
MatrixType Type() const
Definition: newmat4.cpp:423
virtual void SetParameters(const GeneralMatrix *)
Definition: newmat.h:487
void Next()
Definition: newmatrc.h:149
GeneralMatrix * gm
Definition: newmat.h:1348
void GetMatrix(const GeneralMatrix *)
Definition: newmat4.cpp:610
MatrixType Type() const
Definition: newmat4.cpp:413
virtual ~GeneralMatrix()
Definition: newmat4.cpp:161
friend class ReturnMatrix
Definition: newmat.h:535
void ReSize(int)
Definition: newmat4.cpp:262
void ReSize(int n)
Definition: newmat4.cpp:279
void ReSize(int i, bool keep=false)
Definition: newmat4.cpp:998