home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume34 / newmat07 / part02 < prev    next >
Encoding:
Text File  |  1993-01-10  |  63.2 KB  |  1,949 lines

  1. Newsgroups: comp.sources.misc
  2. From: robertd@kauri.vuw.ac.nz (Robert Davies)
  3. Subject: v34i108:  newmat07 - A matrix package in C++, Part02/08
  4. Message-ID: <1993Jan11.152939.1846@sparky.imd.sterling.com>
  5. X-Md4-Signature: 7b18b257c557c47ef34992777777f095
  6. Date: Mon, 11 Jan 1993 15:29:39 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 108
  11. Archive-name: newmat07/part02
  12. Environment: C++
  13. Supersedes: newmat06: Volume 34, Issue 7-13
  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 2 (of 8)."
  22. # Contents:  boolean.h controlw.h ex_b.mak example.mak except.h
  23. #   include.h newmatap.h newmatb.txt newmatio.h newmatrc.h newmatrm.h
  24. #   precisio.h
  25. # Wrapped by robert@kea on Sun Jan 10 23:57:25 1993
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'boolean.h' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'boolean.h'\"
  29. else
  30. echo shar: Extracting \"'boolean.h'\" \(483 characters\)
  31. sed "s/^X//" >'boolean.h' <<'END_OF_FILE'
  32. X//$$ boolean.h                       Boolean class
  33. X
  34. X#ifndef Boolean_LIB
  35. X#define Boolean_LIB 0
  36. X
  37. Xclass Boolean
  38. X{
  39. X   int value;
  40. Xpublic:
  41. X   Boolean(const int b) { value = b ? 1 : 0; }
  42. X   Boolean(const void* b) { value = b ? 1 : 0; }
  43. X   Boolean() {}
  44. X   operator int() const { return value; }
  45. X   int operator!() const { return !value; }
  46. X   FREE_CHECK(Boolean);
  47. X};
  48. X
  49. X#ifndef __GNUG__
  50. X   const Boolean TRUE = 1;
  51. X   const Boolean FALSE = 0;
  52. X#else
  53. X#define FALSE 0
  54. X#define TRUE 1
  55. X#endif
  56. X
  57. X#endif
  58. END_OF_FILE
  59. if test 483 -ne `wc -c <'boolean.h'`; then
  60.     echo shar: \"'boolean.h'\" unpacked with wrong size!
  61. fi
  62. # end of 'boolean.h'
  63. fi
  64. if test -f 'controlw.h' -a "${1}" != "-c" ; then 
  65.   echo shar: Will not clobber existing file \"'controlw.h'\"
  66. else
  67. echo shar: Extracting \"'controlw.h'\" \(1495 characters\)
  68. sed "s/^X//" >'controlw.h' <<'END_OF_FILE'
  69. X//$$ controlw.h                Control word class
  70. X
  71. X#ifndef CONTROL_WORD_LIB
  72. X#define CONTROL_WORD_LIB 0
  73. X
  74. X// for organising an int as a series of bits which indicate whether an
  75. X// option is on or off.
  76. X
  77. Xclass ControlWord
  78. X{
  79. Xprotected:
  80. X   int cw;                                      // the control word
  81. Xpublic:
  82. X   ControlWord() : cw(0) {}                     // do nothing
  83. X   ControlWord(int i) : cw(i) {}                // load an integer
  84. X
  85. X      // select specific bits (for testing at least one set)
  86. X   ControlWord operator*(ControlWord i) const
  87. X      { return ControlWord(cw & i.cw); }
  88. X   void operator*=(ControlWord i)  { cw &= i.cw; }
  89. X
  90. X      // set bits
  91. X   ControlWord operator+(ControlWord i) const
  92. X      { return ControlWord(cw | i.cw); }
  93. X   void operator+=(ControlWord i)  { cw |= i.cw; }
  94. X
  95. X      // reset bits
  96. X   ControlWord operator-(ControlWord i) const
  97. X      { return ControlWord(cw - (cw & i.cw)); }
  98. X   void operator-=(ControlWord i) { cw -= (cw & i.cw); }
  99. X
  100. X      // check if all of selected bits set or reset
  101. X   Boolean operator>=(ControlWord i) const { return (cw & i.cw) == i.cw; }
  102. X   Boolean operator<=(ControlWord i) const { return (cw & i.cw) == cw; }
  103. X
  104. X      // flip selected bits
  105. X   ControlWord operator^(ControlWord i) const
  106. X      { return ControlWord(cw ^ i.cw); }
  107. X   ControlWord operator~() const { return ControlWord(~cw); }
  108. X
  109. X      // convert to integer
  110. X   int operator+() const { return cw; }
  111. X   int operator!() const { return cw==0; }
  112. X   FREE_CHECK(ControlWord)
  113. X};
  114. X
  115. X
  116. X#endif
  117. END_OF_FILE
  118. if test 1495 -ne `wc -c <'controlw.h'`; then
  119.     echo shar: \"'controlw.h'\" unpacked with wrong size!
  120. fi
  121. # end of 'controlw.h'
  122. fi
  123. if test -f 'ex_b.mak' -a "${1}" != "-c" ; then 
  124.   echo shar: Will not clobber existing file \"'ex_b.mak'\"
  125. else
  126. echo shar: Extracting \"'ex_b.mak'\" \(2428 characters\)
  127. sed "s/^X//" >'ex_b.mak' <<'END_OF_FILE'
  128. X.AUTODEPEND
  129. X
  130. X#        *Translator Definitions*
  131. XCC = bcc +EX_B.CFG
  132. XTASM = TASM
  133. XTLIB = tlib
  134. XTLINK = tlink
  135. XLIBPATH = C:\BORLANDC\LIB
  136. XINCLUDEPATH = C:\BORLANDC\INCLUDE
  137. X
  138. X
  139. X#        *Implicit Rules*
  140. X.c.obj:
  141. X  $(CC) -c {$< }
  142. X
  143. X.cpp.obj:
  144. X  $(CC) -c {$< }
  145. X
  146. X#        *List Macros*
  147. X
  148. X
  149. XEXE_dependencies =  \
  150. X bandmat.obj \
  151. X cholesky.obj \
  152. X evalue.obj \
  153. X example.obj \
  154. X except.obj \
  155. X fft.obj \
  156. X hholder.obj \
  157. X jacobi.obj \
  158. X newmat1.obj \
  159. X newmat2.obj \
  160. X newmat3.obj \
  161. X newmat4.obj \
  162. X newmat5.obj \
  163. X newmat6.obj \
  164. X newmat7.obj \
  165. X newmat8.obj \
  166. X newmat9.obj \
  167. X newmatex.obj \
  168. X newmatrm.obj \
  169. X sort.obj \
  170. X submat.obj \
  171. X svd.obj
  172. X
  173. X#        *Explicit Rules*
  174. Xex_b.exe: ex_b.cfg $(EXE_dependencies)
  175. X  $(TLINK) /v/x/c/P-/L$(LIBPATH) @&&|
  176. Xc0l.obj+
  177. Xbandmat.obj+
  178. Xcholesky.obj+
  179. Xevalue.obj+
  180. Xexample.obj+
  181. Xexcept.obj+
  182. Xfft.obj+
  183. Xhholder.obj+
  184. Xjacobi.obj+
  185. Xnewmat1.obj+
  186. Xnewmat2.obj+
  187. Xnewmat3.obj+
  188. Xnewmat4.obj+
  189. Xnewmat5.obj+
  190. Xnewmat6.obj+
  191. Xnewmat7.obj+
  192. Xnewmat8.obj+
  193. Xnewmat9.obj+
  194. Xnewmatex.obj+
  195. Xnewmatrm.obj+
  196. Xsort.obj+
  197. Xsubmat.obj+
  198. Xsvd.obj
  199. Xex_b
  200. X        # no map file
  201. Xemu.lib+
  202. Xmathl.lib+
  203. Xcl.lib
  204. X|
  205. X
  206. X
  207. X#        *Individual File Dependencies*
  208. Xbandmat.obj: ex_b.cfg bandmat.cxx 
  209. X    $(CC) -c bandmat.cxx
  210. X
  211. Xcholesky.obj: ex_b.cfg cholesky.cxx 
  212. X    $(CC) -c cholesky.cxx
  213. X
  214. Xevalue.obj: ex_b.cfg evalue.cxx 
  215. X    $(CC) -c evalue.cxx
  216. X
  217. Xexample.obj: ex_b.cfg example.cxx 
  218. X    $(CC) -c example.cxx
  219. X
  220. Xexcept.obj: ex_b.cfg except.cxx 
  221. X    $(CC) -c except.cxx
  222. X
  223. Xfft.obj: ex_b.cfg fft.cxx 
  224. X    $(CC) -c fft.cxx
  225. X
  226. Xhholder.obj: ex_b.cfg hholder.cxx 
  227. X    $(CC) -c hholder.cxx
  228. X
  229. Xjacobi.obj: ex_b.cfg jacobi.cxx 
  230. X    $(CC) -c jacobi.cxx
  231. X
  232. Xnewmat1.obj: ex_b.cfg newmat1.cxx 
  233. X    $(CC) -c newmat1.cxx
  234. X
  235. Xnewmat2.obj: ex_b.cfg newmat2.cxx 
  236. X    $(CC) -c newmat2.cxx
  237. X
  238. Xnewmat3.obj: ex_b.cfg newmat3.cxx 
  239. X    $(CC) -c newmat3.cxx
  240. X
  241. Xnewmat4.obj: ex_b.cfg newmat4.cxx 
  242. X    $(CC) -c newmat4.cxx
  243. X
  244. Xnewmat5.obj: ex_b.cfg newmat5.cxx 
  245. X    $(CC) -c newmat5.cxx
  246. X
  247. Xnewmat6.obj: ex_b.cfg newmat6.cxx 
  248. X    $(CC) -c newmat6.cxx
  249. X
  250. Xnewmat7.obj: ex_b.cfg newmat7.cxx 
  251. X    $(CC) -c newmat7.cxx
  252. X
  253. Xnewmat8.obj: ex_b.cfg newmat8.cxx 
  254. X    $(CC) -c newmat8.cxx
  255. X
  256. Xnewmat9.obj: ex_b.cfg newmat9.cxx 
  257. X    $(CC) -c newmat9.cxx
  258. X
  259. Xnewmatex.obj: ex_b.cfg newmatex.cxx 
  260. X    $(CC) -c newmatex.cxx
  261. X
  262. Xnewmatrm.obj: ex_b.cfg newmatrm.cxx 
  263. X    $(CC) -c newmatrm.cxx
  264. X
  265. Xsort.obj: ex_b.cfg sort.cxx 
  266. X    $(CC) -c sort.cxx
  267. X
  268. Xsubmat.obj: ex_b.cfg submat.cxx 
  269. X    $(CC) -c submat.cxx
  270. X
  271. Xsvd.obj: ex_b.cfg svd.cxx 
  272. X    $(CC) -c svd.cxx
  273. X
  274. X#        *Compiler Configuration File*
  275. Xex_b.cfg: ex_b.mak
  276. X  copy &&|
  277. X-ml
  278. X-wpro
  279. X-weas
  280. X-wpre
  281. X-I$(INCLUDEPATH)
  282. X-L$(LIBPATH)
  283. X-P
  284. X| ex_b.cfg
  285. X
  286. X
  287. END_OF_FILE
  288. if test 2428 -ne `wc -c <'ex_b.mak'`; then
  289.     echo shar: \"'ex_b.mak'\" unpacked with wrong size!
  290. fi
  291. # end of 'ex_b.mak'
  292. fi
  293. if test -f 'example.mak' -a "${1}" != "-c" ; then 
  294.   echo shar: Will not clobber existing file \"'example.mak'\"
  295. else
  296. echo shar: Extracting \"'example.mak'\" \(1654 characters\)
  297. sed "s/^X//" >'example.mak' <<'END_OF_FILE'
  298. X
  299. XOBJ  =  example.o                                          \
  300. X        cholesky.o evalue.o fft.o hholder.o jacobi.o       \
  301. X        newmat1.o newmat2.o newmat3.o newmat4.o newmat5.o  \
  302. X        newmat6.o newmat7.o newmat8.o newmatrm.o           \
  303. X        sort.o submat.o svd.o bandmat.o except.o newmatex.o
  304. X
  305. Xexample:      $(OBJ)
  306. X          g++ -o $@ $(OBJ) -lm
  307. X
  308. X%.o:          %.cxx
  309. X          g++ -c $*.cxx
  310. X
  311. Xnewmatxx:     include.h newmat.h boolean.h except.h
  312. X          rm -f newmatxx
  313. X          echo "main .h files uptodate?" > newmatxx
  314. X
  315. Xexcept.o:     except.h except.cxx
  316. X
  317. Xnewmatex.o:   newmatxx newmatex.cxx
  318. X
  319. Xexample.o:    newmatxx newmatap.h example.cxx
  320. X
  321. Xcholesky.o:   newmatxx cholesky.cxx
  322. X
  323. Xevalue.o:     newmatxx newmatrm.h precisio.h evalue.cxx
  324. X
  325. Xfft.o:        newmatxx newmatap.h fft.cxx
  326. X
  327. Xhholder.o:    newmatxx newmatap.h hholder.cxx
  328. X
  329. Xjacobi.o:     newmatxx precisio.h newmatrm.h jacobi.cxx
  330. X
  331. Xbandmat.o:    newmatxx newmatrc.h controlw.h bandmat.cxx
  332. X
  333. Xnewmat1.o:    newmatxx newmat1.cxx
  334. X
  335. Xnewmat2.o:    newmatxx newmatrc.h controlw.h newmat2.cxx
  336. X
  337. Xnewmat3.o:    newmatxx newmatrc.h controlw.h newmat3.cxx
  338. X
  339. Xnewmat4.o:    newmatxx newmatrc.h controlw.h newmat4.cxx
  340. X
  341. Xnewmat5.o:    newmatxx newmatrc.h controlw.h newmat5.cxx
  342. X
  343. Xnewmat6.o:    newmatxx newmatrc.h controlw.h newmat6.cxx
  344. X
  345. Xnewmat7.o:    newmatxx newmatrc.h controlw.h newmat7.cxx
  346. X
  347. Xnewmat8.o:    newmatxx newmatap.h newmat8.cxx
  348. X
  349. Xnewmat9.o:    newmatxx newmatrc.h controlw.h newmatio.h newmat9.cxx
  350. X
  351. Xnewmatrm.o:   newmatxx newmatrm.h newmatrm.cxx
  352. X
  353. Xsort.o:       newmatxx newmatap.h sort.cxx
  354. X
  355. Xsubmat.o:     newmatxx newmatrc.h controlw.h submat.cxx
  356. X
  357. Xsvd.o:        newmatxx newmatrm.h precisio.h svd.cxx
  358. X
  359. X
  360. X
  361. X
  362. X
  363. X
  364. X
  365. X
  366. X
  367. X
  368. X
  369. X
  370. END_OF_FILE
  371. if test 1654 -ne `wc -c <'example.mak'`; then
  372.     echo shar: \"'example.mak'\" unpacked with wrong size!
  373. fi
  374. # end of 'example.mak'
  375. fi
  376. if test -f 'except.h' -a "${1}" != "-c" ; then 
  377.   echo shar: Will not clobber existing file \"'except.h'\"
  378. else
  379. echo shar: Extracting \"'except.h'\" \(7543 characters\)
  380. sed "s/^X//" >'except.h' <<'END_OF_FILE'
  381. X//$$ except.h                          Exception handling classes
  382. X
  383. X// A set of classes to simulate exceptions in C++
  384. X//
  385. X//   Partially copied from Carlos Vidal's article in the C users' journal
  386. X//   September 1992, pp 19-28
  387. X//
  388. X//   Operations defined
  389. X//      Try {     }
  390. X//      Throw ( exception object )
  391. X//      Catch ( exception class ) {      }
  392. X//      CatchAll {      }
  393. X//      CatchAndThrow
  394. X//
  395. X//   All catch lists must end with a CatchAll or CatchAndThrow statement
  396. X//   but not both.
  397. X//
  398. X//   When exceptions are finally implemented replace Try, Throw, Catch,
  399. X//   CatchAll, CatchAndThrow by try, throw, catch, catch(...), and {}.
  400. X//
  401. X//   All exception classes must be derived from Exception, have no non-static
  402. X//   variables and must include functions
  403. X//
  404. X//      static long st_type()  { return 2; }
  405. X//      long type() const { return 2; }
  406. X//
  407. X//   where 2 is replaced by a prime number unique to the exception class.
  408. X//   See notes for use with levels of exceptions.
  409. X//
  410. X
  411. X#ifndef EXCEPTION_LIB
  412. X#define EXCEPTION_LIB
  413. X
  414. X#include <setjmp.h>
  415. X
  416. Xvoid Terminate();
  417. X
  418. X/*********** classes for setting up exceptions and reporting ***************/
  419. X
  420. Xclass Exception;
  421. X
  422. Xclass Tracer                                    // linked list showing how
  423. X{                                               // we got here
  424. X   char* entry;
  425. X   Tracer* previous;
  426. Xpublic:
  427. X   Tracer(char*);
  428. X   ~Tracer();
  429. X   void ReName(char*);
  430. X   friend class Exception;
  431. X};
  432. X
  433. X
  434. Xclass Exception                                 // The base exception class
  435. X{
  436. Xpublic:
  437. X   static Tracer* last;                         // points to Tracer list
  438. X   static long st_type() { return 1; }
  439. X   virtual long type() const { return 1; }
  440. X   static void PrintTrace(Boolean=FALSE);       // for printing trace
  441. X   friend class Tracer;
  442. X   Exception(int action);
  443. X};
  444. X
  445. X
  446. Xinline Tracer::Tracer(char* e)
  447. X   : entry(e), previous(Exception::last) { Exception::last = this; }
  448. X
  449. Xinline Tracer::~Tracer() { Exception::last = previous; }
  450. X
  451. Xinline void Tracer::ReName(char* e) { entry=e; }
  452. X
  453. X
  454. X
  455. X
  456. X
  457. X/************** the definitions of Try, Throw and Catch *******************/
  458. X
  459. X
  460. Xclass JumpItem;
  461. Xclass Janitor;
  462. X
  463. Xclass JumpBase         // pointer to a linked list of jmp_buf s
  464. X{
  465. Xpublic:
  466. X   static JumpItem *jl;
  467. X   static long type;                    // type id. of last exception
  468. X   static jmp_buf env;
  469. X};
  470. X
  471. Xclass JumpItem         // an item in a linked list of jmp_buf s
  472. X{
  473. Xpublic:
  474. X   JumpItem *ji;
  475. X   jmp_buf env;
  476. X   Tracer* trace;                     // to keep check on Tracer items
  477. X   Janitor* janitor;                  // list of items for cleanup
  478. X   JumpItem() : trace(0), janitor(0), ji(JumpBase::jl)
  479. X      { JumpBase::jl = this; }
  480. X   ~JumpItem() { JumpBase::jl = ji; }
  481. X};
  482. X
  483. Xvoid Throw(const Exception& exc);
  484. X
  485. Xvoid Throw();
  486. X
  487. X#define Try                                             \
  488. X      if (!setjmp( JumpBase::jl->env )) {               \
  489. X      JumpBase::jl->trace = Exception::last;            \
  490. X      JumpItem JI387256156;
  491. X
  492. X#define Catch(EXCEPTION)                                \
  493. X   } else if (JumpBase::type % EXCEPTION::st_type() == 0) {
  494. X
  495. X
  496. X#define CatchAll } else
  497. X
  498. X#define CatchAndThrow  } else Throw();
  499. X
  500. X
  501. X
  502. X/******************* cleanup heap following Throw ************************/
  503. X
  504. Xclass Janitor
  505. X{
  506. Xprotected:
  507. X   static Boolean do_not_link;                  // set when new is called
  508. X   Boolean OnStack;                             // false if created by new
  509. Xpublic:
  510. X   Janitor* NextJanitor;
  511. X   virtual void CleanUp() {}
  512. X   Janitor();
  513. X#ifdef __GNUC__
  514. X   virtual ~Janitor();                          // to stop warning messages
  515. X#else
  516. X   ~Janitor();
  517. X#endif
  518. X};
  519. X
  520. X
  521. X
  522. X
  523. X#ifdef DO_FREE_CHECK
  524. X// Routines for tracing whether new and delete calls are balanced
  525. X
  526. Xclass FreeCheck;
  527. X
  528. Xclass FreeCheckLink
  529. X{
  530. Xprotected:
  531. X   FreeCheckLink* next;
  532. X   void* ClassStore;
  533. X   FreeCheckLink();
  534. X   virtual void Report()=0;                   // print details of link
  535. X   friend class FreeCheck;
  536. X};
  537. X
  538. Xclass FCLClass : public FreeCheckLink         // for registering objects
  539. X{
  540. X   char* ClassName;
  541. X   FCLClass(void* t, char* name);
  542. X   void Report();
  543. X   friend class FreeCheck;
  544. X};
  545. X
  546. Xclass FCLRealArray : public FreeCheckLink     // for registering real arrays
  547. X{
  548. X   char* Operation;
  549. X   int size;
  550. X   FCLRealArray(void* t, char* o, int s);
  551. X   void Report();
  552. X   friend class FreeCheck;
  553. X};
  554. X
  555. Xclass FCLIntArray : public FreeCheckLink     // for registering int arrays
  556. X{
  557. X   char* Operation;
  558. X   int size;
  559. X   FCLIntArray(void* t, char* o, int s);
  560. X   void Report();
  561. X   friend class FreeCheck;
  562. X};
  563. X
  564. X
  565. Xclass FreeCheck
  566. X{
  567. X   static FreeCheckLink* next;
  568. Xpublic:
  569. X   static void Register(void*, char*);
  570. X   static void DeRegister(void*, char*);
  571. X   static void RegisterR(void*, char*, int);
  572. X   static void DeRegisterR(void*, char*, int);
  573. X   static void RegisterI(void*, char*, int);
  574. X   static void DeRegisterI(void*, char*, int);
  575. X   static void Status();
  576. X   friend class FreeCheckLink;
  577. X   friend class FCLClass;
  578. X   friend class FCLRealArray;
  579. X   friend class FCLIntArray;
  580. X};
  581. X
  582. X#define FREE_CHECK(Class)                                                  \
  583. Xpublic:                                                                    \
  584. X   void* operator new(size_t size)                                         \
  585. X   {                                                                       \
  586. X      void* t = ::operator new(size); FreeCheck::Register(t,#Class);       \
  587. X      return t;                                                            \
  588. X   }                                                                       \
  589. X   void operator delete(void* t)                                           \
  590. X   { FreeCheck::DeRegister(t,#Class); ::operator delete(t); }
  591. X
  592. X#define NEW_DELETE(Class)                                                  \
  593. Xpublic:                                                                    \
  594. X   void* operator new(size_t size)                                         \
  595. X   {                                                                       \
  596. X      do_not_link=TRUE;                                                    \
  597. X      void* t = ::operator new(size); FreeCheck::Register(t,#Class);       \
  598. X      return t;                                                            \
  599. X   }                                                                       \
  600. X   void operator delete(void* t)                                           \
  601. X   { FreeCheck::DeRegister(t,#Class); ::operator delete(t); }
  602. X
  603. X#define MONITOR_REAL_NEW(Operation, Size, Pointer)                         \
  604. X   FreeCheck::RegisterR(Pointer, Operation, Size);
  605. X#define MONITOR_INT_NEW(Operation, Size, Pointer)                          \
  606. X   FreeCheck::RegisterI(Pointer, Operation, Size);
  607. X#define MONITOR_REAL_DELETE(Operation, Size, Pointer)                      \
  608. X   FreeCheck::DeRegisterR(Pointer, Operation, Size);
  609. X#define MONITOR_INT_DELETE(Operation, Size, Pointer)                       \
  610. X   FreeCheck::DeRegisterI(Pointer, Operation, Size);
  611. X#else
  612. X#define FREE_CHECK(Class) public:
  613. X#define MONITOR_REAL_NEW(Operation, Size, Pointer) {}
  614. X#define MONITOR_INT_NEW(Operation, Size, Pointer) {}
  615. X#define MONITOR_REAL_DELETE(Operation, Size, Pointer) {}
  616. X#define MONITOR_INT_DELETE(Operation, Size, Pointer) {}
  617. X
  618. X
  619. X#define NEW_DELETE(Class)                                                  \
  620. Xpublic:                                                                    \
  621. X   void* operator new(size_t size)                                         \
  622. X   { do_not_link=TRUE; void* t = ::operator new(size); return t; }         \
  623. X   void operator delete(void* t) { ::operator delete(t); }
  624. X
  625. X#endif
  626. X
  627. X
  628. X
  629. X
  630. X#endif
  631. X
  632. X
  633. X
  634. X
  635. END_OF_FILE
  636. if test 7543 -ne `wc -c <'except.h'`; then
  637.     echo shar: \"'except.h'\" unpacked with wrong size!
  638. fi
  639. # end of 'except.h'
  640. fi
  641. if test -f 'include.h' -a "${1}" != "-c" ; then 
  642.   echo shar: Will not clobber existing file \"'include.h'\"
  643. else
  644. echo shar: Extracting \"'include.h'\" \(3401 characters\)
  645. sed "s/^X//" >'include.h' <<'END_OF_FILE'
  646. X//$$ include.h           include files required by various versions of C++
  647. X
  648. X//#define Glock                         // for Glockenspiel on the PC
  649. X//#define ATandT                        // for AT&T C++ on a Sun
  650. X
  651. X//#define SETUP_C_SUBSCRIPTS              // allow element access via A[i][j]
  652. X
  653. X
  654. X#define TEMPS_DESTROYED_QUICKLY         // for compiler that delete
  655. X                    // temporaries too quickly
  656. X
  657. X//#define DO_FREE_CHECK                   // check news and deletes balance
  658. X
  659. X#define USING_DOUBLE                    // elements of type double
  660. X//#define USING_FLOAT                   // elements of type float
  661. X
  662. X#define Version21                       // version 2.1 or later
  663. X
  664. X
  665. X#ifdef _MSC_VER                         // Microsoft
  666. X   #include <stdlib.h>
  667. X
  668. X   typedef int jmp_buf[9];
  669. X   extern "C"
  670. X   {
  671. X      int __cdecl setjmp(jmp_buf);
  672. X      void __cdecl longjmp(jmp_buf, int);
  673. X   }
  674. X
  675. X   #ifdef WANT_STREAM
  676. X      #include <iostream.h>
  677. X      #include <iomanip.h>
  678. X   #endif
  679. X   #ifdef WANT_MATH
  680. X      #include <math.h>
  681. X      #include <float.h>
  682. X   #endif
  683. X#endif
  684. X
  685. X#ifdef __ZTC__                          // Zortech
  686. X   #include <stdlib.h>
  687. X   #ifdef WANT_STREAM
  688. X      #include <stream.hpp>
  689. X      #define flush ""                  // doesn't have io manipulators
  690. X   #endif
  691. X   #ifdef WANT_MATH
  692. X      #include <math.h>
  693. X      #include <float.h>
  694. X   #endif
  695. X#endif
  696. X
  697. X#ifdef __BCPLUSPLUS__                   // Borland
  698. X   #include <stdlib.h>
  699. X   #ifdef WANT_STREAM
  700. X      #include <iostream.h>
  701. X      #include <iomanip.h>
  702. X   #endif
  703. X   #ifdef WANT_MATH
  704. X      #include <math.h>
  705. X      #define SystemV                   // optional in Borland
  706. X      #include <values.h>               // Borland has both float and values
  707. X   #endif
  708. X   #undef __TURBOC__                    // also defined in Borland
  709. X#endif
  710. X
  711. X#ifdef __TURBOC__                       // Turbo
  712. X   #include <stdlib.h>
  713. X   #ifdef WANT_STREAM
  714. X      #include <iostream.h>
  715. X      #include <iomanip.h>
  716. X   #endif
  717. X   #ifdef WANT_MATH
  718. X      #include <math.h>
  719. X      #define SystemV                   // optional in Turbo
  720. X      #include <values.h>
  721. X   #endif
  722. X#endif
  723. X
  724. X#ifdef ATandT                           // AT&T
  725. X#include <stdlib.h>
  726. X#ifdef WANT_STREAM
  727. X#include <iostream.h>
  728. X#include <iomanip.h>
  729. X#endif
  730. X#ifdef WANT_MATH
  731. X#include <math.h>
  732. X#define SystemV                         // must use System V on my Sun
  733. X#include <values.h>                     //    as float.h is not present
  734. X#endif
  735. X#endif
  736. X
  737. X#ifdef __GNUG__                         // Gnu C++
  738. X   #include <stdlib.h>
  739. X   #ifdef WANT_STREAM
  740. X      #include <stream.h>               // no iomanip in G++
  741. X      #define flush ""
  742. X   #endif
  743. X   #ifdef WANT_MATH
  744. X      #include <math.h>
  745. X      #include <float.h>
  746. X   #endif
  747. X   #ifndef TEMPS_DESTROYED_QUICKLY
  748. X      #define TEMPS_DESTROYED_QUICKLY
  749. X   #endif
  750. X#endif
  751. X
  752. X#ifdef Glock                            // Glockenspiel
  753. X   extern "C" { #include <stdlib.h> }
  754. X   #ifdef WANT_STREAM
  755. X      #include <stream.hxx>
  756. X      #include <iomanip.hxx>
  757. X   #endif
  758. X   #ifdef WANT_MATH
  759. X      extern "C" { #include <math.h> }
  760. X      extern "C" { #include <float.h> }
  761. X   #endif
  762. X   #define NO_LONG_NAMES                // very long names don't work
  763. X#endif
  764. X
  765. X
  766. X
  767. X#ifdef USING_FLOAT                      // set precision type to float
  768. Xtypedef float Real;
  769. Xtypedef double long_Real;
  770. X#endif
  771. X
  772. X#ifdef USING_DOUBLE                     // set precision type to double
  773. Xtypedef double Real;
  774. Xtypedef long double long_Real;
  775. X#endif
  776. X
  777. X
  778. END_OF_FILE
  779. if test 3401 -ne `wc -c <'include.h'`; then
  780.     echo shar: \"'include.h'\" unpacked with wrong size!
  781. fi
  782. # end of 'include.h'
  783. fi
  784. if test -f 'newmatap.h' -a "${1}" != "-c" ; then 
  785.   echo shar: Will not clobber existing file \"'newmatap.h'\"
  786. else
  787. echo shar: Extracting \"'newmatap.h'\" \(2830 characters\)
  788. sed "s/^X//" >'newmatap.h' <<'END_OF_FILE'
  789. X//$$ newmatap.h           definition file for matrix package applications
  790. X
  791. X// Copyright (C) 1991,2,3: R B Davies
  792. X
  793. X#ifndef MATRIXAP_LIB
  794. X#define MATRIXAP_LIB 0
  795. X
  796. X#include "newmat.h"
  797. X
  798. X
  799. X/**************************** applications *****************************/
  800. X
  801. X
  802. Xvoid HHDecompose(Matrix&, LowerTriangularMatrix&);
  803. X
  804. Xvoid HHDecompose(const Matrix&, Matrix&, Matrix&);
  805. X
  806. XReturnMatrix Cholesky(const SymmetricMatrix&);
  807. X
  808. XReturnMatrix Cholesky(const SymmetricBandMatrix&);
  809. X
  810. X#ifndef __GNUG__
  811. Xvoid SVD(const Matrix&, DiagonalMatrix&, Matrix&, Matrix&,
  812. X    Boolean=TRUE, Boolean=TRUE);
  813. X#else
  814. Xvoid SVD(const Matrix&, DiagonalMatrix&, Matrix&, Matrix&,
  815. X    Boolean=(Boolean)TRUE, Boolean=(Boolean)TRUE);
  816. X#endif
  817. X
  818. X
  819. Xvoid SVD(const Matrix&, DiagonalMatrix&);
  820. X
  821. X#ifndef __GNUG__
  822. Xinline void SVD(const Matrix& A, DiagonalMatrix& D, Matrix& U,
  823. X   Boolean withU = TRUE) { SVD(A, D, U, U, withU, FALSE); }
  824. X#else
  825. Xinline void SVD(const Matrix& A, DiagonalMatrix& D, Matrix& U,
  826. X   Boolean withU = (Boolean)TRUE) { SVD(A, D, U, U, withU, FALSE); }
  827. X#endif
  828. X
  829. Xvoid Jacobi(const SymmetricMatrix&, DiagonalMatrix&);
  830. X
  831. Xvoid Jacobi(const SymmetricMatrix&, DiagonalMatrix&, SymmetricMatrix&);
  832. X
  833. Xvoid Jacobi(const SymmetricMatrix&, DiagonalMatrix&, Matrix&);
  834. X
  835. X#ifndef __GNUG__
  836. Xvoid Jacobi(const SymmetricMatrix&, DiagonalMatrix&, SymmetricMatrix&,
  837. X   Matrix&, Boolean=TRUE);
  838. X#else
  839. Xvoid Jacobi(const SymmetricMatrix&, DiagonalMatrix&, SymmetricMatrix&,
  840. X   Matrix&, Boolean=(Boolean)TRUE);
  841. X#endif
  842. X
  843. Xvoid EigenValues(const SymmetricMatrix&, DiagonalMatrix&);
  844. X
  845. Xvoid EigenValues(const SymmetricMatrix&, DiagonalMatrix&, SymmetricMatrix&);
  846. X
  847. Xvoid EigenValues(const SymmetricMatrix&, DiagonalMatrix&, Matrix&);
  848. X
  849. Xclass SymmetricEigenAnalysis
  850. X// not implemented yet
  851. X{
  852. Xpublic:
  853. X   SymmetricEigenAnalysis(const SymmetricMatrix&);
  854. Xprivate:
  855. X   DiagonalMatrix diag;
  856. X   DiagonalMatrix offdiag;
  857. X   SymmetricMatrix backtransform;
  858. X   FREE_CHECK(SymmetricEigenAnalysis)
  859. X};
  860. X
  861. Xvoid SortAscending(GeneralMatrix&);
  862. X
  863. Xvoid SortDescending(GeneralMatrix&);
  864. X
  865. X
  866. Xvoid FFT(const ColumnVector&, const ColumnVector&,
  867. X   ColumnVector&, ColumnVector&);
  868. X
  869. Xvoid FFTI(const ColumnVector&, const ColumnVector&,
  870. X   ColumnVector&, ColumnVector&);
  871. X
  872. Xvoid RealFFT(const ColumnVector&, ColumnVector&, ColumnVector&);
  873. X
  874. Xvoid RealFFTI(const ColumnVector&, const ColumnVector&, ColumnVector&);
  875. X
  876. X
  877. X/********************** linear equation solving ****************************/
  878. X
  879. Xclass LinearEquationSolver : public BaseMatrix
  880. X{
  881. X   GeneralMatrix* gm;
  882. X   int search(const BaseMatrix*) const { return 0; }
  883. X   friend class BaseMatrix;
  884. Xpublic:
  885. X   LinearEquationSolver(const BaseMatrix& bm);
  886. X   ~LinearEquationSolver() { delete gm; }
  887. X   void CleanUp() { delete gm; } 
  888. X   GeneralMatrix* Evaluate(MatrixType) { return gm; }
  889. X   // probably should have an error message if MatrixType != UnSp
  890. X   NEW_DELETE(LinearEquationSolver)
  891. X};
  892. X
  893. X
  894. X
  895. X
  896. X
  897. X#endif
  898. END_OF_FILE
  899. if test 2830 -ne `wc -c <'newmatap.h'`; then
  900.     echo shar: \"'newmatap.h'\" unpacked with wrong size!
  901. fi
  902. # end of 'newmatap.h'
  903. fi
  904. if test -f 'newmatb.txt' -a "${1}" != "-c" ; then 
  905.   echo shar: Will not clobber existing file \"'newmatb.txt'\"
  906. else
  907. echo shar: Extracting \"'newmatb.txt'\" \(24907 characters\)
  908. sed "s/^X//" >'newmatb.txt' <<'END_OF_FILE'
  909. X//$$ newmatb.txt                                   Design
  910. X
  911. X
  912. XCopyright (C) 1991,2,3: R B Davies
  913. X
  914. XPlease treat this as an academic publication. You can use the ideas but
  915. Xplease acknowledge in any publication.
  916. X
  917. X
  918. X
  919. X                      Notes on the design of the package
  920. X                      ==================================
  921. X
  922. XContents
  923. X========
  924. X
  925. XWhat this is package for
  926. XWhat size of matrices?
  927. XAllow matrix expressions?
  928. XWhich matrix types?
  929. XWhat element types?
  930. XNaming convention
  931. XRow and Column index ranges
  932. XStructure of matrix objects
  933. XData storage - one block or several
  934. XData storage - by row or by column or other
  935. XStorage of symmetric matrices
  936. XElement access - method and checking
  937. XUse iterators?
  938. XMemory management - reference counting or status variable?
  939. XEvaluation of expressions - use two stage method?
  940. XHow to overcome an explosion in number of operations
  941. XDestruction of temporaries
  942. XA calculus of matrix types
  943. XError handling
  944. XSparse matrices
  945. XComplex matrices
  946. X
  947. X
  948. XI describe some of the ideas behind this package, some of the decisions
  949. Xthat I needed to make and give some details about the way it works. You
  950. Xdon't need to read this file in order to use the package.
  951. X
  952. XI don't think it is obvious what is the best way of going about
  953. Xstructuring a matrix package. And I don't think you can figure this
  954. Xout with "thought" experiments. Different people have to try out
  955. Xdifferent approaches. And someone else may have to figure out which is
  956. Xbest. Or, more likely, the ultimate packages will lift some ideas from
  957. Xeach of a variety of trial packages. So, I don't claim my package is an
  958. X"ultimate" package, but simply a trial of a number of ideas.
  959. X
  960. XBut I do hope it will meet the immediate requirements of some people who
  961. Xneed to carry out matrix calculations.
  962. X
  963. X
  964. XWhat this is package for
  965. X------------------------
  966. X
  967. XThe package is used for the manipulation of matrices, including the
  968. Xstandard operations such as multiplication as understood by numerical
  969. Xanalysts, engineers and mathematicians. A matrix is a two dimensional
  970. Xarray of numbers. However, very special operations such as matrix
  971. Xmultiplication are defined specifically for matrices. This means that a
  972. X"matrix" package tends to be different from a general "array" package.
  973. X
  974. XI see a matrix package as providing the following
  975. X
  976. X1.   Evaluation of matrix expressions in a form familiar to
  977. X     scientists and engineers. For example  A = B * (C + D.t());
  978. X2.   Access to the elements of a matrix;
  979. X3.   Access to submatrices;
  980. X4.   Common elementary matrix functions such as determinant and trace;
  981. X5.   A platform for developing advanced matrix functions such as eigen-
  982. X     value analysis;
  983. X6.   Good efficiency and storage management;
  984. X7.   Graceful exit from errors (I don't provide this yet).
  985. X
  986. XIt may also provide
  987. X
  988. X8.   A variety of types of elements (eg real and complex);
  989. X9.   A variety of types of matrices (eg rectangular and symmetric).
  990. X
  991. XIn contrast an array package should provide
  992. X
  993. X1'.  Arrays can be copied with a single instruction; may have some
  994. X     arithmetic operations, say + - and scalar + - * /, it may provide
  995. X     matrix multiplication as a function;
  996. X2'.  High speed access to elements directly and with iterators;
  997. X3'.  Access to subarrays and rows (and columns?);
  998. X6'.  Good efficiency and storage management;
  999. X7'.  Graceful exit from errors;
  1000. X8'.  A variety of types of elements (eg real and complex);
  1001. X9'.  One, two and three dimensional arrays, at least, with starting
  1002. X     points of the indices set by user; may have arrays with ragged
  1003. X     rows.
  1004. X
  1005. XIt may be possible to amalgamate these two sets of requirements to some
  1006. Xextent. However my package is definitely oriented towards the first set.
  1007. X
  1008. XEven within the bounds set by the first set of requirements there is a
  1009. Xsubstantial opportunity for variation between what different matrix
  1010. Xpackages might provide.
  1011. X
  1012. XIt is not possible to build a matrix package that will meet everyone's
  1013. Xrequirements. In many cases if you put in one facility, you impose
  1014. Xoverheads on everyone using the package. This both is storage required
  1015. Xfor the program and in efficiency. Likewise a package that is optimised
  1016. Xtowards handling large matrices is likely to become less efficient for
  1017. Xvery small matrices where the administration time for the matrix may
  1018. Xbecome significant compared with the time to carry out the operations.
  1019. X
  1020. XIt is better to provide a variety of packages (hopefully compatible) so
  1021. Xthat most users can find one that meets their requirements. This package
  1022. Xis intended to be one of these packages; but not all of them.
  1023. X
  1024. XSince my background is in statistical methods, this package is oriented
  1025. Xtowards the kinds things you need for statistical analyses.
  1026. X
  1027. X
  1028. XWhat size of matrices?
  1029. X----------------------
  1030. X
  1031. XA matrix package may target small matrices (say 3 x 3), or medium sized
  1032. Xmatrices, or very large matrices. A package targeting very small
  1033. Xmatrices will seek to minimise administration. A package for medium
  1034. Xsized or very large matrices can spend more time on administration in
  1035. Xorder to conserve space or optimise the evaluation of expressions. A
  1036. Xpackage for very large matrices will need to pay special attention to
  1037. Xstorage and numerical properties.
  1038. X
  1039. XThis package is designed for medium sized matrices. This means it is
  1040. Xworth introducing some optimisations, but I don't have to worry about
  1041. Xthe 64K limit that some compilers impose.
  1042. X
  1043. X
  1044. XAllow matrix expressions?
  1045. X-------------------------
  1046. X
  1047. XI want to be able to write matrix expressions the way I would on paper.
  1048. XSo if I want to multiply two matrices and then add the transpose of a
  1049. Xthird one I can write something like
  1050. X
  1051. X   X = A * B + C.t();
  1052. X
  1053. XI want this expression to be evaluated with close to the same efficiency
  1054. Xas a hand-coded version. This is not so much of a problem with
  1055. Xexpressions including a multiply since the multiply will dominate the
  1056. Xtime. However, it is not so easy to achieve with expressions with just +
  1057. Xand - .
  1058. X
  1059. XA second requirement is that temporary matrices generated during the
  1060. Xevaluation of an expression are destroyed as quickly as possible.
  1061. X
  1062. XA desirable feature is that a certain amount of "intelligence" be
  1063. Xdisplayed in the evaluation of an expression. For example, in the
  1064. Xexpression
  1065. X
  1066. X   X = A.i() * B;
  1067. X
  1068. Xwhere i() denotes inverse, it would be desirable if the inverse wasn't
  1069. Xexplicitly calculated.
  1070. X
  1071. X
  1072. XWhich matrix types?
  1073. X-------------------
  1074. X
  1075. XAs well as the usual rectangular matrices, matrices occuring repeatedly
  1076. Xin numerical calculations are upper and lower triangular matrices,
  1077. Xsymmetric matrices and diagonal matrices. This is particularly the case
  1078. Xin calculations involving least squares and eigenvalue calculations. So
  1079. Xas a first stage these were the types I decided to include.
  1080. X
  1081. XIt is also necessary to have types row vector and column vector. In a
  1082. X"matrix" package, in contrast to an "array" package, it is necessary to
  1083. Xhave both these types since they behave differently in matrix
  1084. Xexpressions. The vector types can be derived for the rectangular matrix
  1085. Xtype, so having them does not greatly increase the complexity of the
  1086. Xpackage.
  1087. X
  1088. XThe problem with having several matrix types is the number of versions
  1089. Xof the binary operators one needs. If one has 5 distinct matrix types
  1090. Xthen a simple package will need 25 versions of each of the binary
  1091. Xoperators. In fact, we can evade this problem, but at the cost of some
  1092. Xcomplexity.
  1093. X
  1094. X
  1095. XWhat element types?
  1096. X-------------------
  1097. X
  1098. XIdeally we would allow element types double, float, complex and int, at
  1099. Xleast. It would be reasonably easy, using templates or equivalent, to
  1100. Xprovide a package which could handle a variety of element types.
  1101. XHowever, as soon as one starts implementing the binary operators between
  1102. Xmatrices with different element types, again one gets an explosion in
  1103. Xthe number of operations one needs to consider. Hence I decided to
  1104. Ximplement only one element type. But the user can decide whether this is
  1105. Xfloat or double. The package assumes elements are of type Real. The user
  1106. Xtypedefs Real to float or double.
  1107. X
  1108. XIn retrospect, it would not be too hard to include matrices with complex
  1109. Xmatrix type.
  1110. X
  1111. XIt might also be worth including symmetric and triangular matrices with
  1112. Xextra precision elements (double or long double) to be used for storage
  1113. Xonly and with a minimum of operations defined. These would be used for
  1114. Xaccumulating the results of sums of squares and product matrices or
  1115. Xmultistage Householder triangularisations.
  1116. X
  1117. X
  1118. XNaming convention
  1119. X-----------------
  1120. X
  1121. XHow are classes and public member functions to be named? As a general
  1122. Xrule I have spelt identifiers out in full with individual words being
  1123. Xcapitalised. For example "UpperTriangularMatrix". If you don't like this
  1124. Xyou can #define or typedef shorter names. This convention means you can
  1125. Xselect an abbreviation scheme that makes sense to you.
  1126. X
  1127. XThe convention causes problems for Glockenspiel C++ on a PC feeding into
  1128. XMicrosoft C. The names Glockenspiel generates exceed the the 32
  1129. Xcharacters recognised by Microsoft C and ambiguities result. So it is
  1130. Xnecessary to #define shorter names.
  1131. X
  1132. XExceptions to the general rule are the functions for transpose and
  1133. Xinverse. To make matrix expressions more like the corresponding
  1134. Xmathematical formulae, I have used the single letter abbreviations, t()
  1135. Xand i() .
  1136. X
  1137. X
  1138. XRow and Column index ranges
  1139. X---------------------------
  1140. X
  1141. XIn mathematical work matrix subscripts usually start at one. In C, array
  1142. Xsubscripts start at zero. In Fortran, they start at one. Possibilities
  1143. Xfor this package were to make them start at 0 or 1 or be arbitrary.
  1144. XAlternatively one could specify an "index set" for indexing the rows and
  1145. Xcolumns of a matrix. One would be able to add or multiply matrices only
  1146. Xif the appropriate row and column index sets were identical.
  1147. X
  1148. XIn fact, I adopted the simpler convention of making the rows and columns
  1149. Xof a matrix be indexed by an integer starting at one, following the
  1150. Xtraditional convention. In an earlier version of the package I had them
  1151. Xstarting at zero, but even I was getting mixed up when trying to use
  1152. Xthis earlier package. So I reverted to the more usual notation.
  1153. X
  1154. X
  1155. XStructure of matrix objects
  1156. X---------------------------
  1157. X
  1158. XEach matrix object contains the basic information such as the number of
  1159. Xrows and columns and a status variable plus a pointer to the data
  1160. Xarray which is on the heap.
  1161. X
  1162. X
  1163. XData storage - one block or several
  1164. X-----------------------------------
  1165. X
  1166. XIn this package the elements of the matrix are stored as a single array.
  1167. XAlternatives would have been to store each row as a separate array or a
  1168. Xset of adjacent rows as a separate array. The present solution
  1169. Xsimplifies the program but limits the size of matrices in systems that
  1170. Xhave a 64k byte (or other) limit on the size of arrays. The large arrays
  1171. Xmay also cause problems for memory management in smaller machines.
  1172. X
  1173. X
  1174. XData storage - by row or by column or other
  1175. X-------------------------------------------
  1176. X
  1177. XIn Fortran two dimensional arrays are stored by column. In most other
  1178. Xsystems they are stored by row. I have followed this later convention.
  1179. XThis makes it easier to interface with other packages written in C but
  1180. Xharder to interface with those written in Fortran.
  1181. X
  1182. XThis may have been a wrong decision. Most work on the efficient
  1183. Xmanipulation of large matrices is being done in Fortran. It would have
  1184. Xbeen easier to use this work if I had adopted the Fortan convention.
  1185. X
  1186. XAn alternative would be to store the elements by mid-sized rectangular
  1187. Xblocks. This might impose less strain on memory management when one
  1188. Xneeds to access both rows and columns.
  1189. X
  1190. X
  1191. XStorage of symmetric matrices
  1192. X-----------------------------
  1193. X
  1194. XSymmetric matrices are stored as lower triangular matrices. The decision
  1195. Xwas pretty arbitrary, but it does slightly simplify the Cholesky
  1196. Xdecomposition program.
  1197. X
  1198. X
  1199. XElement access - method and checking
  1200. X------------------------------------
  1201. X
  1202. XWe want to be able to use the notation A(i,j) to specify the (i,j)-th
  1203. Xelement of a matrix. This is the way mathematicians expect to address
  1204. Xthe elements of matrices. I consider the notation A[i][j] totally alien.
  1205. XHowever I may include it in a later version to help people converting
  1206. Xfrom C. There are two ways of working out the address of A(i,j). One is
  1207. Xusing a "dope" vector which contains the first address of each row.
  1208. XAlternatively you can calculate the address using the formula
  1209. Xappropriate for the structure of A. I use this second approach. It is
  1210. Xprobably slower, but saves worrying about an extra bit of storage. The
  1211. Xother question is whether to check for i and j being in range. I do
  1212. Xcarry out this check following years of experience with both systems
  1213. Xthat do and systems that don't do this check.
  1214. X
  1215. XI would hope that the routines I supply with this package will reduce
  1216. Xyour need to access elements of matrices so speed of access is not a
  1217. Xhigh priority.
  1218. X
  1219. X
  1220. XUse iterators?
  1221. X--------------
  1222. X
  1223. XIterators are an alternative way of providing fast access to the
  1224. Xelements of an array or matrix when they are to be accessed
  1225. Xsequentially. They need to be customised for each type of matrix. I have
  1226. Xnot implemented iterators in this package, although some iterator like
  1227. Xfunctions are used for some row and column functions.
  1228. X
  1229. X
  1230. XMemory management - reference counting or status variable?
  1231. X----------------------------------------------------------
  1232. X
  1233. XConsider the instruction
  1234. X
  1235. X   X = A + B + C;
  1236. X
  1237. XTo evaluate this a simple program will add A to B putting the total in a
  1238. Xtemporary T1. Then it will add T1 to C creating another temporary T2
  1239. Xwhich will be copied into X. T1 and T2 will sit around till the end of
  1240. Xthe block. It would be faster if the program recognised that T1 was
  1241. Xtemporary and stored the sum of T1 and C back into T1 instead of
  1242. Xcreating T2 and then avoided the final copy by just assigning the
  1243. Xcontents of T1 to X rather than copying. In this case there will be no
  1244. Xtemporaries requiring deletion. (More precisely there will be a header
  1245. Xto be deleted but no contents).
  1246. X
  1247. XFor an instruction like
  1248. X
  1249. X   X = (A * B) + (C * D);
  1250. X
  1251. Xwe can't easily avoid one temporary being left over, so we would like
  1252. Xthis temporary deleted as quickly as possible.
  1253. X
  1254. XI provide the functionality for doing this by attaching a status
  1255. Xvariable to each matrix. This indicates if the matrix is temporary so
  1256. Xthat its memory is available for recycling or deleting. Any matrix
  1257. Xoperation checks the status variables of the matrices it is working with
  1258. Xand recycles or deletes any temporary memory.
  1259. X
  1260. XAn alternative or additional approach would be to use delayed copying.
  1261. XIf a program requests a matrix to be copied, the copy is delayed until
  1262. Xan instruction is executed which modifies the memory of either the
  1263. Xoriginal matrix or the copy. This saves the unnecessary copying in the
  1264. Xprevious examples. However, it does not provide the additional
  1265. Xfunctionality of my approach.
  1266. X
  1267. XIt would be possible to have both delayed copy and tagging temporaries,
  1268. Xbut this seemed an unnecessary complexity. In particular delayed copy
  1269. Xmechanisms seem to require two calls to the heap manager, using extra
  1270. Xtime and making building a memory compacting mechanism more difficult.
  1271. X
  1272. X
  1273. XEvaluation of expressions - use two stage method?
  1274. X-------------------------------------------------
  1275. X
  1276. XConsider the instruction
  1277. X
  1278. X   X = B - X;
  1279. X
  1280. XThe simple program will subtract X from B, store the result in a
  1281. Xtemporary T1 and copy T1 into X. It would be faster if the program
  1282. Xrecognised that the result could be stored directly into X. This would
  1283. Xhappen automatically if the program could look at the instruction first
  1284. Xand mark X as temporary.
  1285. X
  1286. XC programmers would expect to avoid the same problem with
  1287. X
  1288. X   X = X - B;
  1289. X
  1290. Xby using an operator -= (which I haven't provided, yet)
  1291. X
  1292. X   X -= B;
  1293. X
  1294. XHowever this is an unnatural notation for non C users and it is much
  1295. Xnicer to write
  1296. X
  1297. X   X = X - B;
  1298. X
  1299. Xand know that the program will carry out the simplification.
  1300. X
  1301. XAnother example where this intelligent analysis of an instruction is
  1302. Xhelpful is in
  1303. X
  1304. X   X = A.i() * B;
  1305. X
  1306. Xwhere i() denotes inverse. Numerical analysts know it is inefficient to
  1307. Xevaluate this expression by carrying out the inverse operation and then
  1308. Xthe multiply. Yet it is a convenient way of writing the instruction. It
  1309. Xwould be helpful if the program recognised this expression and carried
  1310. Xout the more appropriate approach.
  1311. X
  1312. XTo carry out this "intelligent" analysis of an instruction  matrix
  1313. Xexpressions are evaluated in two stages. In the the first stage a tree
  1314. Xrepresentation of the expression is formed.
  1315. X
  1316. XFor example (A+B)*C is represented by a tree
  1317. X
  1318. X                    *
  1319. X                   / \
  1320. X                  +   C
  1321. X                 / \
  1322. X                A   B
  1323. X
  1324. XRather than adding A and B the + operator yields an object of a class
  1325. X"AddedMatrix" which is just a pair of pointers to A and B. Then the *
  1326. Xoperator yields a "MultipliedMatrix" which is a pair of pointers to the
  1327. X"AddedMatrix" and C. The tree is examined for any simplifications and
  1328. Xthen evaluated recursively.
  1329. X
  1330. XFurther possibilities not yet included are to recognise A.t()*A and
  1331. XA.t()+A as symmetric or to improve the efficiency of evaluation of
  1332. Xexpressions like A+B+C, A*B*C, A*B.t()  [t() denotes transpose].
  1333. X
  1334. XOne of the disadvantages of the two-stage approach is that the types of
  1335. Xmatrix expressions are determined at run-time. So the compiler will not
  1336. Xdetect errors of the type
  1337. X
  1338. X   Matrix M; DiagonalMatrix D; ....; D = M;
  1339. X
  1340. XWe don't allow conversions using = when information would be lost. Such
  1341. Xerrors will be detected when the statement is executed.
  1342. X
  1343. X
  1344. XHow to overcome an explosion in number of operations
  1345. X----------------------------------------------------
  1346. X
  1347. XThe package attempts to solve the problem of the large number of
  1348. Xversions of the binary operations required when one has a variety of
  1349. Xtypes. With n types of matrices the binary operations will each require
  1350. Xn-squared separate algorithms. Some reduction in the number may be
  1351. Xpossible by carrying out conversions. However the situation rapidly
  1352. Xbecomes impossible with more than 4 or 5 types.
  1353. X
  1354. XDoug Lea told me that it was possible to avoid this problem. I don't
  1355. Xknow what his solution is. Here's mine.
  1356. X
  1357. XEach matrix type includes routines for extracting individual rows or
  1358. Xcolumns. I assume a row or column consists of a sequence of zeros, a
  1359. Xsequence of stored values and then another sequence of zeros. Only a
  1360. Xsingle algorithm is then required for each binary operation. The rows
  1361. Xcan be located very quickly since most of the matrices are stored row by
  1362. Xrow. Columns must be copied and so the access is somewhat slower. As far
  1363. Xas possible my algorithms access the matrices by row.
  1364. X
  1365. XAn alternative approach of using iterators will be slower since the
  1366. Xiterators will involve a virtual function access at each step.
  1367. X
  1368. XThere is another approach. Each of the matrix types defined in this
  1369. Xpackage can be set up so both rows and columns have their elements at
  1370. Xequal intervals provided we are prepared to store the rows and columns
  1371. Xin up to three chunks. With such an approach one could write a single
  1372. X"generic" algorithm for each of multiply and add. This would be a
  1373. Xreasonable alternative to my approach.
  1374. X
  1375. XI provide several algorithms for operations like + . If one is adding
  1376. Xtwo matrices of the same type then there is no need to access the
  1377. Xindividual rows or columns and a faster general algorithm is
  1378. Xappropriate.
  1379. X
  1380. XGenerally the method works well. However symmetric matrices are not
  1381. Xalways handled very efficiently (yet) since complete rows are not stored
  1382. Xexplicitly.
  1383. X
  1384. XThe original version of the package did not use this access by row or
  1385. Xcolumn method and provided the multitude of algorithms for the
  1386. Xcombination of different matrix types. The code file length turned out
  1387. Xto be just a little longer than the present one when providing the same
  1388. Xfacilities with 5 distinct types of matrices. It would have been very
  1389. Xdifficult to increase the number of matrix types in the original
  1390. Xversion. Apparently 4 to 5 types is about the break even point for
  1391. Xswitching to the approach adopted in the present package.
  1392. X
  1393. XHowever it must also be admitted that there is a substantial overhead in
  1394. Xthe approach adopted in the present package for small matrices. The test
  1395. Xprogram developed for the original version of the package takes 30 to
  1396. X50% longer to run with the current version. This is for matrices in the
  1397. Xrange 6x6 to 10x10.
  1398. X
  1399. XTo try to improve the situation a little I do provide an ordinary matrix
  1400. Xmultiplication routine for the case when all the matrices involved are
  1401. Xrectangular.
  1402. X
  1403. X
  1404. XDestruction of temporaries
  1405. X--------------------------
  1406. X
  1407. XVersions before version 5 of newmat did not work correctly with Gnu C++.
  1408. XThis was because the tree structure used to represent a matrix
  1409. Xexpression was set up on the stack. This was fine for AT&T, Borland and
  1410. XZortech C++. However Gnu C++ destroys temporary structures as soon as
  1411. Xthe function that accesses them finishes. The other compilers wait until
  1412. Xthe end of the current block. (It would be good enough for them to wait
  1413. Xtill the end of the expression.) To overcome this problem, there is now
  1414. Xan option to store the temporaries forming the tree structure on the
  1415. Xheap (created with new) and to delete them explicitly. Activate the
  1416. Xdefinition of TEMPS_DESTROYED_QUICKLY to set this option. In fact, I
  1417. Xsuggest this be the default option as, with it, the package uses less
  1418. Xstorage and runs faster.
  1419. X
  1420. XThere still exist situations Gnu C++ will go wrong. These include
  1421. Xstatements like
  1422. X
  1423. XA = X * Matrix(P * Q); Real r = (A*B)(3,4);
  1424. X
  1425. XNeither of these kinds of statements will occur often in practice.
  1426. X
  1427. X
  1428. XA calculus of matrix types
  1429. X--------------------------
  1430. X
  1431. XThe program needs to be able to work out the class of the result of a
  1432. Xmatrix expression. This is to check that a conversion is legal or to
  1433. Xdetermine the class of a temporary. To assist with this, a class
  1434. XMatrixType is defined. Operators +, -, *, >= are defined to calculate
  1435. Xthe types of the results of expressions or to check that conversions are
  1436. Xlegal.
  1437. X
  1438. X
  1439. XError handling
  1440. X--------------
  1441. X
  1442. XThe package now does have a moderately graceful exit from errors.
  1443. XOriginally I thought I would wait until exceptions became available in
  1444. XC++. Trying to set up an error handling scheme that did not involve an
  1445. Xexception-like facility was just too complicated. Version 5 of this
  1446. Xpackage included the beginnings of such an approach. The approach in the
  1447. Xpresent package, attempting to implement C++ exceptions, is not
  1448. Xcompletely satisfactory, but seems a good interim solution.
  1449. X
  1450. XThe exception mechanism cannot clean-up objects explicitly created by
  1451. Xnew. This must be explicitly carried out by the package writer or the
  1452. Xpackage user. I have not yet done this with the present package so
  1453. Xoccasionally a little garbage may be left behind after an exception. I
  1454. Xdon't think this is a big problem, but it is one that needs fixing.
  1455. X
  1456. XI identify five categories of errors:
  1457. X
  1458. X   Programming error - eg illegal conversion of a matrix, subscript out
  1459. X   of bounds, matrix dimensions don't match;
  1460. X
  1461. X   Illegal data error - eg Cholesky of a non-positive definite matrix;
  1462. X
  1463. X   Out of space error - "new" returns a null pointer;
  1464. X
  1465. X   Convergence failure - an iterative operation fails to converge;
  1466. X
  1467. X   Internal error - failure of an internal check.
  1468. X
  1469. XSome of these have subcategories, which are nicely represented by
  1470. Xderived exception classes. But I don't think it is a good idea for
  1471. Xpackage users to refer to these as they may change in the next release
  1472. Xof the package.
  1473. X
  1474. X
  1475. XSparse matrices
  1476. X---------------
  1477. X
  1478. XThe package does not yet support sparse matrices.
  1479. X
  1480. XFor sparse matrices there is going to be some kind of structure vector.
  1481. XIt is going to have to be calculated for the results of expressions in
  1482. Xmuch the same way that types are calculated. In addition, a whole new
  1483. Xset of row and column operations would have to be written.
  1484. X
  1485. XSparse matrices are important for people solving large sets of
  1486. Xdifferential equations as well as being important for statistical and
  1487. Xoperational research applications. I think comprehensive matrix package
  1488. Xneeds to implement sparse matrices.
  1489. X
  1490. X
  1491. XComplex matrices
  1492. X----------------
  1493. X
  1494. XThe package does not yet support matrices with complex elements. There
  1495. Xare at least two approaches to including these. One is to have matrices
  1496. Xwith complex elements. This probably means making new versions of the
  1497. Xbasic row and column operations for Real*Complex, Complex*Complex,
  1498. XComplex*Real and similarly for + and -. This would be OK, except that I
  1499. Xam also going to have to also do this for sparse and when you put these
  1500. Xtogether, the whole thing will get out of hand.
  1501. X
  1502. XThe alternative is to represent a Complex matrix by a pair of Real
  1503. Xmatrices. One probably needs another level of decoding expressions but I
  1504. Xthink it might still be simpler than the first approach. There is going
  1505. Xto be a problem with accessing elements and the final package may be a
  1506. Xlittle less efficient that one using the previous representation.
  1507. XNeverthless, this is the approach I favour.
  1508. X
  1509. XComplex matrices are used extensively by electrical engineers and really
  1510. Xshould be fully supported in a comprehensive package.
  1511. END_OF_FILE
  1512. if test 24907 -ne `wc -c <'newmatb.txt'`; then
  1513.     echo shar: \"'newmatb.txt'\" unpacked with wrong size!
  1514. fi
  1515. # end of 'newmatb.txt'
  1516. fi
  1517. if test -f 'newmatio.h' -a "${1}" != "-c" ; then 
  1518.   echo shar: Will not clobber existing file \"'newmatio.h'\"
  1519. else
  1520. echo shar: Extracting \"'newmatio.h'\" \(368 characters\)
  1521. sed "s/^X//" >'newmatio.h' <<'END_OF_FILE'
  1522. X//$$ newmatio.h           definition file for matrix package input/output
  1523. X
  1524. X// Copyright (C) 1991,2,3: R B Davies
  1525. X
  1526. X#ifndef MATRIXIO_LIB
  1527. X#define MATRIXIO_LIB 0
  1528. X
  1529. X#include "newmat.h"
  1530. X
  1531. X/**************************** input/output *****************************/
  1532. X
  1533. Xostream& operator<<(ostream&, const BaseMatrix&);
  1534. X
  1535. Xostream& operator<<(ostream&, const GeneralMatrix&);
  1536. X
  1537. X
  1538. X#endif
  1539. END_OF_FILE
  1540. if test 368 -ne `wc -c <'newmatio.h'`; then
  1541.     echo shar: \"'newmatio.h'\" unpacked with wrong size!
  1542. fi
  1543. # end of 'newmatio.h'
  1544. fi
  1545. if test -f 'newmatrc.h' -a "${1}" != "-c" ; then 
  1546.   echo shar: Will not clobber existing file \"'newmatrc.h'\"
  1547. else
  1548. echo shar: Extracting \"'newmatrc.h'\" \(4968 characters\)
  1549. sed "s/^X//" >'newmatrc.h' <<'END_OF_FILE'
  1550. X//$$ newmatrc.h              definition file for row/column classes
  1551. X
  1552. X// Copyright (C) 1991,2,3: R B Davies
  1553. X
  1554. X#ifndef MATRIXRC_LIB
  1555. X#define MATRIXRC_LIB 0
  1556. X
  1557. X#include "controlw.h"
  1558. X
  1559. X
  1560. X
  1561. X/************** classes MatrixRowCol, MatrixRow, MatrixCol *****************/
  1562. X
  1563. X// Used for accessing the rows and columns of matrices
  1564. X// All matrix classes must provide routines for calculating matrix rows and
  1565. X// columns. Assume rows can be found very efficiently.
  1566. X
  1567. Xenum LSF { LoadOnEntry=1,StoreOnExit=2,IsACopy=4,DirectPart=8,StoreHere=16 };
  1568. X
  1569. X
  1570. Xclass LoadAndStoreFlag : public ControlWord
  1571. X{
  1572. Xpublic:
  1573. X   LoadAndStoreFlag() {}
  1574. X   LoadAndStoreFlag(int i) : ControlWord(i) {}
  1575. X   LoadAndStoreFlag(LSF lsf) : ControlWord(lsf) {}
  1576. X   LoadAndStoreFlag(const ControlWord& cwx) : ControlWord(cwx) {}
  1577. X   FREE_CHECK(LoadAndStoreFlag)
  1578. X};
  1579. X
  1580. Xclass MatrixRowCol
  1581. X// the row or column of a matrix
  1582. X{
  1583. Xpublic:                                        // these are public to avoid
  1584. X                           // numerous friend statements
  1585. X   int length;                                 // row or column length
  1586. X   int skip;                                   // initial number of zeros
  1587. X   int storage;                                // number of stored elements
  1588. X   int rowcol;                                 // row or column number
  1589. X   GeneralMatrix* gm;                          // pointer to parent matrix
  1590. X   Real* store;                                // pointer to local storage
  1591. X                           //    less skip
  1592. X   LoadAndStoreFlag cw;                        // Load? Store? Is a Copy?
  1593. X   void IncrMat() { rowcol++; store += storage; }
  1594. X                           // used by NextRow
  1595. X   void IncrDiag() { rowcol++; skip++; }
  1596. X   void IncrUT() { rowcol++; storage--; store += storage; skip++; }
  1597. X   void IncrLT() { rowcol++; store += storage; storage++; }
  1598. X
  1599. Xpublic:
  1600. X   void Add(const MatrixRowCol&);              // add a row/col
  1601. X   void AddScaled(const MatrixRowCol&, Real);  // add a multiple of a row/col
  1602. X   void Add(const MatrixRowCol&, const MatrixRowCol&);
  1603. X                           // add two rows/cols
  1604. X   void Add(const MatrixRowCol&, Real);        // add a row/col
  1605. X   void Sub(const MatrixRowCol&);              // subtract a row/col
  1606. X   void Sub(const MatrixRowCol&, const MatrixRowCol&);
  1607. X                           // sub a row/col from another
  1608. X   void RevSub(const MatrixRowCol&);           // subtract from a row/col
  1609. X   void Copy(const MatrixRowCol&);             // copy a row/col
  1610. X   void CopyCheck(const MatrixRowCol&);        // ... check for data loss
  1611. X   void Copy(const Real*&);                    // copy from an array
  1612. X   void Copy(Real);                            // copy from constant
  1613. X   Real SumAbsoluteValue();                    // sum of absolute values
  1614. X   void Inject(const MatrixRowCol&);           // copy stored els of a row/col
  1615. X   void Negate(const MatrixRowCol&);           // change sign of a row/col
  1616. X   void Multiply(const MatrixRowCol&, Real);   // scale a row/col
  1617. X   friend Real DotProd(const MatrixRowCol&, const MatrixRowCol&);
  1618. X                           // sum of pairwise product
  1619. X   Real* operator()() { return store+skip; }   // pointer to first element
  1620. X   Real* Store() { return store; }
  1621. X   int Skip() { return skip; }                 // number of elements skipped
  1622. X   int Storage() { return storage; }           // number of elements stored
  1623. X   void Skip(int i) { skip=i; }
  1624. X   void Storage(int i) { storage=i; }
  1625. X   void SubRowCol(MatrixRowCol&, int, int) const;
  1626. X                           // get part of a row or column
  1627. X   MatrixRowCol() {}                           // to stop warning messages
  1628. X   ~MatrixRowCol();
  1629. X   FREE_CHECK(MatrixRowCol)
  1630. X};
  1631. X
  1632. Xclass MatrixRow : public MatrixRowCol
  1633. X{
  1634. Xpublic:
  1635. X   // bodies for these are inline at the end of this .h file
  1636. X   MatrixRow(GeneralMatrix*, LoadAndStoreFlag, int=0);
  1637. X                                               // extract a row
  1638. X   ~MatrixRow();
  1639. X   void Next();                                // get next row
  1640. X   FREE_CHECK(MatrixRow)
  1641. X};
  1642. X
  1643. Xclass MatrixCol : public MatrixRowCol
  1644. X{
  1645. Xpublic:
  1646. X   // bodies for these are inline at the end of this .h file
  1647. X   MatrixCol(GeneralMatrix*, LoadAndStoreFlag, int=0);
  1648. X                                               // extract a col
  1649. X   MatrixCol(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
  1650. X                                               // store/retrieve a col
  1651. X   ~MatrixCol();
  1652. X   void Next();                                // get next row
  1653. X   FREE_CHECK(MatrixCol)
  1654. X};
  1655. X
  1656. X
  1657. X/**************************** inline bodies ****************************/
  1658. X
  1659. Xinline MatrixRow::MatrixRow(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int row)
  1660. X{ gm=gmx; cw=cwx; rowcol=row; gm->GetRow(*this); } 
  1661. X
  1662. Xinline void MatrixRow::Next() { gm->NextRow(*this); }
  1663. X
  1664. Xinline MatrixCol::MatrixCol(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int col)
  1665. X{ gm=gmx; cw=cwx; rowcol=col; gm->GetCol(*this); } 
  1666. X
  1667. Xinline MatrixCol::MatrixCol(GeneralMatrix* gmx, Real* r,
  1668. X   LoadAndStoreFlag cwx, int col)
  1669. X{ gm=gmx; store=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); } 
  1670. X
  1671. Xinline void MatrixCol::Next() { gm->NextCol(*this); }
  1672. X
  1673. X
  1674. X#endif
  1675. END_OF_FILE
  1676. if test 4968 -ne `wc -c <'newmatrc.h'`; then
  1677.     echo shar: \"'newmatrc.h'\" unpacked with wrong size!
  1678. fi
  1679. # end of 'newmatrc.h'
  1680. fi
  1681. if test -f 'newmatrm.h' -a "${1}" != "-c" ; then 
  1682.   echo shar: Will not clobber existing file \"'newmatrm.h'\"
  1683. else
  1684. echo shar: Extracting \"'newmatrm.h'\" \(3749 characters\)
  1685. sed "s/^X//" >'newmatrm.h' <<'END_OF_FILE'
  1686. X//$$newmatrm.h                            rectangular matrix operations
  1687. X
  1688. X// Copyright (C) 1991,2,3: R B Davies
  1689. X
  1690. X#ifndef MATRIXRM_LIB
  1691. X#define MATRIXRM_LIB 0
  1692. X
  1693. X
  1694. X// operations on rectangular matrices
  1695. X
  1696. Xclass RectMatrixCol;
  1697. X
  1698. Xclass RectMatrixRowCol
  1699. X// a class for accessing rows and columns of rectangular matrices
  1700. X{
  1701. Xprotected:
  1702. X   Real* store;                   // pointer to storage
  1703. X   int n;                         // number of elements
  1704. X   int spacing;                   // space between elements
  1705. X   int shift;                     // space between cols or rows
  1706. X   RectMatrixRowCol(Real* st, int nx, int sp, int sh)
  1707. X      : store(st), n(nx), spacing(sp), shift(sh) {}
  1708. X   void Reset(Real* st, int nx, int sp, int sh)
  1709. X      { store=st; n=nx; spacing=sp; shift=sh; }
  1710. Xpublic:
  1711. X   Real operator*(const RectMatrixRowCol&) const;         // dot product
  1712. X   void AddScaled(const RectMatrixRowCol&, Real);         // add scaled
  1713. X   void Divide(const RectMatrixRowCol&, Real);            // scaling
  1714. X   void Divide(Real);                                     // scaling
  1715. X   void Negate();                                         // change sign
  1716. X   void Zero();                                           // zero row col
  1717. X   Real& operator[](int i) { return *(store+i*spacing); } // element
  1718. X   Real SumSquare() const;                                // sum of squares
  1719. X   Real& First() { return *store; }                       // get first element
  1720. X   void DownDiag() { store += (shift+spacing); n--; }
  1721. X   void UpDiag() { store -= (shift+spacing); n++; }
  1722. X   friend void ComplexScale(RectMatrixCol&, RectMatrixCol&, Real, Real);
  1723. X   friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
  1724. X   FREE_CHECK(RectMatrixRowCol)
  1725. X};
  1726. X
  1727. Xclass RectMatrixRow : public RectMatrixRowCol
  1728. X{
  1729. Xpublic:
  1730. X   RectMatrixRow(const Matrix&, int, int, int);
  1731. X   RectMatrixRow(const Matrix&, int);
  1732. X   void Reset(const Matrix&, int, int, int);
  1733. X   void Reset(const Matrix&, int);
  1734. X   Real& operator[](int i) { return *(store+i); }
  1735. X   void Down() { store += shift; }
  1736. X   void Right() { store++; n--; }
  1737. X   void Up() { store -= shift; }
  1738. X   void Left() { store--; n++; }
  1739. X   FREE_CHECK(RectMatrixRow)
  1740. X};
  1741. X
  1742. Xclass RectMatrixCol : public RectMatrixRowCol
  1743. X{
  1744. Xpublic:
  1745. X   RectMatrixCol(const Matrix&, int, int, int);
  1746. X   RectMatrixCol(const Matrix&, int);
  1747. X   void Reset(const Matrix&, int, int, int);
  1748. X   void Reset(const Matrix&, int);
  1749. X   void Down() { store += spacing; n--; }
  1750. X   void Right() { store++; }
  1751. X   void Up() { store -= spacing; n++; }
  1752. X   void Left() { store--; }
  1753. X   friend void ComplexScale(RectMatrixCol&, RectMatrixCol&, Real, Real);
  1754. X   friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
  1755. X   FREE_CHECK(RectMatrixCol)
  1756. X};
  1757. X
  1758. Xclass RectMatrixDiag : public RectMatrixRowCol
  1759. X{
  1760. Xpublic:
  1761. X   RectMatrixDiag(const DiagonalMatrix& D)
  1762. X      : RectMatrixRowCol(D.Store(), D.Nrows(), 1, 1) {}
  1763. X   Real& operator[](int i) { return *(store+i); }
  1764. X   void DownDiag() { store++; n--; }
  1765. X   void UpDiag() { store--; n++; }
  1766. X   FREE_CHECK(RectMatrixDiag)
  1767. X};
  1768. X
  1769. X
  1770. Xinline RectMatrixRow::RectMatrixRow
  1771. X   (const Matrix& M, int row, int skip, int length)
  1772. X   : RectMatrixRowCol( M.Store()+row*M.Ncols()+skip, length, 1, M.Ncols() ) {}
  1773. X
  1774. Xinline RectMatrixRow::RectMatrixRow (const Matrix& M, int row)
  1775. X   : RectMatrixRowCol( M.Store()+row*M.Ncols(), M.Ncols(), 1, M.Ncols() ) {}
  1776. X
  1777. Xinline RectMatrixCol::RectMatrixCol
  1778. X   (const Matrix& M, int skip, int col, int length)
  1779. X   : RectMatrixRowCol( M.Store()+col+skip*M.Ncols(), length, M.Ncols(), 1 ) {}
  1780. X
  1781. Xinline RectMatrixCol::RectMatrixCol (const Matrix& M, int col)
  1782. X   : RectMatrixRowCol( M.Store()+col, M.Nrows(), M.Ncols(), 1 ) {}
  1783. X
  1784. Xinline Real square(Real x) { return x*x; }
  1785. Xinline Real sign(Real x, Real y)
  1786. X   { return (y>=0) ? x : -x; }                    // assume x >=0
  1787. X
  1788. X
  1789. X#endif
  1790. END_OF_FILE
  1791. if test 3749 -ne `wc -c <'newmatrm.h'`; then
  1792.     echo shar: \"'newmatrm.h'\" unpacked with wrong size!
  1793. fi
  1794. # end of 'newmatrm.h'
  1795. fi
  1796. if test -f 'precisio.h' -a "${1}" != "-c" ; then 
  1797.   echo shar: Will not clobber existing file \"'precisio.h'\"
  1798. else
  1799. echo shar: Extracting \"'precisio.h'\" \(3227 characters\)
  1800. sed "s/^X//" >'precisio.h' <<'END_OF_FILE'
  1801. X//$$ precisio.h                          floating point constants
  1802. X
  1803. X#ifndef PRECISION_LIB
  1804. X#define PRECISION_LIB 0
  1805. X
  1806. X#ifndef SystemV                    // if there is float.h
  1807. X
  1808. X
  1809. X#ifdef USING_FLOAT
  1810. X
  1811. X
  1812. Xclass FloatingPointPrecision
  1813. X{
  1814. Xpublic:
  1815. X   static int Dig()
  1816. X      { return FLT_DIG; }        // number of decimal digits or precision
  1817. X   static Real Epsilon()
  1818. X      { return FLT_EPSILON; }    // smallest number such that 1+Eps!=Eps
  1819. X   static int Mantissa()
  1820. X      { return FLT_MANT_DIG; }   // bits in mantisa
  1821. X   static Real Maximum()
  1822. X      { return FLT_MAX; }        // maximum value
  1823. X   static int MaximumDecimalExponent()
  1824. X      { return FLT_MAX_10_EXP; } // maximum decimal exponent
  1825. X   static int MaximumExponent()
  1826. X      { return FLT_MAX_EXP; }    // maximum binary exponent
  1827. X   static Real Minimum()
  1828. X      { return FLT_MIN; }        // minimum positive value
  1829. X   static int MinimumDecimalExponent()
  1830. X      { return FLT_MIN_10_EXP; } // minimum decimal exponent
  1831. X   static int MinimumExponent()
  1832. X      { return FLT_MIN_EXP; }    // minimum binary exponent
  1833. X   static int Radix()
  1834. X      { return FLT_RADIX; }      // exponent radix
  1835. X   static int Rounds()
  1836. X      { return FLT_ROUNDS; }     // addition rounding (1 = does round)
  1837. X   FREE_CHECK(FloatingPointPrecision)
  1838. X};
  1839. X
  1840. X#endif
  1841. X
  1842. X
  1843. X#ifdef USING_DOUBLE
  1844. X
  1845. Xclass FloatingPointPrecision
  1846. X{
  1847. Xpublic:
  1848. X   static int Dig()
  1849. X      { return DBL_DIG; }        // number of decimal digits or precision
  1850. X   static Real Epsilon()
  1851. X      { return DBL_EPSILON; }    // smallest number such that 1+Eps!=Eps
  1852. X   static int Mantissa()
  1853. X      { return DBL_MANT_DIG; }   // bits in mantisa
  1854. X   static Real Maximum()
  1855. X      { return DBL_MAX; }        // maximum value
  1856. X   static int MaximumDecimalExponent()
  1857. X      { return DBL_MAX_10_EXP; } // maximum decimal exponent
  1858. X   static int MaximumExponent()
  1859. X      { return DBL_MAX_EXP; }    // maximum binary exponent
  1860. X   static Real Minimum()
  1861. X   {
  1862. X#ifdef __BCPLUSPLUS__
  1863. X       return 2.225074e-308;     // minimum positive value
  1864. X#else
  1865. X       return DBL_MIN;
  1866. X#endif
  1867. X   }
  1868. X   static int MinimumDecimalExponent()
  1869. X      { return DBL_MIN_10_EXP; } // minimum decimal exponent
  1870. X   static int MinimumExponent()
  1871. X      { return DBL_MIN_EXP; }    // minimum binary exponent
  1872. X   static int Radix()
  1873. X      { return FLT_RADIX; }      // exponent radix
  1874. X   static int Rounds()
  1875. X      { return FLT_ROUNDS; }     // addition rounding (1 = does round)
  1876. X   FREE_CHECK(FloatingPointPrecision)
  1877. X};
  1878. X
  1879. X#endif
  1880. X
  1881. X#endif
  1882. X
  1883. X#ifdef SystemV                    // if there is no float.h
  1884. X
  1885. X#ifdef USING_FLOAT
  1886. X
  1887. Xclass FloatingPointPrecision
  1888. X{
  1889. Xpublic:
  1890. X   static Real Epsilon()
  1891. X      { return pow(2.0,1-FSIGNIF); }  // smallest number such that 1+Eps!=Eps
  1892. X   static Real Maximum()
  1893. X      { return MAXFLOAT; }        // maximum value
  1894. X   static Real Minimum()
  1895. X      { return MINFLOAT; }        // minimum positive value
  1896. X   FREE_CHECK(FloatingPointPrecision)
  1897. X};
  1898. X
  1899. X#endif
  1900. X
  1901. X
  1902. X#ifdef USING_DOUBLE
  1903. X
  1904. Xclass FloatingPointPrecision
  1905. X{
  1906. Xpublic:
  1907. X   static Real Epsilon()
  1908. X      { return pow(2.0,1-DSIGNIF); }  // smallest number such that 1+Eps!=Eps
  1909. X   static Real Maximum()
  1910. X      { return MAXDOUBLE; }          // maximum value
  1911. X   static Real Minimum()
  1912. X      { return MINDOUBLE; }
  1913. X   FREE_CHECK(FloatingPointPrecision)
  1914. X};
  1915. X
  1916. X#endif
  1917. X
  1918. X#endif
  1919. X
  1920. X
  1921. X
  1922. X
  1923. X#endif
  1924. END_OF_FILE
  1925. if test 3227 -ne `wc -c <'precisio.h'`; then
  1926.     echo shar: \"'precisio.h'\" unpacked with wrong size!
  1927. fi
  1928. # end of 'precisio.h'
  1929. fi
  1930. echo shar: End of archive 2 \(of 8\).
  1931. cp /dev/null ark2isdone
  1932. MISSING=""
  1933. for I in 1 2 3 4 5 6 7 8 ; do
  1934.     if test ! -f ark${I}isdone ; then
  1935.     MISSING="${MISSING} ${I}"
  1936.     fi
  1937. done
  1938. if test "${MISSING}" = "" ; then
  1939.     echo You have unpacked all 8 archives.
  1940.     rm -f ark[1-9]isdone
  1941. else
  1942.     echo You still need to unpack the following archives:
  1943.     echo "        " ${MISSING}
  1944. fi
  1945. ##  End of shell archive.
  1946. exit 0
  1947.  
  1948. exit 0 # Just in case...
  1949.