home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume34 / newmat06 / part05 < prev    next >
Encoding:
Text File  |  1992-12-06  |  61.2 KB  |  2,282 lines

  1. Newsgroups: comp.sources.misc
  2. From: robertd@kauri.vuw.ac.nz (Robert Davies)
  3. Subject:  v34i011:  newmat06 - A matrix package in C++, Part05/07
  4. Message-ID: <1992Dec6.045717.4464@sparky.imd.sterling.com>
  5. X-Md4-Signature: c3fad00c990e6aeca2b3ecacedbfdcba
  6. Date: Sun, 6 Dec 1992 04:57:17 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: robertd@kauri.vuw.ac.nz (Robert Davies)
  10. Posting-number: Volume 34, Issue 11
  11. Archive-name: newmat06/part05
  12. Environment: C++
  13. Supersedes: newmat04: Volume 26, Issue 87-91
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 5 (of 7)."
  22. # Contents:  newmat5.cxx newmat6.cxx newmat7.cxx newmat8.cxx
  23. #   newmat9.cxx newmatex.cxx
  24. # Wrapped by robert@kea on Thu Dec  3 22:37:21 1992
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'newmat5.cxx' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'newmat5.cxx'\"
  28. else
  29. echo shar: Extracting \"'newmat5.cxx'\" \(10181 characters\)
  30. sed "s/^X//" >'newmat5.cxx' <<'END_OF_FILE'
  31. X//$$ newmat5.cxx         Transpose, evaluate etc
  32. X
  33. X// Copyright (C) 1991,2: R B Davies
  34. X
  35. X#include "include.h"
  36. X
  37. X#include "newmat.h"
  38. X#include "newmatrc.h"
  39. X
  40. X//#define REPORT { static ExeCounter ExeCount(__LINE__,5); ExeCount++; }
  41. X
  42. X#define REPORT {}
  43. X
  44. X
  45. X/************************ carry out operations ******************************/
  46. X
  47. X
  48. XGeneralMatrix* GeneralMatrix::Transpose(TransposedMatrix* tm, MatrixType mt)
  49. X{
  50. X   if (!mt) mt = Type().t();           // type of transposed matrix
  51. X   GeneralMatrix* gm1 = mt.New(ncols,nrows,tm); gm1->ReleaseAndDelete();
  52. X
  53. X   if (mt == Type().t())
  54. X   {
  55. X      REPORT
  56. X      for (int i=0; i<ncols; i++)
  57. X      {
  58. X     MatrixRow mr(gm1, StoreOnExit+DirectPart, i);
  59. X         MatrixCol mc(this, mr.Store(), LoadOnEntry, i);
  60. X      }
  61. X   }
  62. X   else
  63. X   {
  64. X      REPORT
  65. X      MatrixRow mr(this, LoadOnEntry);
  66. X      MatrixCol mc(gm1, StoreOnExit+DirectPart);
  67. X      int i = nrows;
  68. X      while (i--) { mc.Copy(mr); mr.Next(); mc.Next(); }
  69. X   }
  70. X   tDelete(); return gm1;
  71. X}
  72. X
  73. XGeneralMatrix* SymmetricMatrix::Transpose(TransposedMatrix*, MatrixType mt)
  74. X{ REPORT  return Evaluate(mt); }
  75. X
  76. X
  77. XGeneralMatrix* DiagonalMatrix::Transpose(TransposedMatrix*, MatrixType mt)
  78. X{ REPORT return Evaluate(mt); }
  79. X
  80. XBoolean GeneralMatrix::IsZero() const
  81. X{
  82. X   REPORT
  83. X   Real* s=store; int i=storage;
  84. X   while (i--) { if (*s++) return FALSE; }
  85. X   return TRUE;
  86. X}
  87. X
  88. XGeneralMatrix* ColumnVector::Transpose(TransposedMatrix*, MatrixType mt)
  89. X{
  90. X   REPORT
  91. X   GeneralMatrix* gmx = new RowVector; MatrixErrorNoSpace(gmx);
  92. X   gmx->nrows = 1; gmx->ncols = gmx->storage = storage;
  93. X   return BorrowStore(gmx,mt);
  94. X}
  95. X
  96. XGeneralMatrix* RowVector::Transpose(TransposedMatrix*, MatrixType mt)
  97. X{
  98. X   REPORT
  99. X   GeneralMatrix* gmx = new ColumnVector; MatrixErrorNoSpace(gmx);
  100. X   gmx->ncols = 1; gmx->nrows = gmx->storage = storage;
  101. X   return BorrowStore(gmx,mt);
  102. X}
  103. X
  104. XGeneralMatrix* GeneralMatrix::Evaluate(MatrixType mt)
  105. X{
  106. X   if (!mt) { REPORT return this; }
  107. X   if (mt==this->Type()) { REPORT return this; }
  108. X   REPORT
  109. X   GeneralMatrix* gmx = mt.New(nrows,ncols,this);
  110. X   MatrixRow mr(this, LoadOnEntry);
  111. X   MatrixRow mrx(gmx, StoreOnExit+DirectPart);
  112. X   int i=nrows;
  113. X   while (i--) { mrx.Copy(mr); mrx.Next(); mr.Next(); }
  114. X   tDelete(); gmx->ReleaseAndDelete(); return gmx;
  115. X}
  116. X
  117. XGeneralMatrix* ConstMatrix::Evaluate(MatrixType mt)
  118. X{
  119. X   if (!mt || mt==cgm->Type())
  120. X   {
  121. X      REPORT
  122. X#ifdef TEMPS_DESTROYED_QUICKLY
  123. X      GeneralMatrix* gmx = (GeneralMatrix*)cgm; delete this; return gmx;
  124. X#else
  125. X      return (GeneralMatrix*)cgm;
  126. X#endif
  127. X   }
  128. X   REPORT
  129. X   GeneralMatrix* gmx = cgm->Type().New(cgm->Nrows(),cgm->Ncols(),this);
  130. X   MatrixRow mr((GeneralMatrix*)cgm, LoadOnEntry);//assume won't change this
  131. X   MatrixRow mrx(gmx, StoreOnExit+DirectPart);
  132. X   int i=cgm->Nrows();
  133. X   while (i--) { mrx.Copy(mr); mrx.Next(); mr.Next(); }
  134. X   gmx->ReleaseAndDelete();
  135. X#ifdef TEMPS_DESTROYED_QUICKLY
  136. X   delete this;
  137. X#endif
  138. X   return gmx; // no tDelete
  139. X}
  140. X
  141. XGeneralMatrix* ShiftedMatrix::Evaluate(MatrixType mt)
  142. X{
  143. X   gm=((BaseMatrix*&)bm)->Evaluate();
  144. X   if (!mt) mt = gm->Type().AddEqualEl();
  145. X   int nr=gm->Nrows(); int nc=gm->Ncols();
  146. X   if (!(mt==gm->Type()))
  147. X   {
  148. X      REPORT
  149. X      GeneralMatrix* gmx = mt.New(nr,nc,this);
  150. X      MatrixRow mr(gm, LoadOnEntry); 
  151. X      MatrixRow mrx(gmx, StoreOnExit+DirectPart);
  152. X      while (nr--) { mrx.Add(mr,f); mrx.Next(); mr.Next(); }
  153. X      gmx->ReleaseAndDelete(); gm->tDelete();
  154. X#ifdef TEMPS_DESTROYED_QUICKLY
  155. X      delete this;
  156. X#endif
  157. X      return gmx;
  158. X   }
  159. X   else if (gm->reuse())
  160. X   {
  161. X      REPORT gm->Add(f);
  162. X#ifdef TEMPS_DESTROYED_QUICKLY
  163. X      GeneralMatrix* gmx = gm; delete this; return gmx;
  164. X#else
  165. X      return gm;
  166. X#endif
  167. X   }
  168. X   else
  169. X   {
  170. X      REPORT GeneralMatrix* gmy = gm->Type().New(nr,nc,this);
  171. X      gmy->ReleaseAndDelete(); gmy->Add(gm,f);
  172. X#ifdef TEMPS_DESTROYED_QUICKLY
  173. X      delete this;
  174. X#endif
  175. X      return gmy;
  176. X   }
  177. X}
  178. X
  179. XGeneralMatrix* ScaledMatrix::Evaluate(MatrixType mt)
  180. X{
  181. X   gm=((BaseMatrix*&)bm)->Evaluate();
  182. X   int nr=gm->Nrows(); int nc=gm->Ncols();
  183. X   if (!mt) mt = gm->Type();
  184. X   if (mt==gm->Type())
  185. X   {
  186. X      if (gm->reuse())
  187. X      {
  188. X         REPORT gm->Multiply(f);
  189. X#ifdef TEMPS_DESTROYED_QUICKLY
  190. X         GeneralMatrix* gmx = gm; delete this; return gmx;
  191. X#else
  192. X         return gm;
  193. X#endif
  194. X      }
  195. X      else
  196. X      {
  197. X         REPORT GeneralMatrix* gmx = gm->Type().New(nr,nc,this);
  198. X         gmx->ReleaseAndDelete(); gmx->Multiply(gm,f);
  199. X#ifdef TEMPS_DESTROYED_QUICKLY
  200. X         delete this;
  201. X#endif
  202. X         return gmx;
  203. X      }
  204. X   }
  205. X   else
  206. X   {
  207. X      REPORT
  208. X      GeneralMatrix* gmx = mt.New(nr,nc,this);
  209. X      MatrixRow mr(gm, LoadOnEntry); 
  210. X      MatrixRow mrx(gmx, StoreOnExit+DirectPart);
  211. X      while (nr--) { mrx.Multiply(mr,f); mrx.Next(); mr.Next(); }
  212. X      gmx->ReleaseAndDelete(); gm->tDelete();
  213. X#ifdef TEMPS_DESTROYED_QUICKLY
  214. X      delete this;
  215. X#endif
  216. X      return gmx;
  217. X   }
  218. X}
  219. X
  220. XGeneralMatrix* NegatedMatrix::Evaluate(MatrixType mt)
  221. X{
  222. X   gm=((BaseMatrix*&)bm)->Evaluate();
  223. X   if (!mt) mt = gm->Type();
  224. X   int nr=gm->Nrows(); int nc=gm->Ncols();
  225. X   if (mt==gm->Type())
  226. X   {
  227. X      if (gm->reuse())
  228. X      {
  229. X         REPORT gm->Negate();
  230. X#ifdef TEMPS_DESTROYED_QUICKLY
  231. X         GeneralMatrix* gmx = gm; delete this; return gmx;
  232. X#else
  233. X         return gm;
  234. X#endif
  235. X      }
  236. X      else
  237. X      {
  238. X         REPORT
  239. X         GeneralMatrix* gmx = gm->Type().New(nr,nc,this);
  240. X         gmx->ReleaseAndDelete(); gmx->Negate(gm);
  241. X#ifdef TEMPS_DESTROYED_QUICKLY
  242. X         delete this;
  243. X#endif
  244. X         return gmx;
  245. X      }
  246. X   }
  247. X   else
  248. X   {
  249. X      REPORT
  250. X      GeneralMatrix* gmx = mt.New(nr,nc,this);
  251. X      MatrixRow mr(gm, LoadOnEntry); 
  252. X      MatrixRow mrx(gmx, StoreOnExit+DirectPart);
  253. X      while (nr--) { mrx.Negate(mr); mrx.Next(); mr.Next(); }
  254. X      gmx->ReleaseAndDelete(); gm->tDelete();
  255. X#ifdef TEMPS_DESTROYED_QUICKLY
  256. X      delete this;
  257. X#endif
  258. X      return gmx;
  259. X   }
  260. X}   
  261. X
  262. XGeneralMatrix* TransposedMatrix::Evaluate(MatrixType mt)
  263. X{
  264. X   REPORT
  265. X   gm=((BaseMatrix*&)bm)->Evaluate();
  266. X   if (!mt) mt = gm->Type().t();
  267. X   GeneralMatrix* gmx=gm->Transpose(this, mt);
  268. X#ifdef TEMPS_DESTROYED_QUICKLY
  269. X   delete this;
  270. X#endif
  271. X   return gmx;
  272. X}
  273. X   
  274. XGeneralMatrix* RowedMatrix::Evaluate(MatrixType mt)
  275. X{
  276. X   gm = ((BaseMatrix*&)bm)->Evaluate();
  277. X   GeneralMatrix* gmx = new RowVector; MatrixErrorNoSpace(gmx);
  278. X   gmx->nrows = 1; gmx->ncols = gmx->storage = gm->storage;
  279. X#ifdef TEMPS_DESTROYED_QUICKLY
  280. X   GeneralMatrix* gmy = gm; delete this; return gmy->BorrowStore(gmx,mt);
  281. X#else
  282. X   return gm->BorrowStore(gmx,mt);
  283. X#endif
  284. X}
  285. X
  286. XGeneralMatrix* ColedMatrix::Evaluate(MatrixType mt)
  287. X{
  288. X   gm = ((BaseMatrix*&)bm)->Evaluate();
  289. X   GeneralMatrix* gmx = new ColumnVector; MatrixErrorNoSpace(gmx);
  290. X   gmx->ncols = 1; gmx->nrows = gmx->storage = gm->storage;
  291. X#ifdef TEMPS_DESTROYED_QUICKLY
  292. X   GeneralMatrix* gmy = gm; delete this; return gmy->BorrowStore(gmx,mt);
  293. X#else
  294. X   return gm->BorrowStore(gmx,mt);
  295. X#endif
  296. X}
  297. X
  298. XGeneralMatrix* DiagedMatrix::Evaluate(MatrixType mt)
  299. X{
  300. X   gm = ((BaseMatrix*&)bm)->Evaluate();
  301. X   GeneralMatrix* gmx = new DiagonalMatrix; MatrixErrorNoSpace(gmx);
  302. X   gmx->nrows = gmx->ncols = gmx->storage = gm->storage;
  303. X#ifdef TEMPS_DESTROYED_QUICKLY
  304. X   GeneralMatrix* gmy = gm; delete this; return gmy->BorrowStore(gmx,mt);
  305. X#else
  306. X   return gm->BorrowStore(gmx,mt);
  307. X#endif
  308. X}
  309. X
  310. XGeneralMatrix* MatedMatrix::Evaluate(MatrixType mt)
  311. X{
  312. X   Tracer tr("MatedMatrix::Evaluate");
  313. X   gm = ((BaseMatrix*&)bm)->Evaluate();
  314. X   GeneralMatrix* gmx = new Matrix; MatrixErrorNoSpace(gmx);
  315. X   gmx->nrows = nr; gmx->ncols = nc; gmx->storage = gm->storage;
  316. X   if (nr*nc != gmx->storage)
  317. X      Throw(IncompatibleDimensionsException());
  318. X#ifdef TEMPS_DESTROYED_QUICKLY
  319. X   GeneralMatrix* gmy = gm; delete this; return gmy->BorrowStore(gmx,mt);
  320. X#else
  321. X   return gm->BorrowStore(gmx,mt);
  322. X#endif
  323. X}
  324. X
  325. XGeneralMatrix* GetSubMatrix::Evaluate(MatrixType mt)
  326. X{
  327. X   REPORT
  328. X   Tracer tr("SubMatrix(evaluate)");
  329. X   gm = ((BaseMatrix*&)bm)->Evaluate();
  330. X   if (row_number < 0) row_number = gm->Nrows();
  331. X   if (col_number < 0) col_number = gm->Ncols();
  332. X   if (row_skip+row_number > gm->Nrows() || col_skip+col_number > gm->Ncols())
  333. X      Throw(SubMatrixDimensionException());
  334. X   if (!mt) mt = MatrixType::Rt;
  335. X   GeneralMatrix* gmx = mt.New(row_number, col_number, this);
  336. X   int i = row_number;
  337. X   MatrixRow mr(gm, LoadOnEntry, row_skip); 
  338. X   MatrixRow mrx(gmx, StoreOnExit+DirectPart);
  339. X   MatrixRowCol sub;
  340. X   while (i--)
  341. X   {
  342. X      mr.SubRowCol(sub, col_skip, col_number);   // put values in sub
  343. X      mrx.Copy(sub); mrx.Next(); mr.Next();
  344. X   }
  345. X   gmx->ReleaseAndDelete(); gm->tDelete();
  346. X#ifdef TEMPS_DESTROYED_QUICKLY
  347. X   delete this;
  348. X#endif
  349. X   return gmx;
  350. X}   
  351. X
  352. X
  353. XGeneralMatrix* ReturnMatrixX::Evaluate(MatrixType mt)
  354. X{
  355. X#ifdef TEMPS_DESTROYED_QUICKLY
  356. X   GeneralMatrix* gmx = gm; delete this; return gmx->Evaluate(mt);
  357. X#else
  358. X   return gm->Evaluate(mt);
  359. X#endif
  360. X}
  361. X
  362. X
  363. Xvoid GeneralMatrix::Add(GeneralMatrix* gm1, Real f)
  364. X{
  365. X   REPORT
  366. X   Real* s1=gm1->store; Real* s=store; int i=(storage >> 2);
  367. X   while (i--)
  368. X   { *s++ = *s1++ + f; *s++ = *s1++ + f; *s++ = *s1++ + f; *s++ = *s1++ + f; }
  369. X   i = storage & 3; while (i--) *s++ = *s1++ + f;
  370. X}
  371. X   
  372. Xvoid GeneralMatrix::Add(Real f)
  373. X{
  374. X   REPORT
  375. X   Real* s=store; int i=(storage >> 2);
  376. X   while (i--) { *s++ += f; *s++ += f; *s++ += f; *s++ += f; }
  377. X   i = storage & 3; while (i--) *s++ += f;
  378. X}
  379. X   
  380. Xvoid GeneralMatrix::Negate(GeneralMatrix* gm1)
  381. X{
  382. X   // change sign of elements
  383. X   REPORT
  384. X   Real* s1=gm1->store; Real* s=store; int i=(storage >> 2);
  385. X   while (i--)
  386. X   { *s++ = -(*s1++); *s++ = -(*s1++); *s++ = -(*s1++); *s++ = -(*s1++); }
  387. X   i = storage & 3; while(i--) *s++ = -(*s1++);
  388. X}
  389. X   
  390. Xvoid GeneralMatrix::Negate()
  391. X{
  392. X   REPORT
  393. X   Real* s=store; int i=(storage >> 2);
  394. X   while (i--)
  395. X   { *s = -(*s); s++; *s = -(*s); s++; *s = -(*s); s++; *s = -(*s); s++; }
  396. X   i = storage & 3; while(i--) { *s = -(*s); s++; }
  397. X}
  398. X   
  399. Xvoid GeneralMatrix::Multiply(GeneralMatrix* gm1, Real f)
  400. X{
  401. X   REPORT
  402. X   Real* s1=gm1->store; Real* s=store;  int i=(storage >> 2);
  403. X   while (i--)
  404. X   { *s++ = *s1++ * f; *s++ = *s1++ * f; *s++ = *s1++ * f; *s++ = *s1++ * f; }
  405. X   i = storage & 3; while (i--) *s++ = *s1++ * f;
  406. X}
  407. X   
  408. Xvoid GeneralMatrix::Multiply(Real f)
  409. X{
  410. X   REPORT
  411. X   Real* s=store; int i=(storage >> 2);
  412. X   while (i--) { *s++ *= f; *s++ *= f; *s++ *= f; *s++ *= f; }
  413. X   i = storage & 3; while (i--) *s++ *= f;
  414. X}
  415. X   
  416. END_OF_FILE
  417. if test 10181 -ne `wc -c <'newmat5.cxx'`; then
  418.     echo shar: \"'newmat5.cxx'\" unpacked with wrong size!
  419. fi
  420. # end of 'newmat5.cxx'
  421. fi
  422. if test -f 'newmat6.cxx' -a "${1}" != "-c" ; then 
  423.   echo shar: Will not clobber existing file \"'newmat6.cxx'\"
  424. else
  425. echo shar: Extracting \"'newmat6.cxx'\" \(12930 characters\)
  426. sed "s/^X//" >'newmat6.cxx' <<'END_OF_FILE'
  427. X//$$ newmat6.cxx            Operators, element access, submatrices
  428. X
  429. X// Copyright (C) 1991,2: R B Davies
  430. X
  431. X#include "include.h"
  432. X
  433. X#include "newmat.h"
  434. X#include "newmatrc.h"
  435. X
  436. X
  437. X//#define REPORT { static ExeCounter ExeCount(__LINE__,6); ExeCount++; }
  438. X
  439. X#define REPORT {}
  440. X
  441. X/*************************** general utilities *************************/
  442. X
  443. Xstatic int tristore(int n)                      // els in triangular matrix
  444. X{ return (n*(n+1))/2; }
  445. X
  446. X
  447. X/****************************** operators *******************************/
  448. X
  449. XReal& Matrix::operator()(int m, int n)
  450. X{
  451. X   if (m<=0 || m>nrows || n<=0 || n>ncols)
  452. X      Throw(IndexException(m,n,*this));
  453. X   return store[(m-1)*ncols+n-1];
  454. X}
  455. X
  456. XReal& SymmetricMatrix::operator()(int m, int n)
  457. X{
  458. X   if (m<=0 || n<=0 || m>nrows || n>ncols)
  459. X      Throw(IndexException(m,n,*this));
  460. X   if (m>=n) return store[tristore(m-1)+n-1];
  461. X   else return store[tristore(n-1)+m-1];
  462. X}
  463. X
  464. XReal& UpperTriangularMatrix::operator()(int m, int n)
  465. X{
  466. X   if (m<=0 || n<m || n>ncols)
  467. X      Throw(IndexException(m,n,*this));
  468. X   return store[(m-1)*ncols+n-1-tristore(m-1)];
  469. X}
  470. X
  471. XReal& LowerTriangularMatrix::operator()(int m, int n)
  472. X{
  473. X   if (n<=0 || m<n || m>nrows)
  474. X      Throw(IndexException(m,n,*this));
  475. X   return store[tristore(m-1)+n-1];
  476. X}
  477. X
  478. XReal& DiagonalMatrix::operator()(int m, int n)
  479. X{
  480. X   if (n<=0 || m!=n || m>nrows || n>ncols)
  481. X      Throw(IndexException(m,n,*this));
  482. X   return store[n-1];
  483. X}
  484. X
  485. XReal& DiagonalMatrix::operator()(int m)
  486. X{
  487. X   if (m<=0 || m>nrows) Throw(IndexException(m,*this));
  488. X   return store[m-1];
  489. X}
  490. X
  491. XReal& ColumnVector::operator()(int m)
  492. X{
  493. X   if (m<=0 || m> nrows) Throw(IndexException(m,*this));
  494. X   return store[m-1];
  495. X}
  496. X
  497. XReal& RowVector::operator()(int n)
  498. X{
  499. X   if (n<=0 || n> ncols) Throw(IndexException(n,*this));
  500. X   return store[n-1];
  501. X}
  502. X
  503. XReal& BandMatrix::operator()(int m, int n)
  504. X{
  505. X   int w = upper+lower+1; int i = lower+n-m;
  506. X   if (m<=0 || m>nrows || n<=0 || n>ncols || i<0 || i>=w)
  507. X      Throw(IndexException(m,n,*this));
  508. X   return store[w*(m-1)+i];
  509. X}
  510. X
  511. XReal& UpperBandMatrix::operator()(int m, int n)
  512. X{
  513. X   int w = upper+1; int i = n-m;
  514. X   if (m<=0 || m>nrows || n<=0 || n>ncols || i<0 || i>=w)
  515. X      Throw(IndexException(m,n,*this));
  516. X   return store[w*(m-1)+i];
  517. X}
  518. X
  519. XReal& LowerBandMatrix::operator()(int m, int n)
  520. X{
  521. X   int w = lower+1; int i = lower+n-m;
  522. X   if (m<=0 || m>nrows || n<=0 || n>ncols || i<0 || i>=w)
  523. X      Throw(IndexException(m,n,*this));
  524. X   return store[w*(m-1)+i];
  525. X}
  526. X
  527. XReal& SymmetricBandMatrix::operator()(int m, int n)
  528. X{
  529. X   int w = lower+1;
  530. X   if (m>=n)
  531. X   {
  532. X      int i = lower+n-m;
  533. X      if ( m>nrows || n<=0 || i<0 )
  534. X         Throw(IndexException(m,n,*this));
  535. X      return store[w*(m-1)+i];
  536. X   }
  537. X   else
  538. X   {
  539. X      int i = lower+m-n;
  540. X      if ( n>nrows || m<=0 || i<0 )
  541. X         Throw(IndexException(m,n,*this));
  542. X      return store[w*(n-1)+i];
  543. X   }
  544. X}
  545. X
  546. X#ifndef __ZTC__
  547. X
  548. XReal Matrix::operator()(int m, int n) const
  549. X{
  550. X   if (m<=0 || m>nrows || n<=0 || n>ncols)
  551. X      Throw(IndexException(m,n,*this));
  552. X   return store[(m-1)*ncols+n-1];
  553. X}
  554. X
  555. XReal SymmetricMatrix::operator()(int m, int n) const
  556. X{
  557. X   if (m<=0 || n<=0 || m>nrows || n>ncols)
  558. X      Throw(IndexException(m,n,*this));
  559. X   if (m>=n) return store[tristore(m-1)+n-1];
  560. X   else return store[tristore(n-1)+m-1];
  561. X}
  562. X
  563. XReal UpperTriangularMatrix::operator()(int m, int n) const
  564. X{
  565. X   if (m<=0 || n<m || n>ncols)
  566. X      Throw(IndexException(m,n,*this));
  567. X   return store[(m-1)*ncols+n-1-tristore(m-1)];
  568. X}
  569. X
  570. XReal LowerTriangularMatrix::operator()(int m, int n) const
  571. X{
  572. X   if (n<=0 || m<n || m>nrows)
  573. X      Throw(IndexException(m,n,*this));
  574. X   return store[tristore(m-1)+n-1];
  575. X}
  576. X
  577. XReal DiagonalMatrix::operator()(int m, int n) const
  578. X{
  579. X   if (n<=0 || m!=n || m>nrows || n>ncols)
  580. X      Throw(IndexException(m,n,*this));
  581. X   return store[n-1];
  582. X}
  583. X
  584. XReal DiagonalMatrix::operator()(int m) const
  585. X{
  586. X   if (m<=0 || m>nrows) Throw(IndexException(m,*this));
  587. X   return store[m-1];
  588. X}
  589. X
  590. XReal ColumnVector::operator()(int m) const
  591. X{
  592. X   if (m<=0 || m> nrows) Throw(IndexException(m,*this));
  593. X   return store[m-1];
  594. X}
  595. X
  596. XReal RowVector::operator()(int n) const
  597. X{
  598. X   if (n<=0 || n> ncols) Throw(IndexException(n,*this));
  599. X   return store[n-1];
  600. X}
  601. X
  602. XReal BandMatrix::operator()(int m, int n) const
  603. X{
  604. X   int w = upper+lower+1; int i = lower+n-m;
  605. X   if (m<=0 || m>nrows || n<=0 || n>ncols || i<0 || i>=w)
  606. X      Throw(IndexException(m,n,*this));
  607. X   return store[w*(m-1)+i];
  608. X}
  609. X
  610. XReal SymmetricBandMatrix::operator()(int m, int n) const
  611. X{
  612. X   int w = lower+1;
  613. X   if (m>=n)
  614. X   {
  615. X      int i = lower+n-m;
  616. X      if ( m>nrows || n<=0 || i<0 )
  617. X         Throw(IndexException(m,n,*this));
  618. X      return store[w*(m-1)+i];
  619. X   }
  620. X   else
  621. X   {
  622. X      int i = lower+m-n;
  623. X      if ( n>nrows || m<=0 || i<0 )
  624. X         Throw(IndexException(m,n,*this));
  625. X      return store[w*(n-1)+i];
  626. X   }
  627. X}
  628. X
  629. X#endif
  630. X
  631. XReal BaseMatrix::AsScalar() const
  632. X{
  633. X   REPORT
  634. X   GeneralMatrix* gm = ((BaseMatrix&)*this).Evaluate();
  635. X   if (gm->nrows!=1 || gm->ncols!=1)
  636. X   {
  637. X      Try
  638. X      {
  639. X         Tracer tr("AsScalar");
  640. X     Throw(ProgramException("Cannot convert to scalar", *gm));
  641. X      }
  642. X      CatchAll { gm->tDelete(); Throw(); }
  643. X   }
  644. X   Real x = *(gm->store); gm->tDelete(); return x;
  645. X}
  646. X
  647. X#ifdef TEMPS_DESTROYED_QUICKLY
  648. X
  649. XAddedMatrix& BaseMatrix::operator+(const BaseMatrix& bm) const
  650. X{
  651. X   REPORT
  652. X   AddedMatrix* x = new AddedMatrix(this, &bm);
  653. X   MatrixErrorNoSpace(x);
  654. X   return *x;
  655. X}
  656. X
  657. XMultipliedMatrix& BaseMatrix::operator*(const BaseMatrix& bm) const
  658. X{
  659. X   REPORT
  660. X   MultipliedMatrix* x = new MultipliedMatrix(this, &bm);
  661. X   MatrixErrorNoSpace(x);
  662. X   return *x;
  663. X}
  664. X
  665. XSolvedMatrix& InvertedMatrix::operator*(const BaseMatrix& bmx) const
  666. X{
  667. X   REPORT
  668. X   SolvedMatrix* x;
  669. X   Try { x = new SolvedMatrix(bm, &bmx); MatrixErrorNoSpace(x); }
  670. X   CatchAll { delete this; Throw(); }
  671. X   delete this;                // since we are using bm rather than this
  672. X   return *x;
  673. X}
  674. X
  675. XSubtractedMatrix& BaseMatrix::operator-(const BaseMatrix& bm) const
  676. X{
  677. X   REPORT
  678. X   SubtractedMatrix* x = new SubtractedMatrix(this, &bm);
  679. X   MatrixErrorNoSpace(x);
  680. X   return *x;
  681. X}
  682. X
  683. XShiftedMatrix& BaseMatrix::operator+(Real f) const
  684. X{
  685. X   REPORT
  686. X   ShiftedMatrix* x = new ShiftedMatrix(this, f);
  687. X   MatrixErrorNoSpace(x);
  688. X   return *x;
  689. X}
  690. X
  691. XScaledMatrix& BaseMatrix::operator*(Real f) const
  692. X{
  693. X   REPORT
  694. X   ScaledMatrix* x = new ScaledMatrix(this, f);
  695. X   MatrixErrorNoSpace(x);
  696. X   return *x;
  697. X}
  698. X
  699. XScaledMatrix& BaseMatrix::operator/(Real f) const
  700. X{
  701. X   REPORT
  702. X   ScaledMatrix* x = new ScaledMatrix(this, 1.0/f);
  703. X   MatrixErrorNoSpace(x);
  704. X   return *x;
  705. X}
  706. X
  707. XShiftedMatrix& BaseMatrix::operator-(Real f) const
  708. X{
  709. X   REPORT
  710. X   ShiftedMatrix* x = new ShiftedMatrix(this, -f);
  711. X   MatrixErrorNoSpace(x);
  712. X   return *x;
  713. X}
  714. X
  715. XTransposedMatrix& BaseMatrix::t() const
  716. X{
  717. X   REPORT
  718. X   TransposedMatrix* x = new TransposedMatrix(this);
  719. X   MatrixErrorNoSpace(x);
  720. X   return *x;
  721. X}
  722. X
  723. XNegatedMatrix& BaseMatrix::operator-() const
  724. X{
  725. X   REPORT
  726. X   NegatedMatrix* x = new NegatedMatrix(this);
  727. X   MatrixErrorNoSpace(x);
  728. X   return *x;
  729. X}
  730. X
  731. XInvertedMatrix& BaseMatrix::i() const
  732. X{
  733. X   REPORT
  734. X   InvertedMatrix* x = new InvertedMatrix(this);
  735. X   MatrixErrorNoSpace(x);
  736. X   return *x;
  737. X}
  738. X
  739. XConstMatrix& GeneralMatrix::c() const
  740. X{
  741. X   if (tag != -1)
  742. X      Throw(ProgramException(".c() applied to temporary matrix"));
  743. X   REPORT
  744. X   ConstMatrix* x = new ConstMatrix(this);
  745. X   MatrixErrorNoSpace(x);
  746. X   return *x;
  747. X}
  748. X
  749. XRowedMatrix& BaseMatrix::AsRow() const
  750. X{
  751. X   REPORT
  752. X   RowedMatrix* x = new RowedMatrix(this);
  753. X   MatrixErrorNoSpace(x);
  754. X   return *x;
  755. X}
  756. X
  757. XColedMatrix& BaseMatrix::AsColumn() const
  758. X{
  759. X   REPORT
  760. X   ColedMatrix* x = new ColedMatrix(this);
  761. X   MatrixErrorNoSpace(x);
  762. X   return *x;
  763. X}
  764. X
  765. XDiagedMatrix& BaseMatrix::AsDiagonal() const
  766. X{
  767. X   REPORT
  768. X   DiagedMatrix* x = new DiagedMatrix(this);
  769. X   MatrixErrorNoSpace(x);
  770. X   return *x;
  771. X}
  772. X
  773. XMatedMatrix& BaseMatrix::AsMatrix(int nrx, int ncx) const
  774. X{
  775. X   REPORT
  776. X   MatedMatrix* x = new MatedMatrix(this,nrx,ncx);
  777. X   MatrixErrorNoSpace(x);
  778. X   return *x;
  779. X}
  780. X
  781. X#else
  782. X
  783. XAddedMatrix BaseMatrix::operator+(const BaseMatrix& bm) const
  784. X{ REPORT return AddedMatrix(this, &bm); }
  785. X
  786. XMultipliedMatrix BaseMatrix::operator*(const BaseMatrix& bm) const
  787. X{ REPORT return MultipliedMatrix(this, &bm); }
  788. X
  789. XSolvedMatrix InvertedMatrix::operator*(const BaseMatrix& bmx) const
  790. X{ REPORT return SolvedMatrix(bm, &bmx); }
  791. X
  792. XSubtractedMatrix BaseMatrix::operator-(const BaseMatrix& bm) const
  793. X{ REPORT return SubtractedMatrix(this, &bm); }
  794. X
  795. XShiftedMatrix BaseMatrix::operator+(Real f) const
  796. X{ REPORT return ShiftedMatrix(this, f); }
  797. X
  798. XScaledMatrix BaseMatrix::operator*(Real f) const
  799. X{ REPORT return ScaledMatrix(this, f); }
  800. X
  801. XScaledMatrix BaseMatrix::operator/(Real f) const
  802. X{ REPORT return ScaledMatrix(this, 1.0/f); }
  803. X
  804. XShiftedMatrix BaseMatrix::operator-(Real f) const
  805. X{ REPORT return ShiftedMatrix(this, -f); }
  806. X
  807. XTransposedMatrix BaseMatrix::t() const
  808. X{ REPORT return TransposedMatrix(this); }
  809. X
  810. XNegatedMatrix BaseMatrix::operator-() const
  811. X{ REPORT return NegatedMatrix(this); }
  812. X
  813. XInvertedMatrix BaseMatrix::i() const
  814. X{ REPORT return InvertedMatrix(this); }
  815. X
  816. XConstMatrix GeneralMatrix::c() const
  817. X{
  818. X   if (tag != -1)
  819. X      Throw(ProgramException(".c() applied to temporary matrix"));
  820. X   REPORT return ConstMatrix(this);
  821. X}
  822. X
  823. XRowedMatrix BaseMatrix::AsRow() const
  824. X{ REPORT return RowedMatrix(this); }
  825. X
  826. XColedMatrix BaseMatrix::AsColumn() const
  827. X{ REPORT return ColedMatrix(this); }
  828. X
  829. XDiagedMatrix BaseMatrix::AsDiagonal() const
  830. X{ REPORT return DiagedMatrix(this); }
  831. X
  832. XMatedMatrix BaseMatrix::AsMatrix(int nrx, int ncx) const
  833. X{ REPORT return MatedMatrix(this,nrx,ncx); }
  834. X
  835. X#endif
  836. X
  837. Xvoid GeneralMatrix::operator=(Real f)
  838. X{ REPORT int i=storage; Real* s=store; while (i--) { *s++ = f; } }
  839. X
  840. Xvoid Matrix::operator=(const BaseMatrix& X)
  841. X{ REPORT CheckConversion(X); Eq(X,MatrixType::Rt); } 
  842. X
  843. Xvoid RowVector::operator=(const BaseMatrix& X)
  844. X{
  845. X   REPORT CheckConversion(X); Eq(X,MatrixType::RV);
  846. X   if (nrows!=1)
  847. X   {
  848. X      Tracer tr("RowVector(=)");
  849. X      Throw(VectorException(*this));
  850. X   }
  851. X}
  852. X
  853. Xvoid ColumnVector::operator=(const BaseMatrix& X)
  854. X{
  855. X   REPORT CheckConversion(X); Eq(X,MatrixType::CV);
  856. X   if (ncols!=1)
  857. X   {
  858. X      Tracer tr("ColumnVector(=)");
  859. X      Throw(VectorException(*this));
  860. X   }
  861. X}
  862. X
  863. Xvoid SymmetricMatrix::operator=(const BaseMatrix& X)
  864. X{ REPORT CheckConversion(X); Eq(X,MatrixType::Sm); }
  865. Xvoid UpperTriangularMatrix::operator=(const BaseMatrix& X)
  866. X{ REPORT CheckConversion(X); Eq(X,MatrixType::UT); }
  867. X
  868. Xvoid LowerTriangularMatrix::operator=(const BaseMatrix& X)
  869. X{ REPORT CheckConversion(X); Eq(X,MatrixType::LT); }
  870. X
  871. Xvoid DiagonalMatrix::operator=(const BaseMatrix& X)
  872. X{ REPORT CheckConversion(X); Eq(X,MatrixType::Dg); }
  873. X
  874. Xvoid GeneralMatrix::operator<<(const Real* r)
  875. X{
  876. X   REPORT
  877. X   int i = storage; Real* s=store;
  878. X   while(i--) *s++ = *r++;
  879. X}
  880. X
  881. X
  882. X/************************* element access *********************************/
  883. X
  884. XReal& Matrix::element(int m, int n)
  885. X{
  886. X   if (m<0 || m>= nrows || n<0 || n>= ncols)
  887. X      Throw(IndexException(m,n,*this,TRUE));
  888. X   return store[m*ncols+n];
  889. X}
  890. X
  891. XReal& SymmetricMatrix::element(int m, int n)
  892. X{
  893. X   if (m<0 || n<0 || m >= nrows || n>=ncols)
  894. X      Throw(IndexException(m,n,*this,TRUE));
  895. X   if (m>=n) return store[tristore(m)+n];
  896. X   else return store[tristore(n)+m];
  897. X}
  898. X
  899. XReal& UpperTriangularMatrix::element(int m, int n)
  900. X{
  901. X   if (m<0 || n<m || n>=ncols)
  902. X      Throw(IndexException(m,n,*this,TRUE));
  903. X   return store[m*ncols+n-tristore(m)];
  904. X}
  905. X
  906. XReal& LowerTriangularMatrix::element(int m, int n)
  907. X{
  908. X   if (n<0 || m<n || m>=nrows)
  909. X      Throw(IndexException(m,n,*this,TRUE));
  910. X   return store[tristore(m)+n];
  911. X}
  912. X
  913. XReal& DiagonalMatrix::element(int m, int n)
  914. X{
  915. X   if (n<0 || m!=n || m>=nrows || n>=ncols)
  916. X      Throw(IndexException(m,n,*this,TRUE));
  917. X   return store[n];
  918. X}
  919. X
  920. XReal& DiagonalMatrix::element(int m)
  921. X{
  922. X   if (m<0 || m>=nrows) Throw(IndexException(m,*this,TRUE));
  923. X   return store[m];
  924. X}
  925. X
  926. XReal& ColumnVector::element(int m)
  927. X{
  928. X   if (m<0 || m>= nrows) Throw(IndexException(m,*this,TRUE));
  929. X   return store[m];
  930. X}
  931. X
  932. XReal& RowVector::element(int n)
  933. X{
  934. X   if (n<0 || n>= ncols)  Throw(IndexException(n,*this,TRUE));
  935. X   return store[n];
  936. X}
  937. X
  938. XReal& BandMatrix::element(int m, int n)
  939. X{
  940. X   int w = upper+lower+1; int i = lower+n-m;
  941. X   if (m<0 || m>= nrows || n<0 || n>= ncols || i<0 || i>=w)
  942. X      Throw(IndexException(m,n,*this,TRUE));
  943. X   return store[w*m+i];
  944. X}
  945. X
  946. XReal& UpperBandMatrix::element(int m, int n)
  947. X{
  948. X   int w = upper+1; int i = n-m;
  949. X   if (m<0 || m>= nrows || n<0 || n>= ncols || i<0 || i>=w)
  950. X      Throw(IndexException(m,n,*this,TRUE));
  951. X   return store[w*m+i];
  952. X}
  953. X
  954. XReal& LowerBandMatrix::element(int m, int n)
  955. X{
  956. X   int w = lower+1; int i = lower+n-m;
  957. X   if (m<0 || m>= nrows || n<0 || n>= ncols || i<0 || i>=w)
  958. X      Throw(IndexException(m,n,*this,TRUE));
  959. X   return store[w*m+i];
  960. X}
  961. X
  962. XReal& SymmetricBandMatrix::element(int m, int n)
  963. X{
  964. X   int w = lower+1;
  965. X   if (m>=n)
  966. X   {
  967. X      int i = lower+n-m;
  968. X      if ( m>=nrows || n<0 || i<0 )
  969. X         Throw(IndexException(m,n,*this,TRUE));
  970. X      return store[w*m+i];
  971. X   }
  972. X   else
  973. X   {
  974. X      int i = lower+m-n;
  975. X      if ( n>=nrows || m<0 || i<0 )
  976. X         Throw(IndexException(m,n,*this,TRUE));
  977. X      return store[w*n+i];
  978. X   }
  979. X}
  980. X
  981. END_OF_FILE
  982. if test 12930 -ne `wc -c <'newmat6.cxx'`; then
  983.     echo shar: \"'newmat6.cxx'\" unpacked with wrong size!
  984. fi
  985. # end of 'newmat6.cxx'
  986. fi
  987. if test -f 'newmat7.cxx' -a "${1}" != "-c" ; then 
  988.   echo shar: Will not clobber existing file \"'newmat7.cxx'\"
  989. else
  990. echo shar: Extracting \"'newmat7.cxx'\" \(14846 characters\)
  991. sed "s/^X//" >'newmat7.cxx' <<'END_OF_FILE'
  992. X//$$ newmat7.cxx     Invert, solve, binary operations
  993. X
  994. X// Copyright (C) 1991,2: R B Davies
  995. X
  996. X#include "include.h"
  997. X
  998. X#include "newmat.h"
  999. X#include "newmatrc.h"
  1000. X
  1001. X//#define REPORT { static ExeCounter ExeCount(__LINE__,7); ExeCount++; }
  1002. X
  1003. X#define REPORT {}
  1004. X
  1005. X
  1006. X/***************************** solve routines ******************************/
  1007. X
  1008. XGeneralMatrix* GeneralMatrix::MakeSolver()
  1009. X{
  1010. X   REPORT
  1011. X   GeneralMatrix* gm = new CroutMatrix(*this);
  1012. X   MatrixErrorNoSpace(gm); gm->ReleaseAndDelete(); return gm;
  1013. X}
  1014. X
  1015. XGeneralMatrix* Matrix::MakeSolver()
  1016. X{
  1017. X   REPORT
  1018. X   GeneralMatrix* gm = new CroutMatrix(*this);
  1019. X   MatrixErrorNoSpace(gm); gm->ReleaseAndDelete(); return gm;
  1020. X}
  1021. X
  1022. Xvoid CroutMatrix::Solver(MatrixRowCol& mcout, const MatrixRowCol& mcin)
  1023. X{
  1024. X   REPORT
  1025. X   Real* el = mcin.store; int i = mcin.skip;
  1026. X   while (i--) *el++ = 0.0;
  1027. X   el += mcin.storage; i = nrows - mcin.skip - mcin.storage;
  1028. X   while (i--) *el++ = 0.0;
  1029. X   lubksb(mcin.store, mcout.skip);
  1030. X}
  1031. X
  1032. X
  1033. X// Do we need check for entirely zero output?
  1034. X
  1035. Xvoid UpperTriangularMatrix::Solver(MatrixRowCol& mcout,
  1036. X   const MatrixRowCol& mcin)
  1037. X{
  1038. X   REPORT
  1039. X   Real* elx = mcin.store+mcout.skip; int i = mcin.skip-mcout.skip;
  1040. X   while (i-- > 0) *elx++ = 0.0;
  1041. X   int nr = mcin.skip+mcin.storage; elx = mcin.store+nr; Real* el = elx;
  1042. X   int j = mcout.skip+mcout.storage-nr; int nc = ncols-nr; i = nr-mcout.skip;
  1043. X   while (j-- > 0) *elx++ = 0.0;
  1044. X   Real* Ael = store + (nr*(2*ncols-nr+1))/2; j = 0;
  1045. X   while (i-- > 0)
  1046. X   {
  1047. X      elx = el; Real sum = 0.0; int jx = j++; Ael -= nc;
  1048. X      while (jx--) sum += *(--Ael) * *(--elx);
  1049. X      elx--; *elx = (*elx - sum) / *(--Ael);
  1050. X   }
  1051. X}
  1052. X
  1053. Xvoid LowerTriangularMatrix::Solver(MatrixRowCol& mcout,
  1054. X   const MatrixRowCol& mcin)
  1055. X{
  1056. X   REPORT
  1057. X   Real* elx = mcin.store+mcout.skip; int i = mcin.skip-mcout.skip;
  1058. X   while (i-- > 0) *elx++ = 0.0;
  1059. X   int nc = mcin.skip; i = nc+mcin.storage; elx = mcin.store+i;
  1060. X   int nr = mcout.skip+mcout.storage; int j = nr-i; i = nr-nc;
  1061. X   while (j-- > 0) *elx++ = 0.0;
  1062. X   Real* el = mcin.store+nc; Real* Ael = store + (nc*(nc+1))/2; j = 0;
  1063. X   while (i-- > 0)
  1064. X   {
  1065. X      elx = el; Real sum = 0.0; int jx = j++; Ael += nc;
  1066. X      while (jx--) sum += *Ael++ * *elx++;
  1067. X      *elx = (*elx - sum) / *Ael++;
  1068. X   }
  1069. X}
  1070. X
  1071. X/******************* carry out binary operations *************************/
  1072. X
  1073. Xstatic GeneralMatrix*
  1074. X   GeneralAdd(GeneralMatrix*,GeneralMatrix*,AddedMatrix*,MatrixType);
  1075. Xstatic GeneralMatrix*
  1076. X   GeneralSub(GeneralMatrix*,GeneralMatrix*,SubtractedMatrix*,MatrixType);
  1077. Xstatic GeneralMatrix*
  1078. X   GeneralMult(GeneralMatrix*,GeneralMatrix*,MultipliedMatrix*,MatrixType);
  1079. Xstatic GeneralMatrix*
  1080. X   GeneralSolv(GeneralMatrix*,GeneralMatrix*,BaseMatrix*,MatrixType);
  1081. X
  1082. XGeneralMatrix* AddedMatrix::Evaluate(MatrixType mt)
  1083. X{
  1084. X   REPORT
  1085. X   gm1=((BaseMatrix*&)bm1)->Evaluate();
  1086. X   gm2=((BaseMatrix*&)bm2)->Evaluate();
  1087. X#ifdef TEMPS_DESTROYED_QUICKLY
  1088. X   GeneralMatrix* gmx = GeneralAdd(gm1,gm2,this,mt); delete this; return gmx;
  1089. X#else
  1090. X   return GeneralAdd(gm1,gm2,this,mt);
  1091. X#endif   
  1092. X}
  1093. X
  1094. XGeneralMatrix* SubtractedMatrix::Evaluate(MatrixType mt)
  1095. X{
  1096. X   REPORT
  1097. X   gm1=((BaseMatrix*&)bm1)->Evaluate();
  1098. X   gm2=((BaseMatrix*&)bm2)->Evaluate();
  1099. X#ifdef TEMPS_DESTROYED_QUICKLY
  1100. X   GeneralMatrix* gmx = GeneralSub(gm1,gm2,this,mt); delete this; return gmx;
  1101. X#else
  1102. X   return GeneralSub(gm1,gm2,this,mt);
  1103. X#endif   
  1104. X}
  1105. X
  1106. XGeneralMatrix* MultipliedMatrix::Evaluate(MatrixType mt)
  1107. X{
  1108. X   REPORT
  1109. X//   GeneralMatrix*
  1110. X   gm2 = ((BaseMatrix*&)bm2)->Evaluate();
  1111. X   gm2 = gm2->Evaluate(gm2->Type().MultRHS());     // no symmetric on RHS
  1112. X   gm1=((BaseMatrix*&)bm1)->Evaluate();
  1113. X#ifdef TEMPS_DESTROYED_QUICKLY
  1114. X   GeneralMatrix* gmx = GeneralMult(gm1, gm2, this, mt);
  1115. X   delete this; return gmx;
  1116. X#else
  1117. X   return GeneralMult(gm1, gm2, this, mt);
  1118. X#endif   
  1119. X}
  1120. X
  1121. XGeneralMatrix* SolvedMatrix::Evaluate(MatrixType mt)
  1122. X{
  1123. X   REPORT
  1124. X   gm1=((BaseMatrix*&)bm1)->Evaluate();
  1125. X   gm2=((BaseMatrix*&)bm2)->Evaluate();
  1126. X#ifdef TEMPS_DESTROYED_QUICKLY
  1127. X   GeneralMatrix* gmx;
  1128. X   Try { gmx = GeneralSolv(gm1,gm2,this,mt); }
  1129. X   CatchAll { delete this; Throw(); }
  1130. X   delete this; return gmx;
  1131. X#else
  1132. X   return GeneralSolv(gm1,gm2,this,mt);
  1133. X#endif   
  1134. X}
  1135. X
  1136. X// routines for adding or subtracting matrices of identical storage structure
  1137. X
  1138. Xstatic void Add(GeneralMatrix* gm, GeneralMatrix* gm1, GeneralMatrix* gm2)
  1139. X{
  1140. X   REPORT
  1141. X   Real* s1=gm1->Store(); Real* s2=gm2->Store();
  1142. X   Real* s=gm->Store(); int i=gm->Storage() >> 2;
  1143. X   while (i--)
  1144. X   {
  1145. X       *s++ = *s1++ + *s2++; *s++ = *s1++ + *s2++;
  1146. X       *s++ = *s1++ + *s2++; *s++ = *s1++ + *s2++;
  1147. X   }
  1148. X   i=gm->Storage() & 3; while (i--) *s++ = *s1++ + *s2++;
  1149. X}
  1150. X   
  1151. Xstatic void Add(GeneralMatrix* gm, GeneralMatrix* gm2)
  1152. X{
  1153. X   REPORT
  1154. X   Real* s2=gm2->Store(); Real* s=gm->Store(); int i=gm->Storage() >> 2;
  1155. X   while (i--)
  1156. X   { *s++ += *s2++; *s++ += *s2++; *s++ += *s2++; *s++ += *s2++; }
  1157. X   i=gm->Storage() & 3; while (i--) *s++ += *s2++;
  1158. X}
  1159. X
  1160. Xstatic void Subtract(GeneralMatrix* gm, GeneralMatrix* gm1, GeneralMatrix* gm2)
  1161. X{
  1162. X   REPORT
  1163. X   Real* s1=gm1->Store(); Real* s2=gm2->Store();
  1164. X   Real* s=gm->Store(); int i=gm->Storage() >> 2;
  1165. X   while (i--)
  1166. X   {
  1167. X       *s++ = *s1++ - *s2++; *s++ = *s1++ - *s2++;
  1168. X       *s++ = *s1++ - *s2++; *s++ = *s1++ - *s2++;
  1169. X   }
  1170. X   i=gm->Storage() & 3; while (i--) *s++ = *s1++ - *s2++;
  1171. X}
  1172. X
  1173. Xstatic void Subtract(GeneralMatrix* gm, GeneralMatrix* gm2)
  1174. X{
  1175. X   REPORT
  1176. X   Real* s2=gm2->Store(); Real* s=gm->Store(); int i=gm->Storage() >> 2;
  1177. X   while (i--)
  1178. X   { *s++ -= *s2++; *s++ -= *s2++; *s++ -= *s2++; *s++ -= *s2++; }
  1179. X   i=gm->Storage() & 3; while (i--) *s++ -= *s2++;
  1180. X}
  1181. X
  1182. Xstatic void ReverseSubtract(GeneralMatrix* gm, GeneralMatrix* gm2)
  1183. X{
  1184. X   REPORT
  1185. X   Real* s2=gm2->Store(); Real* s=gm->Store(); int i=gm->Storage() >> 2;
  1186. X   while (i--)
  1187. X   {
  1188. X      *s = *s2++ - *s; s++; *s = *s2++ - *s; s++;
  1189. X      *s = *s2++ - *s; s++; *s = *s2++ - *s; s++;
  1190. X   }
  1191. X   i=gm->Storage() & 3; while (i--) { *s = *s2++ - *s; s++; }
  1192. X}
  1193. X
  1194. X// routines for adding or subtracting matrices of different storage structure
  1195. X
  1196. Xstatic void AddDS(GeneralMatrix* gm, GeneralMatrix* gm1, GeneralMatrix* gm2)
  1197. X{
  1198. X   int nr = gm->Nrows();
  1199. X   MatrixRow mr1(gm1, LoadOnEntry); MatrixRow mr2(gm2, LoadOnEntry);
  1200. X   MatrixRow mr(gm, StoreOnExit+DirectPart);
  1201. X   while (nr--) { mr.Add(mr1,mr2); mr1.Next(); mr2.Next(); mr.Next(); }
  1202. X}
  1203. X   
  1204. Xstatic void AddDS(GeneralMatrix* gm, GeneralMatrix* gm2)
  1205. X// Add into first argument
  1206. X{
  1207. X   int nr = gm->Nrows();
  1208. X   MatrixRow mr(gm, StoreOnExit+LoadOnEntry+DirectPart);
  1209. X   MatrixRow mr2(gm2, LoadOnEntry);
  1210. X   while (nr--) { mr.Add(mr2); mr.Next(); mr2.Next(); }
  1211. X}
  1212. X
  1213. Xstatic void SubtractDS
  1214. X   (GeneralMatrix* gm, GeneralMatrix* gm1, GeneralMatrix* gm2)
  1215. X{
  1216. X   int nr = gm->Nrows();
  1217. X   MatrixRow mr1(gm1, LoadOnEntry); MatrixRow mr2(gm2, LoadOnEntry);
  1218. X   MatrixRow mr(gm, StoreOnExit+DirectPart);
  1219. X   while (nr--) { mr.Sub(mr1,mr2); mr1.Next(); mr2.Next(); mr.Next(); }
  1220. X}
  1221. X
  1222. Xstatic void SubtractDS(GeneralMatrix* gm, GeneralMatrix* gm2)
  1223. X{
  1224. X   int nr = gm->Nrows();
  1225. X   MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart);
  1226. X   MatrixRow mr2(gm2, LoadOnEntry);
  1227. X   while (nr--) { mr.Sub(mr2); mr.Next(); mr2.Next(); }
  1228. X}
  1229. X
  1230. Xstatic void ReverseSubtractDS(GeneralMatrix* gm, GeneralMatrix* gm2)
  1231. X{
  1232. X   int nr = gm->Nrows();
  1233. X   MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart);
  1234. X   MatrixRow mr2(gm2, LoadOnEntry);
  1235. X   while (nr--) { mr.RevSub(mr2); mr2.Next(); mr.Next(); }
  1236. X}
  1237. X
  1238. X#ifdef GXX
  1239. Xvoid AddedMatrix::SelectVersion
  1240. X   (MatrixType mtx, int& c1, int& c2) const
  1241. X#else
  1242. Xvoid AddedMatrix::SelectVersion
  1243. X   (MatrixType mtx, Boolean& c1, Boolean& c2) const
  1244. X#endif
  1245. X// for determining version of add and subtract routines
  1246. X// will need to modify if further matrix structures are introduced
  1247. X{
  1248. X   MatrixBandWidth bm1 = gm1->BandWidth();
  1249. X   MatrixBandWidth bm2 = gm2->BandWidth();
  1250. X   MatrixBandWidth bmx = bm1 + bm2;
  1251. X   c1 = (mtx == gm1->Type()) && (bmx == bm1);
  1252. X   c2 = (mtx == gm2->Type()) && (bmx == bm2);
  1253. X}
  1254. X
  1255. Xstatic GeneralMatrix* GeneralAdd(GeneralMatrix* gm1, GeneralMatrix* gm2,
  1256. X   AddedMatrix* am, MatrixType mtx)
  1257. X{
  1258. X   Tracer tr("GeneralAdd");
  1259. X   int nr=gm1->Nrows(); int nc=gm1->Ncols();
  1260. X   if (nr!=gm2->Nrows() || nc!=gm2->Ncols()) 
  1261. X      Throw(IncompatibleDimensionsException());
  1262. X   if (!mtx) mtx = gm1->Type() + gm2->Type();
  1263. X#ifdef GXX
  1264. X   int c1,c2; am->SelectVersion(mtx,c1,c2);
  1265. X#else
  1266. X   Boolean c1,c2; am->SelectVersion(mtx,c1,c2); // causes problems for g++
  1267. X#endif
  1268. X   if (c1 && c2)
  1269. X   {
  1270. X      if (gm1->reuse()) { REPORT Add(gm1,gm2); gm2->tDelete(); return gm1; }
  1271. X      else if (gm2->reuse()) { REPORT Add(gm2,gm1); return gm2; }
  1272. X      else
  1273. X      {
  1274. X         REPORT GeneralMatrix* gmx = gm1->Type().New(nr,nc,am);
  1275. X         gmx->ReleaseAndDelete(); Add(gmx,gm1,gm2); return gmx;
  1276. X      }
  1277. X   }
  1278. X   else
  1279. X   {
  1280. X      if (c1 && gm1->reuse() )               // must have type test first
  1281. X      { REPORT AddDS(gm1,gm2); gm2->tDelete(); return gm1; }
  1282. X      else if (c2 && gm2->reuse() )
  1283. X      { REPORT AddDS(gm2,gm1); if (!c1) gm1->tDelete(); return gm2; }
  1284. X      else
  1285. X      {
  1286. X         REPORT
  1287. X     GeneralMatrix* gmx = mtx.New(nr,nc,am); AddDS(gmx,gm1,gm2);
  1288. X     if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete();
  1289. X         gmx->ReleaseAndDelete(); return gmx;
  1290. X      }
  1291. X   }
  1292. X}
  1293. X
  1294. X
  1295. Xstatic GeneralMatrix* GeneralSub(GeneralMatrix* gm1, GeneralMatrix* gm2,
  1296. X   SubtractedMatrix* sm, MatrixType mtx)
  1297. X{
  1298. X   Tracer tr("GeneralSub");
  1299. X   if (!mtx) mtx = gm1->Type() + gm2->Type();
  1300. X   int nr=gm1->Nrows(); int nc=gm1->Ncols();
  1301. X   if (nr!=gm2->Nrows() || nc!=gm2->Ncols())
  1302. X      Throw(IncompatibleDimensionsException());
  1303. X#ifdef GXX
  1304. X   int c1,c2; sm->SelectVersion(mtx,c1,c2);
  1305. X#else
  1306. X   Boolean c1,c2; sm->SelectVersion(mtx,c1,c2); // causes problems for g++
  1307. X#endif
  1308. X   if (c1 && c2)
  1309. X   {
  1310. X      if (gm1->reuse())
  1311. X      { REPORT Subtract(gm1,gm2); gm2->tDelete(); return gm1; }
  1312. X      else if (gm2->reuse()) { REPORT ReverseSubtract(gm2,gm1); return gm2; }
  1313. X      else
  1314. X      {
  1315. X         REPORT
  1316. X     GeneralMatrix* gmx = gm1->Type().New(nr,nc,sm);
  1317. X         gmx->ReleaseAndDelete(); Subtract(gmx,gm1,gm2); return gmx;
  1318. X      }
  1319. X   }
  1320. X   else
  1321. X   {
  1322. X      if ( c1 && gm1->reuse() )
  1323. X      { REPORT  SubtractDS(gm1,gm2); gm2->tDelete(); return gm1; }
  1324. X      else if ( c2 && gm2->reuse() )
  1325. X      {
  1326. X         REPORT
  1327. X         ReverseSubtractDS(gm2,gm1); if (!c1) gm1->tDelete(); return gm2;
  1328. X      }
  1329. X      else
  1330. X      {
  1331. X         REPORT
  1332. X     GeneralMatrix* gmx = mtx.New(nr,nc,sm); SubtractDS(gmx,gm1,gm2);
  1333. X     if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete();
  1334. X     gmx->ReleaseAndDelete(); return gmx;
  1335. X      }
  1336. X   }
  1337. X}
  1338. X
  1339. Xstatic GeneralMatrix* GeneralMult1(GeneralMatrix* gm1, GeneralMatrix* gm2,
  1340. X   MultipliedMatrix* mm, MatrixType mtx)
  1341. X{
  1342. X   REPORT
  1343. X   Tracer tr("GeneralMult1");
  1344. X   if (!mtx) mtx = gm1->Type() * gm2->Type();
  1345. X   int nr=gm1->Nrows(); int nc=gm2->Ncols();
  1346. X   if (gm1->Ncols() !=gm2->Nrows())
  1347. X      Throw(IncompatibleDimensionsException());
  1348. X   GeneralMatrix* gmx = mtx.New(nr,nc,mm);
  1349. X
  1350. X   MatrixCol mcx(gmx, StoreOnExit+DirectPart);
  1351. X   MatrixCol mc2(gm2, LoadOnEntry);
  1352. X   while (nc--)
  1353. X   {
  1354. X      MatrixRow mr1(gm1, LoadOnEntry, mcx.Skip());
  1355. X      Real* el = mcx();                              // pointer to an element
  1356. X      int n = mcx.Storage();
  1357. X      while (n--) { *(el++) = DotProd(mr1,mc2); mr1.Next(); }
  1358. X      mc2.Next(); mcx.Next();
  1359. X   }
  1360. X   gmx->ReleaseAndDelete(); gm1->tDelete(); gm2->tDelete(); return gmx;
  1361. X}
  1362. X
  1363. Xstatic GeneralMatrix* GeneralMult2(GeneralMatrix* gm1, GeneralMatrix* gm2,
  1364. X   MultipliedMatrix* mm, MatrixType mtx)
  1365. X{
  1366. X   REPORT
  1367. X   Tracer tr("GeneralMult2");
  1368. X   if (!mtx) mtx = gm1->Type() * gm2->Type();
  1369. X   int nr=gm1->Nrows(); int nc=gm2->Ncols();
  1370. X   if (gm1->Ncols() !=gm2->Nrows())
  1371. X      Throw(IncompatibleDimensionsException());
  1372. X   GeneralMatrix* gmx = mtx.New(nr,nc,mm);
  1373. X
  1374. X   Real* el = gmx->Store(); int n = gmx->Storage();
  1375. X   while (n--) *el++ = 0.0;
  1376. X   MatrixRow mrx(gmx, LoadOnEntry+StoreOnExit+DirectPart);
  1377. X   MatrixRow mr1(gm1, LoadOnEntry);
  1378. X   while (nr--)
  1379. X   {
  1380. X      MatrixRow mr2(gm2, LoadOnEntry, mr1.Skip());
  1381. X      el = mr1();                              // pointer to an element
  1382. X      n = mr1.Storage();
  1383. X      while (n--) { mrx.AddScaled(mr2, *el++); mr2.Next(); }
  1384. X      mr1.Next(); mrx.Next();
  1385. X   }
  1386. X   gmx->ReleaseAndDelete(); gm1->tDelete(); gm2->tDelete(); return gmx;
  1387. X}
  1388. X
  1389. Xstatic GeneralMatrix* GeneralMult(GeneralMatrix* gm1, GeneralMatrix* gm2,
  1390. X   MultipliedMatrix* mm, MatrixType mtx)
  1391. X{
  1392. X   return GeneralMult1(gm1, gm2, mm, mtx);
  1393. X//   return GeneralMult2(gm1, gm2, mm, mtx);
  1394. X}
  1395. X
  1396. Xstatic GeneralMatrix* GeneralSolv(GeneralMatrix* gm1, GeneralMatrix* gm2,
  1397. X   BaseMatrix* sm, MatrixType mtx)
  1398. X{
  1399. X   REPORT
  1400. X   Tracer tr("GeneralSolv");
  1401. X   if (!mtx) mtx = gm1->Type().i()*gm2->Type();
  1402. X   int nr=gm1->Nrows(); int nc=gm2->Ncols();
  1403. X   if (gm1->Ncols() !=gm2->Nrows())
  1404. X      Throw(IncompatibleDimensionsException());
  1405. X   GeneralMatrix* gmx = mtx.New(nr,nc,sm);
  1406. X
  1407. X   Real* r = new Real [nr]; MatrixErrorNoSpace(r);
  1408. X#ifndef ATandT
  1409. X   MONITOR_REAL_NEW("Make   (GenSolv)",nr,r)
  1410. X                           // deleted for ATandT, to balance deletion below
  1411. X#endif
  1412. X   MatrixCol mcx(gmx, r, StoreOnExit+DirectPart);   // copy to and from r
  1413. X   MatrixCol mc2(gm2, r, LoadOnEntry);
  1414. X   GeneralMatrix* gms = gm1->MakeSolver();
  1415. X   Try
  1416. X   {
  1417. X      while (nc--) { gms->Solver(mcx, mc2); mcx.Next(); mc2.Next(); }
  1418. X   }
  1419. X   CatchAll
  1420. X   {
  1421. X      gms->tDelete(); delete gmx; gm2->tDelete();
  1422. X#ifndef ATandT
  1423. X      MONITOR_REAL_DELETE("Delete (GenSolv)",nr,r)
  1424. X                          // ATandT version 2.1 gives an internal error
  1425. X#endif
  1426. X#ifdef Version21
  1427. X      delete [] r;
  1428. X#else
  1429. X      delete [nr] r;
  1430. X#endif
  1431. X      Throw();
  1432. X   }
  1433. X   gms->tDelete(); gmx->ReleaseAndDelete(); gm2->tDelete();
  1434. X#ifndef ATandT
  1435. X   MONITOR_REAL_DELETE("Delete (GenSolv)",nr,r)
  1436. X                          // ATandT version 2.1 gives an internal error
  1437. X#endif
  1438. X#ifdef Version21
  1439. X   delete [] r;
  1440. X#else
  1441. X   delete [nr] r;
  1442. X#endif
  1443. X   return gmx;
  1444. X}
  1445. X
  1446. XGeneralMatrix* InvertedMatrix::Evaluate(MatrixType mtx)
  1447. X{
  1448. X   // Matrix Inversion - use solve routines
  1449. X   REPORT
  1450. X   gm=((BaseMatrix*&)bm)->Evaluate();
  1451. X   int n = gm->Nrows(); DiagonalMatrix I(n); I=1.0;
  1452. X#ifdef TEMPS_DESTROYED_QUICKLY
  1453. X   GeneralMatrix* gmx;
  1454. X   Try { gmx = GeneralSolv(gm,&I,this,mtx); }
  1455. X   CatchAll { delete this; Throw(); }
  1456. X   delete this; return gmx;
  1457. X#else
  1458. X   return GeneralSolv(gm,&I,this,mtx);
  1459. X#endif   
  1460. X}
  1461. X
  1462. X
  1463. X/*************************** norm functions ****************************/
  1464. X
  1465. XReal BaseMatrix::Norm1() const
  1466. X{
  1467. X   // maximum of sum of absolute values of a column
  1468. X   REPORT
  1469. X   GeneralMatrix* gm = ((BaseMatrix&)*this).Evaluate();
  1470. X   int nc = gm->Ncols(); Real value = 0.0;
  1471. X   MatrixCol mc(gm, LoadOnEntry);
  1472. X   while (nc--)
  1473. X      { Real v = mc.SumAbsoluteValue(); if (value < v) value = v; mc.Next(); }
  1474. X   gm->tDelete(); return value;
  1475. X}
  1476. X
  1477. XReal BaseMatrix::NormInfinity() const
  1478. X{
  1479. X   // maximum of sum of absolute values of a row
  1480. X   REPORT
  1481. X   GeneralMatrix* gm = ((BaseMatrix&)*this).Evaluate();
  1482. X   int nr = gm->Nrows(); Real value = 0.0;
  1483. X   MatrixRow mr(gm, LoadOnEntry);
  1484. X   while (nr--)
  1485. X      { Real v = mr.SumAbsoluteValue(); if (value < v) value = v; mr.Next(); }
  1486. X   gm->tDelete(); return value;
  1487. X}
  1488. END_OF_FILE
  1489. if test 14846 -ne `wc -c <'newmat7.cxx'`; then
  1490.     echo shar: \"'newmat7.cxx'\" unpacked with wrong size!
  1491. fi
  1492. # end of 'newmat7.cxx'
  1493. fi
  1494. if test -f 'newmat8.cxx' -a "${1}" != "-c" ; then 
  1495.   echo shar: Will not clobber existing file \"'newmat8.cxx'\"
  1496. else
  1497. echo shar: Extracting \"'newmat8.cxx'\" \(8360 characters\)
  1498. sed "s/^X//" >'newmat8.cxx' <<'END_OF_FILE'
  1499. X//$$ newmat8.cxx         Advanced LU transform, scalar functions
  1500. X
  1501. X// Copyright (C) 1991,2: R B Davies
  1502. X
  1503. X#define WANT_MATH
  1504. X
  1505. X#include "include.h"
  1506. X
  1507. X#include "newmatap.h"
  1508. X
  1509. X//#define REPORT { static ExeCounter ExeCount(__LINE__,8); ExeCount++; }
  1510. X
  1511. X#define REPORT {}
  1512. X
  1513. X
  1514. X/************************** LU transformation ****************************/
  1515. X
  1516. Xvoid CroutMatrix::ludcmp()
  1517. X// LU decomposition - from numerical recipes in C
  1518. X{
  1519. X   REPORT
  1520. X   Tracer trace("Crout(ludcmp)");
  1521. X   int i,j;
  1522. X
  1523. X   Real* vv=new Real [nrows]; MatrixErrorNoSpace(vv);
  1524. X   MONITOR_REAL_NEW("Make  (CroutMat)",nrows,vv)
  1525. X   Real* a;
  1526. X
  1527. X   a=store;
  1528. X   for (i=0;i<nrows;i++)
  1529. X   {
  1530. X      Real big=0.0;
  1531. X      j=nrows; while (j--) { Real temp=fabs(*a++); if (temp > big) big=temp; }
  1532. X      if (big == 0.0)
  1533. X      {
  1534. X         MONITOR_REAL_DELETE("Delete (CroutMt)",nrows,vv)
  1535. X#ifdef Version21
  1536. X         sing = TRUE; delete [] vv; return;
  1537. X#else
  1538. X         sing = TRUE; delete [nrows] vv; return;
  1539. X#endif
  1540. X      }
  1541. X      vv[i]=1.0/big;
  1542. X   }
  1543. X
  1544. X   Real* aj=store;
  1545. X   for (j=0;j<nrows;j++)
  1546. X   {
  1547. X      Real* ai=store;
  1548. X      for (i=0;i<j;i++)
  1549. X      {
  1550. X         Real sum=*(ai+j); Real* aix=ai; Real* ajx=aj;
  1551. X         int k=i; while (k--) { sum -= *aix++ * *ajx; ajx += nrows; }
  1552. X         *ajx = sum; ai += nrows;
  1553. X      }
  1554. X
  1555. X      Real big=0.0; int imax;
  1556. X      for (i=j;i<nrows;i++)
  1557. X      {
  1558. X         Real sum=*(ai+j); Real* aix=ai; Real* ajx=aj;
  1559. X         int k=j; while (k--) { sum -= *aix++ * *ajx; ajx += nrows; }
  1560. X         *aix = sum; ai += nrows;
  1561. X         Real dum=vv[i]*fabs(sum); if (dum >= big) { big=dum; imax=i; }
  1562. X      }
  1563. X
  1564. X      if (j != imax)
  1565. X      {
  1566. X         Real* amax=store+imax*nrows; Real* ajx=store+j*nrows;
  1567. X         int k=nrows; while(k--) { Real dum=*amax; *amax++=*ajx; *ajx++=dum; }
  1568. X         d=!d; vv[imax]=vv[j];
  1569. X      }
  1570. X
  1571. X      indx[j]=imax; ai=aj+j*nrows;
  1572. X      if (*ai == 0.0)
  1573. X      {
  1574. X         MONITOR_REAL_DELETE("Delete (CroutMt)",nrows,vv)
  1575. X#ifdef Version21
  1576. X         sing = TRUE; delete [] vv; return;
  1577. X#else
  1578. X         sing = TRUE; delete [nrows] vv; return;
  1579. X#endif
  1580. X      }
  1581. X      Real dum=1.0/(*ai);
  1582. X      i=nrows-j; while (--i) { ai += nrows; *ai *= dum; }
  1583. X
  1584. X      aj++;
  1585. X   }
  1586. X   MONITOR_REAL_DELETE("Delete (CroutMt)",nrows,vv)
  1587. X#ifdef Version21
  1588. X   delete [] vv;
  1589. X#else
  1590. X   delete [nrows] vv;
  1591. X#endif
  1592. X}
  1593. X
  1594. Xvoid CroutMatrix::lubksb(Real* B, int mini)
  1595. X{
  1596. X   REPORT
  1597. X   Tracer trace("Crout(lubksb)");
  1598. X   if (sing) Throw(SingularException(*this));   
  1599. X   int i,j; int ii=-1; Real* ai=store;
  1600. X
  1601. X   for (i=0;i<nrows;i++)
  1602. X   {
  1603. X      int ip=indx[i]; Real sum=B[ip]; B[ip]=B[i];
  1604. X      if (ii>=0)
  1605. X      {
  1606. X         Real* aij=ai+ii; Real* bj=B+ii; j=i-ii;
  1607. X         while (j--) { sum -= *aij++ * *bj; bj++; }
  1608. X      }
  1609. X      else if (sum) ii=i;
  1610. X      B[i]=sum; ai += nrows;
  1611. X   }
  1612. X
  1613. X   for (i=nrows-1;i>=mini;i--)
  1614. X   {
  1615. X      Real* bj=B+i; ai -= nrows; Real* ajx=ai+i; Real sum=*bj; bj++;
  1616. X      j=nrows-i; while(--j) { sum -= *(++ajx) * *bj; bj++; }
  1617. X      B[i]=sum/(*(ai+i));
  1618. X   }
  1619. X}
  1620. X
  1621. X
  1622. X/****************************** scalar functions ****************************/
  1623. X
  1624. Xinline Real square(Real x) { return x*x; }
  1625. X
  1626. XReal GeneralMatrix::SumSquare() const
  1627. X{
  1628. X   REPORT
  1629. X   Real sum = 0.0; int i = storage; Real* s = store;
  1630. X   while (i--) sum += square(*s++);
  1631. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1632. X}
  1633. X
  1634. XReal GeneralMatrix::SumAbsoluteValue() const
  1635. X{
  1636. X   REPORT
  1637. X   Real sum = 0.0; int i = storage; Real* s = store;
  1638. X   while (i--) sum += fabs(*s++);
  1639. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1640. X}
  1641. X
  1642. XReal GeneralMatrix::MaximumAbsoluteValue() const
  1643. X{
  1644. X   REPORT
  1645. X   Real maxval = 0.0; int i = storage; Real* s = store;
  1646. X   while (i--) { Real a = fabs(*s++); if (maxval < a) maxval = a; }
  1647. X   ((GeneralMatrix&)*this).tDelete(); return maxval;
  1648. X}
  1649. X
  1650. XReal SymmetricMatrix::SumSquare() const
  1651. X{
  1652. X   REPORT
  1653. X   Real sum1 = 0.0; Real sum2 = 0.0; Real* s = store; int nr = nrows;
  1654. X   for (int i = 0; i<nr; i++)
  1655. X   {
  1656. X      int j = i;
  1657. X      while (j--) sum2 += square(*s++);
  1658. X      sum1 += square(*s++);
  1659. X   }
  1660. X   ((GeneralMatrix&)*this).tDelete(); return sum1 + 2.0 * sum2;
  1661. X}
  1662. X
  1663. XReal SymmetricMatrix::SumAbsoluteValue() const
  1664. X{
  1665. X   REPORT
  1666. X   Real sum1 = 0.0; Real sum2 = 0.0; Real* s = store; int nr = nrows;
  1667. X   for (int i = 0; i<nr; i++)
  1668. X   {
  1669. X      int j = i;
  1670. X      while (j--) sum2 += fabs(*s++);
  1671. X      sum1 += fabs(*s++);
  1672. X   }
  1673. X   ((GeneralMatrix&)*this).tDelete(); return sum1 + 2.0 * sum2;
  1674. X}
  1675. X
  1676. XReal BaseMatrix::SumSquare() const
  1677. X{
  1678. X   REPORT GeneralMatrix* gm = ((BaseMatrix&)*this).Evaluate();
  1679. X   Real s = gm->SumSquare(); return s;
  1680. X}
  1681. X
  1682. XReal BaseMatrix::SumAbsoluteValue() const
  1683. X{
  1684. X   REPORT GeneralMatrix* gm = ((BaseMatrix&)*this).Evaluate();
  1685. X   Real s = gm->SumAbsoluteValue(); return s;
  1686. X}
  1687. X
  1688. XReal BaseMatrix::MaximumAbsoluteValue() const
  1689. X{
  1690. X   REPORT GeneralMatrix* gm = ((BaseMatrix&)*this).Evaluate();
  1691. X   Real s = gm->MaximumAbsoluteValue(); return s;
  1692. X}
  1693. X
  1694. XReal Matrix::Trace() const
  1695. X{
  1696. X   REPORT
  1697. X   Tracer trace("Trace");
  1698. X   int i = nrows; int d = i+1;
  1699. X   if (i != ncols) Throw(NotSquareException(*this));
  1700. X   Real sum = 0.0; Real* s = store;
  1701. X   while (i--) { sum += *s; s += d; }
  1702. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1703. X}
  1704. X
  1705. XReal DiagonalMatrix::Trace() const
  1706. X{
  1707. X   REPORT
  1708. X   int i = nrows; Real sum = 0.0; Real* s = store;
  1709. X   while (i--) sum += *s++;
  1710. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1711. X}
  1712. X
  1713. XReal SymmetricMatrix::Trace() const
  1714. X{
  1715. X   REPORT
  1716. X   int i = nrows; Real sum = 0.0; Real* s = store; int j = 2;
  1717. X   while (i--) { sum += *s; s += j++; }
  1718. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1719. X}
  1720. X
  1721. XReal LowerTriangularMatrix::Trace() const
  1722. X{
  1723. X   REPORT
  1724. X   int i = nrows; Real sum = 0.0; Real* s = store; int j = 2;
  1725. X   while (i--) { sum += *s; s += j++; }
  1726. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1727. X}
  1728. X
  1729. XReal UpperTriangularMatrix::Trace() const
  1730. X{
  1731. X   REPORT
  1732. X   int i = nrows; Real sum = 0.0; Real* s = store;
  1733. X   while (i) { sum += *s; s += i--; }
  1734. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1735. X}
  1736. X
  1737. XReal BandMatrix::Trace() const
  1738. X{
  1739. X   REPORT
  1740. X   int i = nrows; int w = lower+upper+1;
  1741. X   Real sum = 0.0; Real* s = store+lower;
  1742. X   while (i--) { sum += *s; s += w; }
  1743. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1744. X}
  1745. X
  1746. XReal SymmetricBandMatrix::Trace() const
  1747. X{
  1748. X   REPORT
  1749. X   int i = nrows; int w = lower+1;
  1750. X   Real sum = 0.0; Real* s = store+lower;
  1751. X   while (i--) { sum += *s; s += w; }
  1752. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1753. X}
  1754. X
  1755. XReal BaseMatrix::Trace() const
  1756. X{
  1757. X   REPORT
  1758. X   GeneralMatrix* gm = ((BaseMatrix&)*this).Evaluate(MatrixType::Dg);
  1759. X   Real sum = gm->Trace(); return sum;
  1760. X}
  1761. X
  1762. Xvoid LogAndSign::operator*=(Real x)
  1763. X{
  1764. X   if (x > 0.0) { log_value += log(x); }
  1765. X   else if (x < 0.0) { log_value += log(-x); sign = -sign; }
  1766. X   else sign = 0;
  1767. X}
  1768. X
  1769. XReal LogAndSign::Value() const { return sign * exp(log_value); }
  1770. X
  1771. XLogAndSign::LogAndSign(Real f)
  1772. X{
  1773. X   if (f == 0.0) { log_value = 0.0; sign = 0; return; }
  1774. X   else if (f < 0.0) { sign = -1; f = -f; }
  1775. X   else sign = 1;
  1776. X   log_value = log(f);
  1777. X}
  1778. X
  1779. XLogAndSign DiagonalMatrix::LogDeterminant() const
  1780. X{
  1781. X   REPORT
  1782. X   int i = nrows; LogAndSign sum; Real* s = store;
  1783. X   while (i--) sum *= *s++;
  1784. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1785. X}
  1786. X
  1787. XLogAndSign LowerTriangularMatrix::LogDeterminant() const
  1788. X{
  1789. X   REPORT
  1790. X   int i = nrows; LogAndSign sum; Real* s = store; int j = 2;
  1791. X   while (i--) { sum *= *s; s += j++; }
  1792. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1793. X}
  1794. X
  1795. XLogAndSign UpperTriangularMatrix::LogDeterminant() const
  1796. X{
  1797. X   REPORT
  1798. X   int i = nrows; LogAndSign sum; Real* s = store;
  1799. X   while (i) { sum *= *s; s += i--; }
  1800. X   ((GeneralMatrix&)*this).tDelete(); return sum;
  1801. X}
  1802. X
  1803. XLogAndSign BaseMatrix::LogDeterminant() const
  1804. X{
  1805. X   REPORT GeneralMatrix* gm = ((BaseMatrix&)*this).Evaluate();
  1806. X   LogAndSign sum = gm->LogDeterminant(); return sum;
  1807. X}
  1808. X
  1809. XLogAndSign GeneralMatrix::LogDeterminant() const
  1810. X{
  1811. X   REPORT
  1812. X   Tracer tr("Determinant");
  1813. X   if (nrows != ncols) Throw(NotSquareException(*this));
  1814. X   CroutMatrix C(*this); return C.LogDeterminant();
  1815. X}
  1816. X
  1817. XLogAndSign CroutMatrix::LogDeterminant() const
  1818. X{
  1819. X   REPORT
  1820. X   if (sing) return 0.0;
  1821. X   int i = nrows; int dd = i+1; LogAndSign sum; Real* s = store;
  1822. X   while (i--) { sum *= *s; s += dd; }
  1823. X   if (!d) sum.ChangeSign(); return sum;
  1824. X
  1825. X}
  1826. X
  1827. XLinearEquationSolver::LinearEquationSolver(const BaseMatrix& bm)
  1828. X: gm( ( ((BaseMatrix&)bm).Evaluate() )->MakeSolver() )
  1829. X{
  1830. X   if (gm==&bm)
  1831. X   // want a copy if  *gm is actually bm
  1832. X   {
  1833. X      REPORT
  1834. X      GeneralMatrix* gmx = gm->Type().New();
  1835. X      gmx->GetMatrix(gm); gm = gmx;
  1836. X   } 
  1837. X   else { REPORT  gm->Protect(); }
  1838. X}
  1839. X
  1840. END_OF_FILE
  1841. if test 8360 -ne `wc -c <'newmat8.cxx'`; then
  1842.     echo shar: \"'newmat8.cxx'\" unpacked with wrong size!
  1843. fi
  1844. # end of 'newmat8.cxx'
  1845. fi
  1846. if test -f 'newmat9.cxx' -a "${1}" != "-c" ; then 
  1847.   echo shar: Will not clobber existing file \"'newmat9.cxx'\"
  1848. else
  1849. echo shar: Extracting \"'newmat9.cxx'\" \(952 characters\)
  1850. sed "s/^X//" >'newmat9.cxx' <<'END_OF_FILE'
  1851. X//$$ newmat9.cxx         Input and output
  1852. X
  1853. X// Copyright (C) 1991,2: R B Davies
  1854. X
  1855. X
  1856. X#define WANT_STREAM
  1857. X
  1858. X#include "include.h"
  1859. X
  1860. X#include "newmat.h"
  1861. X#include "newmatrc.h"
  1862. X#include "newmatio.h"
  1863. X
  1864. X//#define REPORT { static ExeCounter ExeCount(__LINE__,9); ExeCount++; }
  1865. X
  1866. X#define REPORT {}
  1867. X
  1868. Xostream& operator<<(ostream& s, const BaseMatrix& X)
  1869. X{
  1870. X   GeneralMatrix* gm = ((BaseMatrix&)X).Evaluate(); operator<<(s, *gm);
  1871. X   gm->tDelete(); return s;
  1872. X}
  1873. X
  1874. X
  1875. Xostream& operator<<(ostream& s, const GeneralMatrix& X)
  1876. X{
  1877. X   MatrixRow mr((GeneralMatrix*)&X, LoadOnEntry);
  1878. X   int w = s.width();  int nr = X.Nrows();  long f = s.flags();
  1879. X   s.setf(ios::fixed, ios::floatfield);
  1880. X   for (int i=1; i<=nr; i++)
  1881. X   {
  1882. X      int skip = mr.skip;  int storage = mr.storage;
  1883. X      Real* store = mr.store+skip;  skip *= w+1;
  1884. X      while (skip--) s << " ";
  1885. X      while (storage--) s << setw(w) << *store++ << " ";
  1886. X      mr.Next();  s << "\n";
  1887. X   }
  1888. X   s << flush;  s.flags(f); return s;
  1889. X}
  1890. X
  1891. END_OF_FILE
  1892. if test 952 -ne `wc -c <'newmat9.cxx'`; then
  1893.     echo shar: \"'newmat9.cxx'\" unpacked with wrong size!
  1894. fi
  1895. # end of 'newmat9.cxx'
  1896. fi
  1897. if test -f 'newmatex.cxx' -a "${1}" != "-c" ; then 
  1898.   echo shar: Will not clobber existing file \"'newmatex.cxx'\"
  1899. else
  1900. echo shar: Extracting \"'newmatex.cxx'\" \(9485 characters\)
  1901. sed "s/^X//" >'newmatex.cxx' <<'END_OF_FILE'
  1902. X//$$ newmatex.cxx                    Exception handler
  1903. X
  1904. X// Copyright (C) 1992: R B Davies
  1905. X
  1906. X#define WANT_STREAM                  // include.h will get stream fns
  1907. X
  1908. X#include "include.h"                 // include standard files
  1909. X#include "newmat.h"
  1910. X
  1911. X
  1912. X// action = -1    print message and exit(1)
  1913. X//           0    no message if handler available
  1914. X//           1    print message and use handler
  1915. X
  1916. X
  1917. X
  1918. Xint SpaceException::action = 1;
  1919. Xint DataException::action = 1;
  1920. Xint ConvergenceException::action = 1;
  1921. Xint ProgramException::action = 1;
  1922. Xint InternalException::action = 1;
  1923. X
  1924. X
  1925. Xstatic inline iabs(int i) { return i >= 0 ? i : -i; }
  1926. X
  1927. X
  1928. XMatrixDetails::MatrixDetails(const GeneralMatrix& A)
  1929. X   : type(A.Type()), nrows(A.Nrows()), ncols(A.Ncols())
  1930. X{ MatrixBandWidth bw = A.BandWidth(); ubw = bw.upper; lbw = bw.lower; }
  1931. X
  1932. Xvoid MatrixDetails::PrintOut()
  1933. X{
  1934. X   cout << "MatrixType = " << (char*)type;
  1935. X   cout << "  # Rows = " << nrows;
  1936. X   cout << "; # Cols = " << ncols;
  1937. X   if (lbw >=0) cout << "; lower BW = " << lbw;
  1938. X   if (ubw >=0) cout << "; upper BW = " << ubw;
  1939. X   cout << "\n";
  1940. X}
  1941. X
  1942. X
  1943. X
  1944. XSpaceException::SpaceException() : Exception(abs(action))
  1945. X{
  1946. X   if (action) cout << "Out of space on heap\n";
  1947. X   if (action < 0) exit(1);
  1948. X}
  1949. X
  1950. XMatrixException::MatrixException(int action) : Exception(iabs(action))
  1951. X{ if (action) cout << "The exception is from newmat.\n"; }
  1952. X
  1953. XMatrixException::MatrixException(int action, const GeneralMatrix& A)
  1954. X   : Exception(iabs(action))
  1955. X{
  1956. X   if (action)
  1957. X   {
  1958. X      cout << "The exception is from newmat: details of matrix follow:\n";
  1959. X      MatrixDetails(A).PrintOut();
  1960. X   }
  1961. X}
  1962. X
  1963. XMatrixException::MatrixException(int action, const GeneralMatrix& A,
  1964. X   const GeneralMatrix& B) : Exception(iabs(action))
  1965. X{
  1966. X   if (action)
  1967. X   {
  1968. X      cout << "The exception is from newmat: details of matrices follow:\n";
  1969. X      MatrixDetails(A).PrintOut();
  1970. X      MatrixDetails(B).PrintOut();
  1971. X   }
  1972. X}
  1973. X
  1974. XDataException::DataException(const GeneralMatrix& A)
  1975. X   : MatrixException(action, A) {}
  1976. X
  1977. XNPDException::NPDException(const GeneralMatrix& A)
  1978. X   : DataException(A)
  1979. X{
  1980. X   if (action) cout << "The matrix is not positive definite\n\n";
  1981. X   if (action < 0) exit(1);
  1982. X}
  1983. X
  1984. XSingularException::SingularException(const GeneralMatrix& A)
  1985. X   : DataException(A)
  1986. X{
  1987. X   if (action) cout << "The matrix is singular\n\n";
  1988. X   if (action < 0) exit(1);
  1989. X}
  1990. X
  1991. XConvergenceException::ConvergenceException(const GeneralMatrix& A)
  1992. X   : MatrixException(action,A)
  1993. X{
  1994. X   if (action) cout << "Process fails to converge\n\n";
  1995. X   if (action < 0) exit(1);
  1996. X}
  1997. X
  1998. XProgramException::ProgramException(char* c) : MatrixException(action)
  1999. X{
  2000. X   if (action) cout << c << "\n\n";
  2001. X   if (action < 0) exit(1);
  2002. X}
  2003. X
  2004. XProgramException::ProgramException(char* c, const GeneralMatrix& A)
  2005. X   : MatrixException(action,A)
  2006. X{
  2007. X   if (action) cout << c << "\n\n";
  2008. X   if (action < 0) exit(1);
  2009. X}
  2010. X
  2011. XProgramException::ProgramException(char* c, const GeneralMatrix& A,
  2012. X   const GeneralMatrix& B) : MatrixException(action,A,B)
  2013. X{
  2014. X   if (action) cout << c << "\n\n";
  2015. X   if (action < 0) exit(1);
  2016. X}
  2017. X
  2018. XProgramException::ProgramException(const GeneralMatrix& A)
  2019. X   : MatrixException(action, A) {}
  2020. X
  2021. XProgramException::ProgramException() : MatrixException(action) {}
  2022. X
  2023. XVectorException::VectorException() : ProgramException()
  2024. X{
  2025. X   if (action) cout << "Cannot convert matrix to vector\n\n";
  2026. X   if (action < 0) exit(1);
  2027. X}
  2028. X
  2029. XVectorException::VectorException(const GeneralMatrix& A)
  2030. X   : ProgramException(A)
  2031. X{
  2032. X   if (action) cout << "Cannot convert matrix to vector\n\n";
  2033. X   if (action < 0) exit(1);
  2034. X}
  2035. X
  2036. XNotSquareException::NotSquareException(const GeneralMatrix& A)
  2037. X   : ProgramException(A)
  2038. X{
  2039. X   if (action) cout << "Matrix is not square\n\n";
  2040. X   if (action < 0) exit(1);
  2041. X}
  2042. X
  2043. XSubMatrixDimensionException::SubMatrixDimensionException()
  2044. X   : ProgramException()
  2045. X{
  2046. X   if (action) cout << "Incompatible submatrix dimension\n\n";
  2047. X   if (action < 0) exit(1);
  2048. X}
  2049. X
  2050. XIncompatibleDimensionsException::IncompatibleDimensionsException()
  2051. X   : ProgramException()
  2052. X{
  2053. X   if (action) cout << "Incompatible dimensions\n\n";
  2054. X   if (action < 0) exit(1);
  2055. X}
  2056. X
  2057. XNotDefinedException::NotDefinedException(char* op, char* matrix)
  2058. X   : ProgramException()
  2059. X{
  2060. X   if (action)
  2061. X      cout << "Operation " << op << " not defined for " << matrix << "\n\n";
  2062. X   if (action < 0) exit(1);
  2063. X}
  2064. X
  2065. XCannotBuildException::CannotBuildException(char* matrix)
  2066. X   : ProgramException()
  2067. X{
  2068. X   if (action)
  2069. X      cout << "Cannot build matrix type " << matrix << "\n\n";
  2070. X   if (action < 0) exit(1);
  2071. X}
  2072. X
  2073. XIndexException::IndexException(int i, const GeneralMatrix& A)
  2074. X   : ProgramException(A)
  2075. X{
  2076. X   if (action)
  2077. X      { cout << "Index error: requested index = " << i << "\n\n"; }
  2078. X   if (action < 0) exit(1);
  2079. X}
  2080. X
  2081. XIndexException::IndexException(int i, int j, const GeneralMatrix& A)
  2082. X   : ProgramException(A)
  2083. X{
  2084. X   if (action)
  2085. X   {
  2086. X      cout << "Index error: requested indices = " << i << ", " << j << "\n\n";
  2087. X   }
  2088. X   if (action < 0) exit(1);
  2089. X}
  2090. X
  2091. X
  2092. XIndexException::IndexException(int i, const GeneralMatrix& A, Boolean)
  2093. X   : ProgramException(A)
  2094. X{
  2095. X   if (action)
  2096. X      { cout << "Element error: requested index (wrt 0) = " << i << "\n\n"; }
  2097. X   if (action < 0) exit(1);
  2098. X}
  2099. X
  2100. XIndexException::IndexException(int i, int j, const GeneralMatrix& A, Boolean)
  2101. X   : ProgramException(A)
  2102. X{
  2103. X   if (action)
  2104. X   {
  2105. X      cout << "Element error: requested indices (wrt 0) = " 
  2106. X         << i << ", " << j << "\n\n";
  2107. X   }
  2108. X   if (action < 0) exit(1);
  2109. X}
  2110. X
  2111. XInternalException::InternalException(char* c) : MatrixException(action)
  2112. X{
  2113. X   if (action) cout << c << "\n\n";
  2114. X   if (action < 0) exit(1);
  2115. X}
  2116. X
  2117. X
  2118. X
  2119. X
  2120. X/************************* ExeCounter functions *****************************/
  2121. X
  2122. X
  2123. X
  2124. Xint ExeCounter::nreports = 0;
  2125. X
  2126. XExeCounter::ExeCounter(int xl, int xf) : line(xl), fileid(xf), nexe(0) {}
  2127. X
  2128. XExeCounter::~ExeCounter()
  2129. X{
  2130. X   nreports++;
  2131. X   cout << nreports << "  " << fileid << "  " << line << "  " << nexe << "\n";
  2132. X}
  2133. X
  2134. X
  2135. X/**************************** error handler *******************************/
  2136. X
  2137. Xvoid MatrixErrorNoSpace(void* v) { if (!v) Throw(SpaceException()); }
  2138. X// throw exception if v is null
  2139. X
  2140. X
  2141. X
  2142. X/************************* test type manipulation ***************************/
  2143. X
  2144. X
  2145. X
  2146. X
  2147. X// These functions may cause problems for Glockenspiel 2.0c; they are used
  2148. X// only for testing so you can delete them
  2149. X
  2150. X
  2151. Xvoid TestTypeAdd()
  2152. X{
  2153. X   MatrixType list[] = { MatrixType::UT,
  2154. X                         MatrixType::LT,
  2155. X                         MatrixType::Rt,
  2156. X                         MatrixType::Sm,
  2157. X             MatrixType::Dg,
  2158. X             MatrixType::RV,
  2159. X             MatrixType::CV,
  2160. X                         MatrixType::BM,
  2161. X                         MatrixType::UB,
  2162. X             MatrixType::LB,
  2163. X             MatrixType::SB };
  2164. X
  2165. X   cout << "+     ";
  2166. X   for (int i=0; i<MatrixType::nTypes(); i++) cout << (char*)list[i] << " ";
  2167. X   cout << "\n";
  2168. X   for (i=0; i<MatrixType::nTypes(); i++)
  2169. X   {
  2170. X      cout << (char*)(list[i]) << " ";
  2171. X      for (int j=0; j<MatrixType::nTypes(); j++)
  2172. X     cout << (char*)(list[j]+list[i]) << " ";
  2173. X      cout << "\n";
  2174. X   }
  2175. X   cout << "\n";
  2176. X}
  2177. X
  2178. Xvoid TestTypeMult()
  2179. X{
  2180. X   MatrixType list[] = { MatrixType::UT,
  2181. X                         MatrixType::LT,
  2182. X                         MatrixType::Rt,
  2183. X                         MatrixType::Sm,
  2184. X                         MatrixType::Dg,
  2185. X                         MatrixType::RV,
  2186. X                         MatrixType::CV,
  2187. X                         MatrixType::BM,
  2188. X                         MatrixType::UB,
  2189. X                         MatrixType::LB,
  2190. X                         MatrixType::SB };
  2191. X   cout << "*     ";
  2192. X   for (int i=0; i<MatrixType::nTypes(); i++)
  2193. X      cout << (char*)list[i] << " ";
  2194. X   cout << "\n";
  2195. X   for (i=0; i<MatrixType::nTypes(); i++)
  2196. X   {
  2197. X      cout << (char*)list[i] << " ";
  2198. X      for (int j=0; j<MatrixType::nTypes(); j++)
  2199. X     cout << (char*)(list[j]*list[i]) << " ";
  2200. X      cout << "\n";
  2201. X   }
  2202. X   cout << "\n";
  2203. X}
  2204. X
  2205. Xvoid TestTypeOrder()
  2206. X{
  2207. X   MatrixType list[] = { MatrixType::UT,
  2208. X                         MatrixType::LT,
  2209. X                         MatrixType::Rt,
  2210. X                         MatrixType::Sm,
  2211. X                         MatrixType::Dg,
  2212. X                         MatrixType::RV,
  2213. X                         MatrixType::CV,
  2214. X                         MatrixType::BM,
  2215. X                         MatrixType::UB,
  2216. X                         MatrixType::LB,
  2217. X                         MatrixType::SB };
  2218. X   cout << ">=    ";
  2219. X   for (int i = 0; i<MatrixType::nTypes(); i++)
  2220. X      cout << (char*)list[i] << " ";
  2221. X   cout << "\n";
  2222. X   for (i=0; i<MatrixType::nTypes(); i++)
  2223. X   {
  2224. X      cout << (char*)list[i] << " ";
  2225. X      for (int j=0; j<MatrixType::nTypes(); j++)
  2226. X     cout << ((list[j]>=list[i]) ? "Yes   " : "No    ");
  2227. X      cout << "\n";
  2228. X   }
  2229. X   cout << "\n";
  2230. X}
  2231. X
  2232. X
  2233. X/************************* miscellanous errors ***************************/
  2234. X
  2235. X
  2236. Xvoid CroutMatrix::GetRow(MatrixRowCol&)
  2237. X   { Throw(NotDefinedException("GetRow","Crout")); }
  2238. Xvoid CroutMatrix::GetCol(MatrixRowCol&)
  2239. X   { Throw(NotDefinedException("GetCol","Crout")); }
  2240. Xvoid CroutMatrix::operator=(const BaseMatrix&)
  2241. X   { Throw(NotDefinedException("=","Crout")); }
  2242. Xvoid BandLUMatrix::GetRow(MatrixRowCol&)
  2243. X   { Throw(NotDefinedException("GetRow","BandLUMatrix")); }
  2244. Xvoid BandLUMatrix::GetCol(MatrixRowCol&)
  2245. X   { Throw(NotDefinedException("GetCol","BandLUMatrix")); }
  2246. Xvoid BandLUMatrix::operator=(const BaseMatrix&)
  2247. X   { Throw(NotDefinedException("=","BandLUMatrix")); }
  2248. X#ifdef TEMPS_DESTROYED_QUICKLY
  2249. X   ReturnMatrixX::ReturnMatrixX(const ReturnMatrixX& tm)
  2250. X     : gm(tm.gm) { Throw(ProgramException("ReturnMatrixX error")); }
  2251. X#endif
  2252. Xvoid GetSubMatrix::operator=(const BaseMatrix&)
  2253. X   { Throw(ProgramException("= not defined for submatrix; use <<")); }
  2254. X
  2255. END_OF_FILE
  2256. if test 9485 -ne `wc -c <'newmatex.cxx'`; then
  2257.     echo shar: \"'newmatex.cxx'\" unpacked with wrong size!
  2258. fi
  2259. # end of 'newmatex.cxx'
  2260. fi
  2261. echo shar: End of archive 5 \(of 7\).
  2262. cp /dev/null ark5isdone
  2263. MISSING=""
  2264. for I in 1 2 3 4 5 6 7 ; do
  2265.     if test ! -f ark${I}isdone ; then
  2266.     MISSING="${MISSING} ${I}"
  2267.     fi
  2268. done
  2269. if test "${MISSING}" = "" ; then
  2270.     echo You have unpacked all 7 archives.
  2271.     rm -f ark[1-9]isdone
  2272. else
  2273.     echo You still need to unpack the following archives:
  2274.     echo "        " ${MISSING}
  2275. fi
  2276. ##  End of shell archive.
  2277. exit 0
  2278.  
  2279. exit 0 # Just in case...
  2280.