Changeset 10791 in ntrip for trunk/BNC/newmat
- Timestamp:
- Dec 3, 2025, 5:37:16 PM (4 months ago)
- Location:
- trunk/BNC/newmat
- Files:
-
- 13 edited
-
bandmat.cpp (modified) (2 diffs)
-
myexcept.cpp (modified) (4 diffs)
-
myexcept.h (modified) (1 diff)
-
newmat.h (modified) (1 diff)
-
newmat2.cpp (modified) (8 diffs)
-
newmat3.cpp (modified) (3 diffs)
-
newmat5.cpp (modified) (1 diff)
-
newmat6.cpp (modified) (2 diffs)
-
newmat7.cpp (modified) (8 diffs)
-
newmat8.cpp (modified) (1 diff)
-
newmat9.cpp (modified) (2 diffs)
-
newmatex.cpp (modified) (1 diff)
-
newmatio.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/newmat/bandmat.cpp
r9434 r10791 29 29 #endif 30 30 31 static inline int my_min(int x, int y) { return x < y ? x : y; } 32 static inline int my_max(int x, int y) { return x > y ? x : y; } 31 ////static inline int my_min(int x, int y) { return x < y ? x : y; } 32 ////static inline int my_max(int x, int y) { return x > y ? x : y; } 33 33 34 34 … … 360 360 // while (i--) { sum *= *a; a += w; } 361 361 if (i) for (;;) { sum *= *a; if (!(--i)) break; a += w; } 362 if (!d) sum.ChangeSign(); return sum; 362 if (!d) sum.ChangeSign(); 363 return sum; 363 364 } 364 365 -
trunk/BNC/newmat/myexcept.cpp
r9434 r10791 21 21 22 22 #include "myexcept.h" // for exception handling 23 #include "newmat.h" // for exception handling 23 24 24 25 #ifdef use_namespace … … 51 52 52 53 53 unsigned long BaseException::Select; 54 char* BaseException::what_error; 55 int BaseException::SoFar; 56 int BaseException::LastOne; 57 58 BaseException::BaseException(const char* a_what) 59 { 60 Select++; SoFar = 0; 61 if (!what_error) // make space for exception message 62 { 63 LastOne = 511; 64 what_error = new char[512]; 65 if (!what_error) // fail to make space 66 { 67 LastOne = 0; 68 what_error = (char *)"No heap space for exception message\n"; 69 } 70 } 71 AddMessage("\n\nAn exception has been thrown\n"); 72 AddMessage(a_what); 73 if (a_what) Tracer::AddTrace(); 74 } 75 76 void BaseException::AddMessage(const char* a_what) 77 { 78 if (a_what) 79 { 80 int l = strlen(a_what); int r = LastOne - SoFar; 81 if (l < r) { strcpy(what_error+SoFar, a_what); SoFar += l; } 82 else if (r > 0) 83 { 84 strncpy(what_error+SoFar, a_what, r); 85 what_error[LastOne] = 0; 86 SoFar = LastOne; 87 } 88 } 89 } 90 91 void BaseException::AddInt(int value) 92 { 93 bool negative; 94 if (value == 0) { AddMessage("0"); return; } 95 else if (value < 0) { value = -value; negative = true; } 96 else negative = false; 97 int n = 0; int v = value; // how many digits will we need? 98 while (v > 0) { v /= 10; n++; } 99 if (negative) n++; 100 if (LastOne-SoFar < n) { AddMessage("***"); return; } 101 102 SoFar += n; n = SoFar; what_error[n] = 0; 103 while (value > 0) 104 { 54 BaseException::BaseException(const char* a_what) { 55 _what = new char[MAXSIZE]; 56 if (!_what) { // fail to make space 57 _what = (char *)"No heap space for exception message\n"; 58 _deleteMe = false; 59 } 60 else { 61 _deleteMe = true; 62 } 63 AddMessage("\n\nAn exception has been thrown\n"); 64 AddMessage(a_what); 65 } 66 67 BaseException::BaseException(const BaseException& oth) { 68 _what = new char[MAXSIZE]; 69 if (!_what) { // fail to make space 70 _what = (char *)"No heap space for exception message\n"; 71 _deleteMe = false; 72 } 73 else { 74 _deleteMe = true; 75 strcpy(_what, oth._what); 76 } 77 } 78 79 BaseException& BaseException::operator=(const BaseException& oth) { 80 if (this == &oth) return *this; 81 _what = new char[MAXSIZE]; 82 if (!_what) { // fail to make space 83 _what = (char *)"No heap space for exception message\n"; 84 _deleteMe = false; 85 } 86 else { 87 _deleteMe = true; 88 strcpy(_what, oth._what); 89 } 90 return *this; 91 } 92 93 BaseException::~BaseException() { 94 if (_deleteMe) delete[] _what; 95 } 96 97 void BaseException::AddMessage(const char* a_what) { 98 if (a_what) { 99 size_t nn = MAXSIZE - strlen(_what) - 1; 100 strncat(_what, a_what, nn); 101 } 102 } 103 104 void BaseException::AddInt(int value) { 105 bool negative = false; 106 if (value == 0) { 107 AddMessage("0"); 108 return; 109 } 110 else if (value < 0) { 111 value = -value; 112 negative = true; 113 } 114 int nn = (negative ? 1 : 0); // how many digits will we need? 115 int vv = value; 116 while (vv > 0) { vv /= 10; ++nn; } 117 if ((int)(MAXSIZE - strlen(_what)) < nn) { 118 AddMessage("***"); 119 return; 120 } 121 122 nn += strlen(_what); 123 _what[nn] = 0; 124 while (value > 0) { 105 125 int nv = value / 10; int rm = value - nv * 10; value = nv; 106 what_error[--n] = (char)(rm + '0');107 } 108 if (negative) what_error[--n] = '-';109 return; 110 } 111 112 void Tracer::PrintTrace()113 { 114 cout << "\n";115 for (Tracer* et = last; et; et=et->previous)116 cout << " * " << et->entry << "\n";117 } 118 119 void Tracer::AddTrace() 120 { 121 if (last)122 {123 BaseException::AddMessage("Trace: ");124 BaseException::AddMessage(last->entry);125 for (Tracer* et = last->previous; et; et=et->previous)126 {127 BaseException::AddMessage("; ");128 BaseException::AddMessage(et->entry);129 }130 BaseException::AddMessage(".\n");131 }132 } 126 _what[--nn] = (char)(rm + '0'); 127 } 128 if (negative) _what[--nn] = '-'; 129 } 130 131 132 void BaseException::MatrixDetails(const GeneralMatrix& A) 133 { 134 MatrixBandWidth bw = A.bandwidth(); 135 int ubw = bw.upper_val; int lbw = bw.lower_val; 136 AddMessage("MatrixType = "); 137 AddMessage(A.Type().Value()); 138 AddMessage(" # Rows = "); BaseException::AddInt(A.Nrows()); 139 AddMessage("; # Cols = "); BaseException::AddInt(A.Ncols()); 140 if (lbw >=0) 141 { 142 AddMessage("; lower BW = "); 143 AddInt(lbw); 144 } 145 if (ubw >=0) 146 { 147 AddMessage("; upper BW = "); 148 AddInt(ubw); 149 } 150 AddMessage("\n"); 151 } 152 133 153 134 154 #ifdef SimulateExceptions … … 230 250 { 231 251 cout << "\n\nThere has been an exception with no handler - exiting"; 232 const char* what = BaseException::what();233 if (what) cout << what << "\n";234 252 exit(1); 235 253 } … … 479 497 480 498 499 unsigned long BaseException::Select; 481 500 unsigned long Logic_error::Select; 482 501 unsigned long Runtime_error::Select; -
trunk/BNC/newmat/myexcept.h
r9434 r10791 63 63 64 64 class BaseException; 65 class GeneralMatrix; 65 66 66 67 class Tracer // linked list showing how 67 68 { // we got here 68 const char* entry; 69 Tracer* previous; 70 public: 71 Tracer(const char*); 72 ~Tracer(); 73 void ReName(const char*); 74 static void PrintTrace(); // for printing trace 75 static void AddTrace(); // insert trace in exception record 76 static Tracer* last; // points to Tracer list 77 friend class BaseException; 78 }; 79 80 81 class BaseException // The base exception class 82 { 83 protected: 84 static char* what_error; // error message 85 static int SoFar; // no. characters already entered 86 static int LastOne; // last location in error buffer 87 public: 88 static void AddMessage(const char* a_what); 89 // messages about exception 90 static void AddInt(int value); // integer to error message 91 static unsigned long Select; // for identifying exception 92 BaseException(const char* a_what = 0); 93 static const char* what() { return what_error; } 94 // for getting error message 95 }; 96 69 public: 70 Tracer(const char*) {}; 71 ~Tracer() {} 72 void ReName(const char*) {} 73 static void PrintTrace() {}; // for printing trace 74 static void AddTrace() {}; // insert trace in exception record 75 static Tracer* last; // points to Tracer list 76 }; 77 78 79 class BaseException { // The base exception class 80 protected: 81 int MAXSIZE = 512; 82 char* _what; // error message 83 bool _deleteMe; 84 public: 85 static unsigned long Select; 86 BaseException(const char* a_what = 0); 87 BaseException(const BaseException& oth); 88 BaseException& operator=(const BaseException& oth); 89 ~BaseException(); 90 void AddMessage(const char* a_what); 91 void AddInt(int value); 92 void MatrixDetails(const GeneralMatrix& A); 93 const char* what() { return _what; } 94 }; 95 96 97 97 #ifdef TypeDefException 98 98 typedef BaseException Exception; // for compatibility with my older libraries 99 99 #endif 100 101 inline Tracer::Tracer(const char* e)102 : entry(e), previous(last) { last = this; }103 104 inline Tracer::~Tracer() { last = previous; }105 106 inline void Tracer::ReName(const char* e) { entry=e; }107 100 108 101 #ifdef SimulateExceptions // SimulateExceptions -
trunk/BNC/newmat/newmat.h
r9434 r10791 1834 1834 MatrixInput(const MatrixInput& mi) : n(mi.n), r(mi.r) {} 1835 1835 MatrixInput(int nx, Real* rx) : n(nx), r(rx) {} 1836 ~MatrixInput();1836 ~MatrixInput() noexcept(false); 1837 1837 MatrixInput operator<<(double); 1838 1838 MatrixInput operator<<(float); -
trunk/BNC/newmat/newmat2.cpp
r9434 r10791 39 39 REPORT 40 40 int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage; 41 if (f < skip) f = skip; if (l > lx) l = lx; l -= f; 41 if (f < skip) f = skip; 42 if (l > lx) l = lx; 43 l -= f; 42 44 if (l<=0) return; 43 45 Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip); … … 50 52 // THIS += (mrc * x) 51 53 int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage; 52 if (f < skip) f = skip; if (l > lx) l = lx; l -= f; 54 if (f < skip) f = skip; 55 if (l > lx) l = lx; 56 l -= f; 53 57 if (l<=0) return; 54 58 Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip); … … 61 65 // THIS -= mrc 62 66 int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage; 63 if (f < skip) f = skip; if (l > lx) l = lx; l -= f; 67 if (f < skip) f = skip; 68 if (l > lx) l = lx; 69 l -= f; 64 70 if (l<=0) return; 65 71 Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip); … … 72 78 REPORT 73 79 int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage; 74 if (f < skip) f = skip; if (l > lx) l = lx; l -= f; 80 if (f < skip) f = skip; 81 if (l > lx) l = lx; 82 l -= f; 75 83 if (l<=0) return; 76 84 Real* elx=data+(f-skip); Real* ely=mrc.data+(f-mrc.skip); … … 83 91 int f = mrc1.skip; int f2 = mrc2.skip; 84 92 int l = f + mrc1.storage; int l2 = f2 + mrc2.storage; 85 if (f < f2) f = f2; if (l > l2) l = l2; l -= f; 93 if (f < f2) f = f2; 94 if (l > l2) l = l2; 95 l -= f; 86 96 if (l<=0) return 0.0; 87 97 … … 97 107 int f = skip; int l = skip + storage; 98 108 int f1 = mrc1.skip; int l1 = f1 + mrc1.storage; 99 if (f1<f) f1=f; if (l1>l) l1=l; 109 if (f1<f) f1=f; 110 if (l1>l) l1=l; 100 111 int f2 = mrc2.skip; int l2 = f2 + mrc2.storage; 101 if (f2<f) f2=f; if (l2>l) l2=l; 112 if (f2<f) f2=f; 113 if (l2>l) l2=l; 102 114 Real* el = data + (f-skip); 103 115 Real* el1 = mrc1.data+(f1-mrc1.skip); Real* el2 = mrc2.data+(f2-mrc2.skip); … … 169 181 int f = skip; int l = skip + storage; 170 182 int f1 = mrc1.skip; int l1 = f1 + mrc1.storage; 171 if (f1<f) f1=f; if (l1>l) l1=l; 183 if (f1<f) f1=f; 184 if (l1>l) l1=l; 172 185 int f2 = mrc2.skip; int l2 = f2 + mrc2.storage; 173 if (f2<f) f2=f; if (l2>l) l2=l; 186 if (f2<f) f2=f; 187 if (l2>l) l2=l; 174 188 Real* el = data + (f-skip); 175 189 Real* el1 = mrc1.data+(f1-mrc1.skip); Real* el2 = mrc2.data+(f2-mrc2.skip); … … 333 347 int f = skip; int l = skip + storage; 334 348 int f1 = mrc1.skip; int l1 = f1 + mrc1.storage; 335 if (f1<f) f1=f; if (l1>l) l1=l; 349 if (f1<f) f1=f; 350 if (l1>l) l1=l; 336 351 int f2 = mrc2.skip; int l2 = f2 + mrc2.storage; 337 if (f2<f) f2=f; if (l2>l) l2=l; 352 if (f2<f) f2=f; 353 if (l2>l) l2=l; 338 354 Real* el = data + (f-skip); int i; 339 if (f1<f2) f1 = f2; if (l1>l2) l1 = l2; 355 if (f1<f2) f1 = f2; 356 if (l1>l2) l1 = l2; 340 357 if (l1<=f1) { REPORT i = l-f; while (i--) *el++ = 0.0; } // disjoint 341 358 else -
trunk/BNC/newmat/newmat3.cpp
r9434 r10791 668 668 Throw(InternalException("SymmetricBandMatrix::GetRow(MatrixRowCol&)")); 669 669 int w = w1+lower_val; s += w-ncols_val; Real* RowCopy; 670 if (s>0) w -= s; mrc.storage = w; int w2 = w-w1; 670 if (s>0) w -= s; 671 mrc.storage = w; 672 int w2 = w-w1; 671 673 if (!(mrc.cw*HaveStore)) 672 674 { … … 709 711 Throw(InternalException("SymmetricBandMatrix::GetCol(MatrixRowCol&)")); 710 712 int w = w1+lower_val; s += w-ncols_val; Real* ColCopy; 711 if (s>0) w -= s; mrc.storage = w; int w2 = w-w1; 713 if (s>0) w -= s; 714 mrc.storage = w; 715 int w2 = w-w1; 712 716 713 717 if ( +(mrc.cw*HaveStore) ) { REPORT ColCopy = mrc.data; } … … 759 763 760 764 int w = w1+lower_val; s += w-ncols_val; 761 if (s>0) w -= s; mrc.storage = w; int w2 = w-w1; 765 if (s>0) w -= s; 766 mrc.storage = w; 767 int w2 = w-w1; 762 768 763 769 Real* ColCopy = mrc.data = mrc.store+mrc.skip; -
trunk/BNC/newmat/newmat5.cpp
r9434 r10791 488 488 return MatrixInput(n, r+1); 489 489 } 490 MatrixInput::~MatrixInput() 490 MatrixInput::~MatrixInput() noexcept(false) 491 491 { 492 492 REPORT -
trunk/BNC/newmat/newmat6.cpp
r9470 r10791 352 352 // MatrixConversionCheck mcc; 353 353 Eq(X,MatrixType::Rt); 354 } 354 } 355 355 356 356 void SquareMatrix::operator=(const BaseMatrix& X) … … 429 429 if (&gm == this) { REPORT tag_val = -1; return; } 430 430 REPORT 431 if (indx) { delete [] indx; indx = 0; } 431 if (indx != 0) { delete [] indx; indx = 0; } 432 432 ((CroutMatrix&)gm).get_aux(*this); 433 433 Eq(gm); 434 434 } 435 435 436 436 437 437 -
trunk/BNC/newmat/newmat7.cpp
r9434 r10791 545 545 { REPORT AddDS(gm1,gm2); gm2->tDelete(); gmx = gm1; } 546 546 else if (c2 && gm2->reuse() ) 547 { REPORT AddDS(gm2,gm1); if (!c1) gm1->tDelete(); gmx = gm2; } 547 { REPORT AddDS(gm2,gm1); 548 if (!c1) gm1->tDelete(); 549 gmx = gm2; 550 } 548 551 else 549 552 { … … 552 555 CatchAll 553 556 { 554 if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete(); 557 if (!c1) gm1->tDelete(); 558 if (!c2) gm2->tDelete(); 555 559 ReThrow; 556 560 } 557 561 AddDS(gmx,gm1,gm2); 558 if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete(); 562 if (!c1) gm1->tDelete(); 563 if (!c2) gm2->tDelete(); 559 564 gmx->ReleaseAndDelete(); 560 565 } … … 616 621 { 617 622 REPORT ReverseSubtractDS(gm2,gm1); 618 if (!c1) gm1->tDelete(); gmx = gm2; 623 if (!c1) gm1->tDelete(); 624 gmx = gm2; 619 625 } 620 626 else … … 625 631 CatchAll 626 632 { 627 if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete(); 633 if (!c1) gm1->tDelete(); 634 if (!c2) gm2->tDelete(); 628 635 ReThrow; 629 636 } 630 637 SubtractDS(gmx,gm1,gm2); 631 if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete(); 638 if (!c1) gm1->tDelete(); 639 if (!c2) gm2->tDelete(); 632 640 gmx->ReleaseAndDelete(); 633 641 } … … 695 703 CatchAll 696 704 { 697 if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete(); 705 if (!c1) gm1->tDelete(); 706 if (!c2) gm2->tDelete(); 698 707 ReThrow; 699 708 } 700 709 SPDS(gmx,gm1,gm2); 701 if (!c1) gm1->tDelete(); if (!c2) gm2->tDelete(); 710 if (!c1) gm1->tDelete(); 711 if (!c2) gm2->tDelete(); 702 712 gmx->ReleaseAndDelete(); 703 713 } … … 779 789 while (i--) 780 790 { 781 if (*s1++ != *s2++) return false; if (*s1++ != *s2++) return false; 782 if (*s1++ != *s2++) return false; if (*s1++ != *s2++) return false; 791 if (*s1++ != *s2++) return false; 792 if (*s1++ != *s2++) return false; 793 if (*s1++ != *s2++) return false; 794 if (*s1++ != *s2++) return false; 783 795 } 784 796 i = n & 3; while (i--) if (*s1++ != *s2++) return false; … … 791 803 while (i--) 792 804 { 793 if (*s1++ != *s2++) return false; if (*s1++ != *s2++) return false; 794 if (*s1++ != *s2++) return false; if (*s1++ != *s2++) return false; 805 if (*s1++ != *s2++) return false; 806 if (*s1++ != *s2++) return false; 807 if (*s1++ != *s2++) return false; 808 if (*s1++ != *s2++) return false; 795 809 } 796 810 i = n & 3; while (i--) if (*s1++ != *s2++) return false; … … 869 883 while (i--) 870 884 { 871 if (*s++) return false; if (*s++) return false; 872 if (*s++) return false; if (*s++) return false; 885 if (*s++) return false; 886 if (*s++) return false; 887 if (*s++) return false; 888 if (*s++) return false; 873 889 } 874 890 i = storage & 3; while (i--) if (*s++) return false; -
trunk/BNC/newmat/newmat8.cpp
r9434 r10791 713 713 s += dd; 714 714 } 715 if (!d) sum.ChangeSign(); return sum; 715 if (!d) sum.ChangeSign(); 716 return sum; 716 717 717 718 } -
trunk/BNC/newmat/newmat9.cpp
r9434 r10791 15 15 #include "newmatio.h" 16 16 #include "newmatrc.h" 17 18 #ifdef USE_STD_NAMESPACE 19 using namespace std; 20 #endif 17 21 18 22 #ifdef use_namespace … … 44 48 MatrixRow mr((GeneralMatrix*)&X, LoadOnEntry); 45 49 int w = s.width(); int nr = X.Nrows(); ios_format_flags f = s.flags(); 46 s.setf(ios::fixed, ios::floatfield); 50 /////s.setf(ios::fixed, ios::floatfield); 47 51 for (int i=1; i<=nr; i++) 48 52 { -
trunk/BNC/newmat/newmatex.cpp
r9434 r10791 29 29 30 30 31 static void MatrixDetails(const GeneralMatrix& A) 32 // write matrix details to Exception buffer 33 { 34 MatrixBandWidth bw = A.bandwidth(); 35 int ubw = bw.upper_val; int lbw = bw.lower_val; 36 BaseException::AddMessage("MatrixType = "); 37 BaseException::AddMessage(A.Type().Value()); 38 BaseException::AddMessage(" # Rows = "); BaseException::AddInt(A.Nrows()); 39 BaseException::AddMessage("; # Cols = "); BaseException::AddInt(A.Ncols()); 40 if (lbw >=0) 41 { 42 BaseException::AddMessage("; lower BW = "); 43 BaseException::AddInt(lbw); 44 } 45 if (ubw >=0) 46 { 47 BaseException::AddMessage("; upper BW = "); 48 BaseException::AddInt(ubw); 49 } 50 BaseException::AddMessage("\n"); 51 } 31 ////static void MatrixDetails(const GeneralMatrix& A) 32 ////// write matrix details to Exception buffer 33 ////{ 34 //// MatrixBandWidth bw = A.bandwidth(); 35 //// int ubw = bw.upper_val; int lbw = bw.lower_val; 36 //// BaseException::AddMessage("MatrixType = "); 37 //// BaseException::AddMessage(A.Type().Value()); 38 //// BaseException::AddMessage(" # Rows = "); BaseException::AddInt(A.Nrows()); 39 //// BaseException::AddMessage("; # Cols = "); BaseException::AddInt(A.Ncols()); 40 //// if (lbw >=0) 41 //// { 42 //// BaseException::AddMessage("; lower BW = "); 43 //// BaseException::AddInt(lbw); 44 //// } 45 //// if (ubw >=0) 46 //// { 47 //// BaseException::AddMessage("; upper BW = "); 48 //// BaseException::AddInt(ubw); 49 //// } 50 //// BaseException::AddMessage("\n"); 51 ////} 52 52 53 53 NPDException::NPDException(const GeneralMatrix& A) -
trunk/BNC/newmat/newmatio.h
r9434 r10791 15 15 16 16 #include "newmat.h" 17 #include <iostream> 17 18 18 #ifdef USE_STD_NAMESPACE19 usingnamespacestd;19 #ifdef use_namespace 20 namespace NEWMAT { 20 21 #endif 22 23 21 24 22 25 // **************************** input/output *****************************/ 23 26 24 ostream& operator<<(ostream&, const BaseMatrix&); 27 std::ostream& operator<<(std::ostream&, const BaseMatrix&); 25 28 26 ostream& operator<<(ostream&, const GeneralMatrix&); 29 std::ostream& operator<<(std::ostream&, const GeneralMatrix&); 27 30 28 31
Note:
See TracChangeset
for help on using the changeset viewer.
