-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathNEWMAT.H
More file actions
3780 lines (3236 loc) · 126 KB
/
NEWMAT.H
File metadata and controls
3780 lines (3236 loc) · 126 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//$$ newmat.h definition file for new version of matrix package
// Copyright (C) 2004: R B Davies
#ifndef NEWMAT_LIB
#define NEWMAT_LIB 0
//$$ include.h include files required by various versions of C++
#ifndef INCLUDE_LIB
#define INCLUDE_LIB
//#define use_namespace // define name spaces
//#define SETUP_C_SUBSCRIPTS // allow element access via A[i][j]
//#define OPT_COMPATIBLE // for use with opt++
// Activate just one of the following 3 statements
//#define SimulateExceptions // use simulated exceptions
#define UseExceptions // use C++ exceptions
//#define DisableExceptions // do not use exceptions
//#define TEMPS_DESTROYED_QUICKLY // for compilers that delete
// temporaries too quickly
//#define TEMPS_DESTROYED_QUICKLY_R // the same thing but applied
// to return from functions only
//#define DO_FREE_CHECK // check news and deletes balance
#define USING_DOUBLE // elements of type double
//#define USING_FLOAT // elements of type float
#define bool_LIB 0 // for compatibility with my older libraries
//#define ios_format_flags ios::fmtflags // for Gnu 3 and Intel for Linux
//#define _STANDARD_ // using standard library
//#define use_float_h // use float.h for precision data
//#define HAS_INT64 // if unsigned _int64 is recognised
// used by newran03
// comment out next line if Exception causes a problem
#define TypeDefException
//*********************** end of options set by user ********************
// for Gnu C++ version 3
#if defined __GNUG__ && __GNUG__ >= 3
#define _STANDARD_ // use standard library
#define ios_format_flags ios::fmtflags
#endif
// for Intel C++ for Linux
#if defined __ICC
#define _STANDARD_ // use standard library
#define ios_format_flags ios::fmtflags
#endif
// for Microsoft Visual C++ 7 and above (and Intel simulating these)
#if defined _MSC_VER && _MSC_VER >= 1300
#define _STANDARD_ // use standard library
#endif
#ifdef _STANDARD_ // using standard library
#include <cstdlib>
#if defined _MSC_VER && _MSC_VER == 1200
#include <limits> // for VC++6
#endif
#ifdef WANT_STREAM
#include <iostream>
#include <iomanip>
#endif
#ifdef WANT_MATH
#include <cmath>
#endif
#ifdef WANT_STRING
#include <cstring>
#endif
#ifdef WANT_TIME
#include <ctime>
#endif
#ifdef WANT_FSTREAM
#include <fstream>
#endif
using namespace std;
#else
#define DEFAULT_HEADER // use AT&T style header
// if no other compiler is recognised
#ifdef _MSC_VER // Microsoft
#include <stdlib.h>
// reactivate these statements to run under MSC version 7.0
// typedef int jmp_buf[9];
// extern "C"
// {
// int __cdecl setjmp(jmp_buf);
// void __cdecl longjmp(jmp_buf, int);
// }
#ifdef WANT_STREAM
#include <iostream.h>
#include <iomanip.h>
#endif
#ifdef WANT_MATH
#include <math.h>
#include <float.h>
#endif
#ifdef WANT_STRING
#include <string.h>
#endif
#ifdef WANT_TIME
#include <time.h>
#endif
#ifdef WANT_FSTREAM
#include <fstream.h>
#endif
#undef DEFAULT_HEADER
#endif
#ifdef __ZTC__ // Zortech
#include <stdlib.h>
#ifdef WANT_STREAM
#include <iostream.hpp>
#include <iomanip.hpp>
#define flush "" // not defined in iomanip?
#endif
#ifdef WANT_MATH
#include <math.h>
#include <float.h>
#endif
#ifdef WANT_STRING
#include <string.h>
#endif
#ifdef WANT_TIME
#include <time.h>
#endif
#ifdef WANT_FSTREAM
#include <fstream.h>
#endif
#undef DEFAULT_HEADER
#endif
#if defined __BCPLUSPLUS__ || defined __TURBOC__ // Borland or Turbo
#include <stdlib.h>
#ifdef WANT_STREAM
#include <iostream.h>
#include <iomanip.h>
#endif
#ifdef WANT_MATH
#include <math.h>
#include <float.h> // Borland has both float and values
// but values.h returns +INF for
// MAXDOUBLE in BC5
#endif
#ifdef WANT_STRING
#include <string.h>
#endif
#ifdef WANT_TIME
#include <time.h>
#endif
#ifdef WANT_FSTREAM
#include <fstream.h>
#endif
#undef DEFAULT_HEADER
#endif
#ifdef __GNUG__ // Gnu C++
#include <stdlib.h>
#ifdef WANT_STREAM
#include <iostream.h>
#include <iomanip.h>
#endif
#ifdef WANT_MATH
#include <math.h>
#include <float.h>
#endif
#ifdef WANT_STRING
#include <string.h>
#endif
#ifdef WANT_TIME
#include <time.h>
#endif
#ifdef WANT_FSTREAM
#include <fstream.h>
#endif
#undef DEFAULT_HEADER
#endif
#ifdef __WATCOMC__ // Watcom C/C++
#include <stdlib.h>
#ifdef WANT_STREAM
#include <iostream.h>
#include <iomanip.h>
#endif
#ifdef WANT_MATH
#include <math.h>
#include <float.h>
#endif
#ifdef WANT_STRING
#include <string.h>
#endif
#ifdef WANT_TIME
#include <time.h>
#endif
#ifdef WANT_FSTREAM
#include <fstream.h>
#endif
#undef DEFAULT_HEADER
#endif
#ifdef macintosh // MPW C++ on the Mac
#include <stdlib.h>
#ifdef WANT_STREAM
#include <iostream.h>
#include <iomanip.h>
#endif
#ifdef WANT_MATH
#include <float.h>
#include <math.h>
#endif
#ifdef WANT_STRING
#include <string.h>
#endif
#ifdef WANT_TIME
#include <time.h>
#endif
#ifdef WANT_FSTREAM
#include <fstream.h>
#endif
#undef DEFAULT_HEADER
#endif
#ifdef use_float_h // use float.h for precision values
#include <stdlib.h>
#ifdef WANT_STREAM
#include <iostream.h>
#include <iomanip.h>
#endif
#ifdef WANT_MATH
#include <float.h>
#include <math.h>
#endif
#ifdef WANT_STRING
#include <string.h>
#endif
#ifdef WANT_TIME
#include <time.h>
#endif
#ifdef WANT_FSTREAM
#include <fstream.h>
#endif
#undef DEFAULT_HEADER
#endif
#ifdef DEFAULT_HEADER // for example AT&T
#define ATandT
#include <stdlib.h>
#ifdef WANT_STREAM
#include <iostream.h>
#include <iomanip.h>
#endif
#ifdef WANT_MATH
#include <math.h>
#define SystemV // use System V
#include <values.h>
#endif
#ifdef WANT_STRING
#include <string.h>
#endif
#ifdef WANT_TIME
#include <time.h>
#endif
#ifdef WANT_FSTREAM
#include <fstream.h>
#endif
#endif // DEFAULT_HEADER
#endif // _STANDARD_
#ifdef use_namespace
namespace RBD_COMMON {
#endif
#ifdef USING_FLOAT // set precision type to float
typedef float Real;
typedef double long_Real;
#endif
#ifdef USING_DOUBLE // set precision type to double
typedef double Real;
typedef long double long_Real;
#endif
// This is for (very old) compilers that do not have bool automatically defined
#ifndef bool_LIB
#define bool_LIB 0
class bool
{
int value;
public:
bool(const int b) { value = b ? 1 : 0; }
bool(const void* b) { value = b ? 1 : 0; }
bool() {}
operator int() const { return value; }
int operator!() const { return !value; }
};
const bool true = 1;
const bool false = 0;
#endif
#ifdef use_namespace
}
#endif
#ifdef use_namespace
namespace RBD_COMMON {}
namespace RBD_LIBRARIES // access all my libraries
{
using namespace RBD_COMMON;
}
#endif
#endif
//$$ myexcept.h Exception handling classes
// A set of classes to simulate exceptions in C++
//
// Partially copied from Carlos Vidal s article in the C users journal
// September 1992, pp 19-28
//
// Operations defined
// Try { }
// Throw ( exception object )
// ReThrow
// Catch ( exception class ) { }
// CatchAll { }
// CatchAndThrow
//
// All catch lists must end with a CatchAll or CatchAndThrow statement
// but not both.
//
// When exceptions are finally implemented replace Try, Throw(E), Rethrow,
// Catch, CatchAll, CatchAndThrow by try, throw E, throw, catch,
// catch(...), and {}.
//
// All exception classes must be derived from BaseException, have no
// non-static variables and must include the statement
//
// static unsigned long Select;
//
// Any constructor in one of these exception classes must include
//
// Select = BaseException::Select;
//
// For each exceptions class, EX_1, some .cpp file must include
//
// unsigned long EX_1::Select;
//
#ifndef EXCEPTION_LIB
#define EXCEPTION_LIB
//#include "include.h"
#ifdef use_namespace
namespace RBD_COMMON {
#endif
void MatrixTerminate();
//********** classes for setting up exceptions and reporting ************//
class BaseException;
class Tracer // linked list showing how
{ // we got here
const char* entry;
Tracer* previous;
public:
Tracer(const char*);
~Tracer();
void ReName(const char*);
static void PrintTrace(); // for printing trace
static void AddTrace(); // insert trace in exception record
static Tracer* last; // points to Tracer list
friend class BaseException;
};
class BaseException // The base exception class
{
protected:
static char* what_error; // error message
static int SoFar; // no. characters already entered
static int LastOne; // last location in error buffer
public:
static void AddMessage(const char* a_what);
// messages about exception
static void AddInt(int value); // integer to error message
static unsigned long Select; // for identifying exception
BaseException(const char* a_what = 0);
static const char* what() { return what_error; }
// for getting error message
};
#ifdef TypeDefException
typedef BaseException Exception; // for compatibility with my older libraries
#endif
inline Tracer::Tracer(const char* e)
: entry(e), previous(last) { last = this; }
inline Tracer::~Tracer() { last = previous; }
inline void Tracer::ReName(const char* e) { entry=e; }
#ifdef SimulateExceptions // SimulateExceptions
#include <setjmp.h>
//************* the definitions of Try, Throw and Catch *****************//
class JumpItem;
class Janitor;
class JumpBase // pointer to a linked list of jmp_buf s
{
public:
static JumpItem *jl;
static jmp_buf env;
};
class JumpItem // an item in a linked list of jmp_buf s
{
public:
JumpItem *ji;
jmp_buf env;
Tracer* trace; // to keep check on Tracer items
Janitor* janitor; // list of items for cleanup
JumpItem() : ji(JumpBase::jl), trace(0), janitor(0)
{ JumpBase::jl = this; }
~JumpItem() { JumpBase::jl = ji; }
};
void Throw();
inline void Throw(const BaseException&) { Throw(); }
#define Try \
if (!setjmp( JumpBase::jl->env )) { \
JumpBase::jl->trace = Tracer::last; \
JumpItem JI387256156;
#define ReThrow Throw()
#define Catch(EXCEPTION) \
} else if (BaseException::Select == EXCEPTION::Select) {
#define CatchAll } else
#define CatchAndThrow } else Throw();
//****************** cleanup heap following Throw ***********************//
class Janitor
{
protected:
static bool do_not_link; // set when new is called
bool OnStack; // false if created by new
public:
Janitor* NextJanitor;
virtual void CleanUp() {}
Janitor();
virtual ~Janitor();
};
// The tiresome old trick for initializing the Janitor class
// this is needed for classes derived from Janitor which have objects
// declared globally
class JanitorInitializer
{
public:
JanitorInitializer();
private:
static int ref_count;
};
static JanitorInitializer JanInit;
#endif // end of SimulateExceptions
#ifdef UseExceptions
#define Try try
#define Throw(E) throw E
#define ReThrow throw
#define Catch catch
#define CatchAll catch(...)
#define CatchAndThrow {}
#endif // end of UseExceptions
#ifdef DisableExceptions // Disable exceptions
#define Try {
#define ReThrow Throw()
#define Catch(EXCEPTION) } if (false) {
#define CatchAll } if (false)
#define CatchAndThrow }
inline void Throw() { MatrixTerminate(); }
inline void Throw(const BaseException&) { MatrixTerminate(); }
#endif // end of DisableExceptions
#ifndef SimulateExceptions // ! SimulateExceptions
class Janitor // a dummy version
{
public:
virtual void CleanUp() {}
Janitor() {}
virtual ~Janitor() {}
};
#endif // end of ! SimulateExceptions
//******************** FREE_CHECK and NEW_DELETE ***********************//
#ifdef DO_FREE_CHECK // DO_FREE_CHECK
// Routines for tracing whether new and delete calls are balanced
class FreeCheck;
class FreeCheckLink
{
protected:
FreeCheckLink* next;
void* ClassStore;
FreeCheckLink();
virtual void Report()=0; // print details of link
friend class FreeCheck;
};
class FCLClass : public FreeCheckLink // for registering objects
{
char* ClassName;
FCLClass(void* t, char* name);
void Report();
friend class FreeCheck;
};
class FCLRealArray : public FreeCheckLink // for registering real arrays
{
char* Operation;
int size;
FCLRealArray(void* t, char* o, int s);
void Report();
friend class FreeCheck;
};
class FCLIntArray : public FreeCheckLink // for registering int arrays
{
char* Operation;
int size;
FCLIntArray(void* t, char* o, int s);
void Report();
friend class FreeCheck;
};
class FreeCheck
{
static FreeCheckLink* next;
static int BadDelete;
public:
static void Register(void*, char*);
static void DeRegister(void*, char*);
static void RegisterR(void*, char*, int);
static void DeRegisterR(void*, char*, int);
static void RegisterI(void*, char*, int);
static void DeRegisterI(void*, char*, int);
static void Status();
friend class FreeCheckLink;
friend class FCLClass;
friend class FCLRealArray;
friend class FCLIntArray;
};
#define FREE_CHECK(Class) \
public: \
void* operator new(size_t size) \
{ \
void* t = ::operator new(size); FreeCheck::Register(t,#Class); \
return t; \
} \
void operator delete(void* t) \
{ FreeCheck::DeRegister(t,#Class); ::operator delete(t); }
#ifdef SimulateExceptions // SimulateExceptions
#define NEW_DELETE(Class) \
public: \
void* operator new(size_t size) \
{ \
do_not_link=true; \
void* t = ::operator new(size); FreeCheck::Register(t,#Class); \
return t; \
} \
void operator delete(void* t) \
{ FreeCheck::DeRegister(t,#Class); ::operator delete(t); }
#endif // end of SimulateExceptions
#define MONITOR_REAL_NEW(Operation, Size, Pointer) \
FreeCheck::RegisterR(Pointer, Operation, Size);
#define MONITOR_INT_NEW(Operation, Size, Pointer) \
FreeCheck::RegisterI(Pointer, Operation, Size);
#define MONITOR_REAL_DELETE(Operation, Size, Pointer) \
FreeCheck::DeRegisterR(Pointer, Operation, Size);
#define MONITOR_INT_DELETE(Operation, Size, Pointer) \
FreeCheck::DeRegisterI(Pointer, Operation, Size);
#else // DO_FREE_CHECK not defined
#define FREE_CHECK(Class) public:
#define MONITOR_REAL_NEW(Operation, Size, Pointer) {}
#define MONITOR_INT_NEW(Operation, Size, Pointer) {}
#define MONITOR_REAL_DELETE(Operation, Size, Pointer) {}
#define MONITOR_INT_DELETE(Operation, Size, Pointer) {}
#ifdef SimulateExceptions // SimulateExceptions
#define NEW_DELETE(Class) \
public: \
void* operator new(size_t size) \
{ do_not_link=true; void* t = ::operator new(size); return t; } \
void operator delete(void* t) { ::operator delete(t); }
#endif // end of SimulateExceptions
#endif // end of ! DO_FREE_CHECK
#ifndef SimulateExceptions // ! SimulateExceptions
#define NEW_DELETE(Class) FREE_CHECK(Class)
#endif // end of ! SimulateExceptions
//********************* derived exceptions ******************************//
class Logic_error : public BaseException
{
public:
static unsigned long Select;
Logic_error(const char* a_what = 0);
};
class Runtime_error : public BaseException
{
public:
static unsigned long Select;
Runtime_error(const char* a_what = 0);
};
class Domain_error : public Logic_error
{
public:
static unsigned long Select;
Domain_error(const char* a_what = 0);
};
class Invalid_argument : public Logic_error
{
public:
static unsigned long Select;
Invalid_argument(const char* a_what = 0);
};
class Length_error : public Logic_error
{
public:
static unsigned long Select;
Length_error(const char* a_what = 0);
};
class Out_of_range : public Logic_error
{
public:
static unsigned long Select;
Out_of_range(const char* a_what = 0);
};
//class Bad_cast : public Logic_error
//{
//public:
// static unsigned long Select;
// Bad_cast(const char* a_what = 0);
//};
//class Bad_typeid : public Logic_error
//{
//public:
// static unsigned long Select;
// Bad_typeid(const char* a_what = 0);
//};
class Range_error : public Runtime_error
{
public:
static unsigned long Select;
Range_error(const char* a_what = 0);
};
class Overflow_error : public Runtime_error
{
public:
static unsigned long Select;
Overflow_error(const char* a_what = 0);
};
class Bad_alloc : public BaseException
{
public:
static unsigned long Select;
Bad_alloc(const char* a_what = 0);
};
#ifdef use_namespace
}
#endif
#endif // end of EXCEPTION_LIB
// body file: myexcept.cpp
#ifdef use_namespace
namespace NEWMAT { using namespace RBD_COMMON; }
namespace RBD_LIBRARIES { using namespace NEWMAT; }
namespace NEWMAT {
#endif
//#define DO_REPORT // to activate REPORT
#ifdef NO_LONG_NAMES
#define UpperTriangularMatrix UTMatrix
#define LowerTriangularMatrix LTMatrix
#define SymmetricMatrix SMatrix
#define DiagonalMatrix DMatrix
#define BandMatrix BMatrix
#define UpperBandMatrix UBMatrix
#define LowerBandMatrix LBMatrix
#define SymmetricBandMatrix SBMatrix
#define BandLUMatrix BLUMatrix
#endif
// ************************** general utilities ****************************/
class GeneralMatrix;
void MatrixErrorNoSpace(const void*); // no space handler
class LogAndSign
// Return from LogDeterminant function
// - value of the log plus the sign (+, - or 0)
{
Real log_val;
int sign_val;
public:
LogAndSign() { log_val=0.0; sign_val=1; }
LogAndSign(Real);
void operator*=(Real);
void pow_eq(int k); // raise to power of k
void PowEq(int k) { pow_eq(k); }
void ChangeSign() { sign_val = -sign_val; }
void change_sign() { sign_val = -sign_val; }
Real LogValue() const { return log_val; }
Real log_value() const { return log_val; }
int Sign() const { return sign_val; }
int sign() const { return sign_val; }
Real value() const;
Real Value() const { return value(); }
FREE_CHECK(LogAndSign)
};
// the following class is for counting the number of times a piece of code
// is executed. It is used for locating any code not executed by test
// routines. Use turbo GREP locate all places this code is called and
// check which ones are not accessed.
// Somewhat implementation dependent as it relies on "cout" still being
// present when ExeCounter objects are destructed.
#ifdef DO_REPORT
class ExeCounter
{
int line; // code line number
int fileid; // file identifier
long nexe; // number of executions
static int nreports; // number of reports
public:
ExeCounter(int,int);
void operator++() { nexe++; }
~ExeCounter(); // prints out reports
};
#endif
// ************************** class MatrixType *****************************/
// Is used for finding the type of a matrix resulting from the binary operations
// +, -, * and identifying what conversions are permissible.
// This class must be updated when new matrix types are added.
class GeneralMatrix; // defined later
class BaseMatrix; // defined later
class MatrixInput; // defined later
class MatrixType
{
public:
enum Attribute { Valid = 1,
Diagonal = 2, // order of these is important
Symmetric = 4,
Band = 8,
Lower = 16,
Upper = 32,
Square = 64,
Skew = 128,
LUDeco = 256,
Ones = 512 };
enum { US = 0,
UT = Valid + Upper + Square,
LT = Valid + Lower + Square,
Rt = Valid,
Sq = Valid + Square,
Sm = Valid + Symmetric + Square,
Sk = Valid + Skew + Square,
Dg = Valid + Diagonal + Band + Lower + Upper + Symmetric
+ Square,
Id = Valid + Diagonal + Band + Lower + Upper + Symmetric
+ Square + Ones,
RV = Valid, // do not separate out
CV = Valid, // vectors
BM = Valid + Band + Square,
UB = Valid + Band + Upper + Square,
LB = Valid + Band + Lower + Square,
SB = Valid + Band + Symmetric + Square,
KB = Valid + Band + Skew + Square,
Ct = Valid + LUDeco + Square,
BC = Valid + Band + LUDeco + Square,
Mask = ~Square
};
static int nTypes() { return 13; } // number of different types
// exclude Ct, US, BC
public:
int attribute;
bool DataLossOK; // true if data loss is OK when
// this represents a destination
public:
MatrixType () : DataLossOK(false) {}
MatrixType (int i) : attribute(i), DataLossOK(false) {}
MatrixType (int i, bool dlok) : attribute(i), DataLossOK(dlok) {}
MatrixType (const MatrixType& mt)
: attribute(mt.attribute), DataLossOK(mt.DataLossOK) {}
void operator=(const MatrixType& mt)
{ attribute = mt.attribute; DataLossOK = mt.DataLossOK; }
void SetDataLossOK() { DataLossOK = true; }
int operator+() const { return attribute; }
MatrixType operator+(MatrixType mt) const
{ return MatrixType(attribute & mt.attribute); }
MatrixType operator*(const MatrixType&) const;
MatrixType SP(const MatrixType&) const;
MatrixType KP(const MatrixType&) const;
MatrixType operator|(const MatrixType& mt) const
{ return MatrixType(attribute & mt.attribute & Valid); }
MatrixType operator&(const MatrixType& mt) const
{ return MatrixType(attribute & mt.attribute & Valid); }
bool operator>=(MatrixType mt) const
{ return ( attribute & ~mt.attribute & Mask ) == 0; }
bool operator<(MatrixType mt) const // for MS Visual C++ 4
{ return ( attribute & ~mt.attribute & Mask ) != 0; }
bool operator==(MatrixType t) const
{ return (attribute == t.attribute); }
bool operator!=(MatrixType t) const
{ return (attribute != t.attribute); }
bool operator!() const { return (attribute & Valid) == 0; }
MatrixType i() const; // type of inverse
MatrixType t() const; // type of transpose
MatrixType AddEqualEl() const // Add constant to matrix
{ return MatrixType(attribute & (Valid + Symmetric + Square)); }
MatrixType MultRHS() const; // type for rhs of multiply
MatrixType sub() const // type of submatrix
{ return MatrixType(attribute & Valid); }
MatrixType ssub() const // type of sym submatrix
{ return MatrixType(attribute); } // not for selection matrix
GeneralMatrix* New() const; // new matrix of given type
GeneralMatrix* New(int,int,BaseMatrix*) const;
// new matrix of given type
const char* value() const; // to print type
const char* Value() const { return value(); }
friend bool Rectangular(MatrixType a, MatrixType b, MatrixType c);
friend bool Compare(const MatrixType&, MatrixType&);
// compare and check conv.
bool is_band() const { return (attribute & Band) != 0; }
bool is_diagonal() const { return (attribute & Diagonal) != 0; }
bool is_symmetric() const { return (attribute & Symmetric) != 0; }
bool CannotConvert() const { return (attribute & LUDeco) != 0; }
// used by operator==
FREE_CHECK(MatrixType)
};
// *********************** class MatrixBandWidth ***********************/
class MatrixBandWidth
{
public:
int lower_val;
int upper_val;
MatrixBandWidth(const int l, const int u) : lower_val(l), upper_val(u) {}
MatrixBandWidth(const int i) : lower_val(i), upper_val(i) {}
MatrixBandWidth operator+(const MatrixBandWidth&) const;
MatrixBandWidth operator*(const MatrixBandWidth&) const;
MatrixBandWidth minimum(const MatrixBandWidth&) const;
MatrixBandWidth t() const { return MatrixBandWidth(upper_val,lower_val); }
bool operator==(const MatrixBandWidth& bw) const
{ return (lower_val == bw.lower_val) && (upper_val == bw.upper_val); }
bool operator!=(const MatrixBandWidth& bw) const { return !operator==(bw); }
int Upper() const { return upper_val; }
int upper() const { return upper_val; }
int Lower() const { return lower_val; }
int lower() const { return lower_val; }
FREE_CHECK(MatrixBandWidth)
};
// ********************* Array length specifier ************************/
// This class is introduced to avoid constructors such as
// ColumnVector(int)
// being used for conversions
class ArrayLengthSpecifier
{
int v;
public: