Changeset 9434 in ntrip
- Timestamp:
- May 19, 2021, 1:32:38 PM (4 years ago)
- Location:
- trunk/BNC/newmat
- Files:
-
- 4 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/newmat/hholder.cpp
r8901 r9434 335 335 } 336 336 337 // Following previous transformation,338 // now apply the same orthogonal transformation to (MX & MU)339 // Need the X Matrix but not the U.340 // Not optimised for accessing consecutive memory341 342 void updateQRZ(const Matrix& X, Matrix& MX, Matrix& MU)343 {344 REPORT345 Tracer et("updateQRZ(2)");346 int s = X.Ncols(); int n = X.Nrows();347 if (n != MX.Nrows())348 Throw(ProgramException("Incompatible dimensions",X,MX));349 if (s != MU.Nrows())350 Throw(ProgramException("Incompatible dimensions",X,MU));351 int t = MX.Ncols();352 if (t != MU.Ncols())353 Throw(ProgramException("Incompatible dimensions",MX,MU));354 355 if (s == 0) return;356 357 const Real* xi0 = X.data(); Real* mx = MX.data(); Real* muj = MU.data();358 for (int i=1; i<=s; ++i)359 {360 Real sum = 0.0;361 {362 const Real* xi=xi0; int k=n;363 while(k--) { sum += square(*xi); xi+= s;}364 }365 Real a0 = sqrt(2.0 - sum); Real* mxj0 = mx;366 for (int j=1; j<=t; ++j)367 {368 Real sum = 0.0;369 const Real* xi=xi0; Real* mxj=mxj0; int k=n;370 while(--k) { sum += *xi * *mxj; xi += s; mxj += t; }371 sum += *xi * *mxj; // last line of loop372 sum += a0 * *muj;373 xi=xi0; mxj=mxj0; k=n;374 while(--k) { *mxj -= sum * *xi; xi += s; mxj += t; }375 *mxj -= sum * *xi; // last line of loop376 *muj -= sum * a0; ++mxj0; ++muj;377 }378 ++xi0;379 }380 }381 382 383 384 // same thing as updateQRZ(Matrix& X, UpperTriangularMatrix& U)385 // except that X is upper triangular386 // contents of X are destroyed - results are in U387 // assume we can access efficiently by columns388 // e.g. X and U will fit in cache memory389 390 void updateQRZ(UpperTriangularMatrix& X, UpperTriangularMatrix& U)391 {392 REPORT393 Tracer et("updateQRZ(3)");394 int s = X.Ncols();395 if (s != U.Ncols())396 Throw(ProgramException("Incompatible dimensions",X,U));397 if (s == 0) return;398 Real* xi0 = X.data(); Real* u = U.data();399 for (int i=1; i<=s; ++i)400 {401 Real r = *u; Real sum = 0.0;402 {403 Real* xi=xi0; int k=i; int l=s;404 while(k--) { sum += square(*xi); xi+= --l;}405 }406 sum = sqrt(sum + square(r));407 if (sum == 0.0) { REPORT X.column(i) = 0.0; *u = 0.0; }408 else409 {410 Real frs = fabs(r) + sum;411 Real a0 = sqrt(frs / sum); Real alpha = a0 / frs;412 if (r <= 0) { REPORT *u = sum; alpha = -alpha; }413 else { REPORT *u = -sum; }414 {415 Real* xj0=xi0; int k=i; int l=s;416 while(k--) { *xj0 *= alpha; --l; xj0 += l;}417 }418 Real* xj0=xi0; Real* uj=u;419 for (int j=i+1; j<=s; ++j)420 {421 Real sum = 0.0; ++xj0; ++uj;422 Real* xi=xi0; Real* xj=xj0; int k=i; int l=s;423 while(k--) { sum += *xi * *xj; --l; xi += l; xj += l; }424 sum += a0 * *uj;425 xi=xi0; xj=xj0; k=i; l=s;426 while(k--) { *xj -= sum * *xi; --l; xi += l; xj += l; }427 *uj -= sum * a0;428 }429 }430 ++xi0; u += s-i+1;431 }432 }433 434 // Following previous transformation,435 // now apply the same orthogonal transformation to (MX & MU)436 // Need the X UpperTriangularMatrix but not the U.437 438 void updateQRZ(const UpperTriangularMatrix& X, Matrix& MX, Matrix& MU)439 {440 REPORT441 Tracer et("updateQRZ(4)");442 int s = X.Ncols();443 if (s != MX.Nrows())444 Throw(ProgramException("Incompatible dimensions",X,MX));445 if (s != MU.Nrows())446 Throw(ProgramException("Incompatible dimensions",X,MU));447 int t = MX.Ncols();448 if (t != MU.Ncols())449 Throw(ProgramException("Incompatible dimensions",MX,MU));450 if (s == 0) return;451 452 const Real* xi0 = X.data(); Real* mx = MX.data(); Real* muj = MU.data();453 for (int i=1; i<=s; ++i)454 {455 Real sum = 0.0;456 {457 const Real* xi=xi0; int k=i; int l=s;458 while(k--) { sum += square(*xi); xi+= --l;}459 }460 Real a0 = sqrt(2.0 - sum); Real* mxj0 = mx;461 for (int j=1; j<=t; ++j)462 {463 Real sum = 0.0;464 const Real* xi=xi0; Real* mxj=mxj0; int k=i; int l=s;465 while(--k) { sum += *xi * *mxj; --l; xi += l; mxj += t; }466 sum += *xi * *mxj; // last line of loop467 sum += a0 * *muj;468 xi=xi0; mxj=mxj0; k=i; l=s;469 while(--k) { *mxj -= sum * *xi; --l; xi += l; mxj += t; }470 *mxj -= sum * *xi; // last line of loop471 *muj -= sum * a0; ++mxj0; ++muj;472 }473 ++xi0;474 }475 }476 477 478 479 480 481 337 // Matrix A's first n columns are orthonormal 482 338 // so A.Columns(1,n).t() * A.Columns(1,n) is the identity matrix. -
trunk/BNC/newmat/include.h
r8901 r9434 1 /// \defgroup rbd_common RBD common library 1 /// \defgroup rbd_common RBD common library 2 2 ///@{ 3 3 … … 44 44 //#define HAS_INT64 // if unsigned _int64 is recognised 45 45 // used by newran03 46 47 //#define set_unix_options // set if running UNIX or LINUX 48 46 49 47 // comment out next line if Exception causes a problem 50 48 #define TypeDefException … … 65 63 #endif 66 64 67 // for Intel C++ for Windows68 #if defined __ICL69 #define _STANDARD_ // use standard library70 #define ios_format_flags ios::fmtflags71 #endif72 73 65 // for Microsoft Visual C++ 7 and above (and Intel simulating these) 74 66 #if defined _MSC_VER && _MSC_VER >= 1300 75 67 #define _STANDARD_ // use standard library 76 #endif77 78 // for Borland Builder C++ 2006 and above79 #if defined __BCPLUSPLUS__ && __BCPLUSPLUS__ >= 0x057080 #define _STANDARD_ // use standard library81 #define ios_format_flags ios::fmtflags82 68 #endif 83 69 … … 104 90 #include <fstream> 105 91 #endif 106 using namespace std; 92 ////using namespace std; 93 #define USE_STD_NAMESPACE 107 94 #else 108 95 -
trunk/BNC/newmat/myexcept.cpp
r8901 r9434 26 26 #endif 27 27 28 #ifdef USE_STD_NAMESPACE 29 using namespace std; 30 #endif 28 31 29 32 //#define REG_DEREG // for print out uses of new/delete -
trunk/BNC/newmat/myexcept.h
r8901 r9434 75 75 static void AddTrace(); // insert trace in exception record 76 76 static Tracer* last; // points to Tracer list 77 static void clear() {} // for compatibility78 77 friend class BaseException; 79 78 }; … … 94 93 static const char* what() { return what_error; } 95 94 // for getting error message 96 static void clear() {} // for compatibility97 95 }; 98 96 -
trunk/BNC/newmat/newmat.h
r8901 r9434 447 447 class GeneralMatrix : public BaseMatrix // declarable matrix types 448 448 { 449 virtual GeneralMatrix* Image() const; // copy of matrix 449 450 protected: 450 451 int tag_val; // shows whether can reuse … … 464 465 void ReverseElements(); // internal reverse of elements 465 466 void ReverseElements(GeneralMatrix*); // reverse order of elements 467 void operator=(Real); // set matrix to constant 466 468 Real* GetStore(); // get store or copy 467 469 GeneralMatrix* BorrowStore(GeneralMatrix*, MatrixType); 468 470 // temporarily access store 469 471 void GetMatrix(const GeneralMatrix*); // used by = and initialise 472 void Eq(const BaseMatrix&, MatrixType); // used by = 473 void Eq(const GeneralMatrix&); // version with no conversion 474 void Eq(const BaseMatrix&, MatrixType, bool);// used by << 475 void Eq2(const BaseMatrix&, MatrixType); // cut down version of Eq 470 476 int search(const BaseMatrix*) const; 471 477 virtual GeneralMatrix* Transpose(TransposedMatrix*, MatrixType); … … 478 484 // CleanUp when the data array has already been deleted 479 485 void PlusEqual(const GeneralMatrix& gm); 480 void SP_Equal(const GeneralMatrix& gm);481 486 void MinusEqual(const GeneralMatrix& gm); 482 487 void PlusEqual(Real f); … … 485 490 public: 486 491 GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp); 487 void Eq(const BaseMatrix&, MatrixType); // used by =488 void Eq(const GeneralMatrix&); // version with no conversion489 void Eq(const BaseMatrix&, MatrixType, bool);// used by <<490 void Eq2(const BaseMatrix&, MatrixType); // cut down version of Eq491 492 virtual MatrixType type() const = 0; // type of a matrix 492 493 MatrixType Type() const { return type(); } … … 502 503 const Real* data() const { return store; } 503 504 const Real* const_data() const { return store; } 504 void operator=(Real); // set matrix to constant505 505 virtual ~GeneralMatrix(); // delete store if set 506 506 void tDelete(); // delete if tag_val permits … … 526 526 void Inject(const GeneralMatrix& GM) { inject(GM); } 527 527 void operator+=(const BaseMatrix&); 528 void SP_eq(const BaseMatrix&);529 528 void operator-=(const BaseMatrix&); 530 529 void operator*=(const BaseMatrix&); … … 580 579 // ReturnMatrix Reverse() const; // reverse order of elements 581 580 void cleanup(); // to clear store 582 virtual GeneralMatrix* Image() const; // copy of matrix583 581 584 582 friend class Matrix; … … 627 625 class Matrix : public GeneralMatrix 628 626 { 627 GeneralMatrix* Image() const; // copy of matrix 629 628 public: 630 629 Matrix() {} … … 669 668 Real minimum2(int& i, int& j) const; 670 669 void operator+=(const Matrix& M) { PlusEqual(M); } 671 void SP_eq(const Matrix& M) { SP_Equal(M); }672 670 void operator-=(const Matrix& M) { MinusEqual(M); } 673 void operator+=(const BaseMatrix& M) { GeneralMatrix::operator+=(M); }674 void SP_eq(const BaseMatrix& M) { GeneralMatrix::SP_eq(M); }675 void operator-=(const BaseMatrix& M) { GeneralMatrix::operator-=(M); }676 671 void operator+=(Real f) { GeneralMatrix::Add(f); } 677 672 void operator-=(Real f) { GeneralMatrix::Add(-f); } 678 673 void swap(Matrix& gm) { GeneralMatrix::swap((GeneralMatrix&)gm); } 679 GeneralMatrix* Image() const; // copy of matrix680 674 friend Real dotproduct(const Matrix& A, const Matrix& B); 681 675 NEW_DELETE(Matrix) … … 685 679 class SquareMatrix : public Matrix 686 680 { 681 GeneralMatrix* Image() const; // copy of matrix 687 682 public: 688 683 SquareMatrix() {} … … 706 701 void ReSize(const GeneralMatrix& A) { resize(A); } 707 702 void operator+=(const Matrix& M) { PlusEqual(M); } 708 void SP_eq(const Matrix& M) { SP_Equal(M); }709 703 void operator-=(const Matrix& M) { MinusEqual(M); } 710 void operator+=(const BaseMatrix& M) { GeneralMatrix::operator+=(M); }711 void SP_eq(const BaseMatrix& M) { GeneralMatrix::SP_eq(M); }712 void operator-=(const BaseMatrix& M) { GeneralMatrix::operator-=(M); }713 704 void operator+=(Real f) { GeneralMatrix::Add(f); } 714 705 void operator-=(Real f) { GeneralMatrix::Add(-f); } 715 706 void swap(SquareMatrix& gm) { GeneralMatrix::swap((GeneralMatrix&)gm); } 716 GeneralMatrix* Image() const; // copy of matrix717 707 NEW_DELETE(SquareMatrix) 718 708 }; … … 721 711 class nricMatrix : public Matrix 722 712 { 713 GeneralMatrix* Image() const; // copy of matrix 723 714 Real** row_pointer; // points to rows 724 715 void MakeRowPointer(); // build rowpointer … … 752 743 void MiniCleanUp(); 753 744 void operator+=(const Matrix& M) { PlusEqual(M); } 754 void SP_eq(const Matrix& M) { SP_Equal(M); }755 745 void operator-=(const Matrix& M) { MinusEqual(M); } 756 void operator+=(const BaseMatrix& M) { GeneralMatrix::operator+=(M); }757 void SP_eq(const BaseMatrix& M) { GeneralMatrix::SP_eq(M); }758 void operator-=(const BaseMatrix& M) { GeneralMatrix::operator-=(M); }759 746 void operator+=(Real f) { GeneralMatrix::Add(f); } 760 747 void operator-=(Real f) { GeneralMatrix::Add(-f); } 761 748 void swap(nricMatrix& gm); 762 GeneralMatrix* Image() const; // copy of matrix763 749 NEW_DELETE(nricMatrix) 764 750 }; … … 767 753 class SymmetricMatrix : public GeneralMatrix 768 754 { 755 GeneralMatrix* Image() const; // copy of matrix 769 756 public: 770 757 SymmetricMatrix() {} … … 802 789 void ReSize(const GeneralMatrix& A) { resize(A); } 803 790 void operator+=(const SymmetricMatrix& M) { PlusEqual(M); } 804 void SP_eq(const SymmetricMatrix& M) { SP_Equal(M); }805 791 void operator-=(const SymmetricMatrix& M) { MinusEqual(M); } 806 void operator+=(const BaseMatrix& M) { GeneralMatrix::operator+=(M); }807 void SP_eq(const BaseMatrix& M) { GeneralMatrix::SP_eq(M); }808 void operator-=(const BaseMatrix& M) { GeneralMatrix::operator-=(M); }809 792 void operator+=(Real f) { GeneralMatrix::Add(f); } 810 793 void operator-=(Real f) { GeneralMatrix::Add(-f); } 811 794 void swap(SymmetricMatrix& gm) { GeneralMatrix::swap((GeneralMatrix&)gm); } 812 GeneralMatrix* Image() const; // copy of matrix813 795 NEW_DELETE(SymmetricMatrix) 814 796 }; … … 817 799 class UpperTriangularMatrix : public GeneralMatrix 818 800 { 801 GeneralMatrix* Image() const; // copy of matrix 819 802 public: 820 803 UpperTriangularMatrix() {} … … 854 837 MatrixBandWidth bandwidth() const; 855 838 void operator+=(const UpperTriangularMatrix& M) { PlusEqual(M); } 856 void SP_eq(const UpperTriangularMatrix& M) { SP_Equal(M); }857 839 void operator-=(const UpperTriangularMatrix& M) { MinusEqual(M); } 858 void operator+=(const BaseMatrix& M) { GeneralMatrix::operator+=(M); }859 void SP_eq(const BaseMatrix& M) { GeneralMatrix::SP_eq(M); }860 void operator-=(const BaseMatrix& M) { GeneralMatrix::operator-=(M); }861 840 void operator+=(Real f) { GeneralMatrix::operator+=(f); } 862 841 void operator-=(Real f) { GeneralMatrix::operator-=(f); } 863 842 void swap(UpperTriangularMatrix& gm) 864 843 { GeneralMatrix::swap((GeneralMatrix&)gm); } 865 GeneralMatrix* Image() const; // copy of matrix866 844 NEW_DELETE(UpperTriangularMatrix) 867 845 }; … … 870 848 class LowerTriangularMatrix : public GeneralMatrix 871 849 { 850 GeneralMatrix* Image() const; // copy of matrix 872 851 public: 873 852 LowerTriangularMatrix() {} … … 906 885 MatrixBandWidth bandwidth() const; 907 886 void operator+=(const LowerTriangularMatrix& M) { PlusEqual(M); } 908 void SP_eq(const LowerTriangularMatrix& M) { SP_Equal(M); }909 887 void operator-=(const LowerTriangularMatrix& M) { MinusEqual(M); } 910 void operator+=(const BaseMatrix& M) { GeneralMatrix::operator+=(M); }911 void SP_eq(const BaseMatrix& M) { GeneralMatrix::SP_eq(M); }912 void operator-=(const BaseMatrix& M) { GeneralMatrix::operator-=(M); }913 888 void operator+=(Real f) { GeneralMatrix::operator+=(f); } 914 889 void operator-=(Real f) { GeneralMatrix::operator-=(f); } 915 890 void swap(LowerTriangularMatrix& gm) 916 891 { GeneralMatrix::swap((GeneralMatrix&)gm); } 917 GeneralMatrix* Image() const; // copy of matrix918 892 NEW_DELETE(LowerTriangularMatrix) 919 893 }; … … 922 896 class DiagonalMatrix : public GeneralMatrix 923 897 { 898 GeneralMatrix* Image() const; // copy of matrix 924 899 public: 925 900 DiagonalMatrix() {} … … 967 942 // ReturnMatrix Reverse() const; // reverse order of elements 968 943 void operator+=(const DiagonalMatrix& M) { PlusEqual(M); } 969 void SP_eq(const DiagonalMatrix& M) { SP_Equal(M); }970 944 void operator-=(const DiagonalMatrix& M) { MinusEqual(M); } 971 void operator+=(const BaseMatrix& M) { GeneralMatrix::operator+=(M); }972 void SP_eq(const BaseMatrix& M) { GeneralMatrix::SP_eq(M); }973 void operator-=(const BaseMatrix& M) { GeneralMatrix::operator-=(M); }974 945 void operator+=(Real f) { GeneralMatrix::operator+=(f); } 975 946 void operator-=(Real f) { GeneralMatrix::operator-=(f); } 976 947 void swap(DiagonalMatrix& gm) 977 948 { GeneralMatrix::swap((GeneralMatrix&)gm); } 978 GeneralMatrix* Image() const; // copy of matrix979 949 NEW_DELETE(DiagonalMatrix) 980 950 }; … … 983 953 class RowVector : public Matrix 984 954 { 955 GeneralMatrix* Image() const; // copy of matrix 985 956 public: 986 957 RowVector() { nrows_val = 1; } … … 1026 997 // friend ReturnMatrix GetMatrixRow(Matrix& A, int row); 1027 998 void operator+=(const Matrix& M) { PlusEqual(M); } 1028 void SP_eq(const Matrix& M) { SP_Equal(M); }1029 999 void operator-=(const Matrix& M) { MinusEqual(M); } 1030 void operator+=(const BaseMatrix& M) { GeneralMatrix::operator+=(M); }1031 void SP_eq(const BaseMatrix& M) { GeneralMatrix::SP_eq(M); }1032 void operator-=(const BaseMatrix& M) { GeneralMatrix::operator-=(M); }1033 1000 void operator+=(Real f) { GeneralMatrix::Add(f); } 1034 1001 void operator-=(Real f) { GeneralMatrix::Add(-f); } 1035 1002 void swap(RowVector& gm) 1036 1003 { GeneralMatrix::swap((GeneralMatrix&)gm); } 1037 GeneralMatrix* Image() const; // copy of matrix1038 1004 NEW_DELETE(RowVector) 1039 1005 }; … … 1042 1008 class ColumnVector : public Matrix 1043 1009 { 1010 GeneralMatrix* Image() const; // copy of matrix 1044 1011 public: 1045 1012 ColumnVector() { ncols_val = 1; } … … 1079 1046 // ReturnMatrix Reverse() const; // reverse order of elements 1080 1047 void operator+=(const Matrix& M) { PlusEqual(M); } 1081 void SP_eq(const Matrix& M) { SP_Equal(M); }1082 1048 void operator-=(const Matrix& M) { MinusEqual(M); } 1083 void operator+=(const BaseMatrix& M) { GeneralMatrix::operator+=(M); }1084 void SP_eq(const BaseMatrix& M) { GeneralMatrix::SP_eq(M); }1085 void operator-=(const BaseMatrix& M) { GeneralMatrix::operator-=(M); }1086 1049 void operator+=(Real f) { GeneralMatrix::Add(f); } 1087 1050 void operator-=(Real f) { GeneralMatrix::Add(-f); } 1088 1051 void swap(ColumnVector& gm) 1089 1052 { GeneralMatrix::swap((GeneralMatrix&)gm); } 1090 GeneralMatrix* Image() const; // copy of matrix1091 1053 NEW_DELETE(ColumnVector) 1092 1054 }; … … 1102 1064 void ludcmp(); 1103 1065 void get_aux(CroutMatrix&); // for copying indx[] etc 1066 GeneralMatrix* Image() const; // copy of matrix 1104 1067 public: 1105 1068 CroutMatrix(const BaseMatrix&); … … 1125 1088 bool even_exchanges() const { return d; } 1126 1089 void swap(CroutMatrix& gm); 1127 GeneralMatrix* Image() const; // copy of matrix1128 1090 NEW_DELETE(CroutMatrix) 1129 1091 }; … … 1134 1096 class BandMatrix : public GeneralMatrix 1135 1097 { 1098 GeneralMatrix* Image() const; // copy of matrix 1136 1099 protected: 1137 1100 void CornerClear() const; // set unused elements to zero … … 1198 1161 void operator<<(const BaseMatrix& X) { GeneralMatrix::operator<<(X); } 1199 1162 void swap(BandMatrix& gm); 1200 GeneralMatrix* Image() const; // copy of matrix1201 1163 NEW_DELETE(BandMatrix) 1202 1164 }; … … 1205 1167 class UpperBandMatrix : public BandMatrix 1206 1168 { 1169 GeneralMatrix* Image() const; // copy of matrix 1207 1170 public: 1208 1171 UpperBandMatrix() {} … … 1237 1200 void swap(UpperBandMatrix& gm) 1238 1201 { BandMatrix::swap((BandMatrix&)gm); } 1239 GeneralMatrix* Image() const; // copy of matrix1240 1202 NEW_DELETE(UpperBandMatrix) 1241 1203 }; … … 1244 1206 class LowerBandMatrix : public BandMatrix 1245 1207 { 1208 GeneralMatrix* Image() const; // copy of matrix 1246 1209 public: 1247 1210 LowerBandMatrix() {} … … 1276 1239 void swap(LowerBandMatrix& gm) 1277 1240 { BandMatrix::swap((BandMatrix&)gm); } 1278 GeneralMatrix* Image() const; // copy of matrix1279 1241 NEW_DELETE(LowerBandMatrix) 1280 1242 }; … … 1283 1245 class SymmetricBandMatrix : public GeneralMatrix 1284 1246 { 1247 GeneralMatrix* Image() const; // copy of matrix 1285 1248 void CornerClear() const; // set unused elements to zero 1286 1249 short SimpleAddOK(const GeneralMatrix* gm); … … 1337 1300 void operator<<(const BaseMatrix& X) { GeneralMatrix::operator<<(X); } 1338 1301 void swap(SymmetricBandMatrix& gm); 1339 GeneralMatrix* Image() const; // copy of matrix1340 1302 NEW_DELETE(SymmetricBandMatrix) 1341 1303 }; … … 1352 1314 void ludcmp(); 1353 1315 void get_aux(BandLUMatrix&); // for copying indx[] etc 1316 GeneralMatrix* Image() const; // copy of matrix 1354 1317 public: 1355 1318 BandLUMatrix(const BaseMatrix&); … … 1379 1342 MatrixBandWidth bandwidth() const; 1380 1343 void swap(BandLUMatrix& gm); 1381 GeneralMatrix* Image() const; // copy of matrix1382 1344 NEW_DELETE(BandLUMatrix) 1383 1345 }; … … 1388 1350 class IdentityMatrix : public GeneralMatrix 1389 1351 { 1352 GeneralMatrix* Image() const; // copy of matrix 1390 1353 public: 1391 1354 IdentityMatrix() {} … … 1423 1386 void swap(IdentityMatrix& gm) 1424 1387 { GeneralMatrix::swap((GeneralMatrix&)gm); } 1425 GeneralMatrix* Image() const; // copy of matrix1426 1388 NEW_DELETE(IdentityMatrix) 1427 1389 }; … … 1447 1409 void operator=(const BaseMatrix&); 1448 1410 void operator+=(const BaseMatrix&); 1449 void SP_eq(const BaseMatrix&);1450 1411 void operator-=(const BaseMatrix&); 1451 1412 void operator*=(const BaseMatrix&); … … 1820 1781 void operator=(const BaseMatrix&); 1821 1782 void operator+=(const BaseMatrix&); 1822 void SP_eq(const BaseMatrix&);1823 1783 void operator-=(const BaseMatrix&); 1824 1784 void operator=(const GetSubMatrix& m) { operator=((const BaseMatrix&)m); } -
trunk/BNC/newmat/newmat.pro
r8901 r9434 10 10 MOC_DIR = .moc 11 11 12 HEADERS += boolean.hcontrolw.h include.h myexcept.h \13 newmatap.h newmat.h newmatio.h newmatnl.h\14 newmatrc.h newmatrm.h precisio.h solution.h12 HEADERS += controlw.h include.h myexcept.h \ 13 newmatap.h newmat.h newmatio.h \ 14 newmatrc.h newmatrm.h precisio.h 15 15 16 SOURCES += bandmat.cpp cholesky.cpp evalue.cpp 17 fft.cpp hholder.cpp jacobi.cpp 18 myexcept.cpp newfft.cpp newmat1.cpp 19 newmat2.cpp newmat3.cpp newmat4.cpp 20 newmat5.cpp newmat6.cpp newmat7.cpp 21 newmat8.cpp newmat9.cpp newmatex.cpp 22 newmatrm.cpp n ewmatnl.cpp nm_misc.cpp\23 sort.cpp submat.cpp svd.cpp solution.cpp16 SOURCES += bandmat.cpp cholesky.cpp evalue.cpp \ 17 fft.cpp hholder.cpp jacobi.cpp \ 18 myexcept.cpp newfft.cpp newmat1.cpp \ 19 newmat2.cpp newmat3.cpp newmat4.cpp \ 20 newmat5.cpp newmat6.cpp newmat7.cpp \ 21 newmat8.cpp newmat9.cpp newmatex.cpp \ 22 newmatrm.cpp nm_misc.cpp sort.cpp \ 23 submat.cpp svd.cpp 24 24 -
trunk/BNC/newmat/newmat6.cpp
r8901 r9434 495 495 Tracer tr("GeneralMatrix::operator+="); 496 496 // MatrixConversionCheck mcc; 497 Protect(); // so it cannot get deleted during Evaluate 497 Protect(); // so it cannot get deleted 498 // during Evaluate 498 499 GeneralMatrix* gm = ((BaseMatrix&)X).Evaluate(); 499 500 AddedMatrix am(this,gm); 500 501 if (gm==this) Release(2); else Release(); 501 502 Eq2(am,type()); 502 }503 504 // GeneralMatrix operators505 506 void GeneralMatrix::SP_eq(const BaseMatrix& X)507 {508 REPORT509 Tracer tr("GeneralMatrix::SP_eq");510 // MatrixConversionCheck mcc;511 Protect(); // so it cannot get deleted during Evaluate512 GeneralMatrix* gm = ((BaseMatrix&)X).Evaluate();513 SPMatrix spm(this,gm);514 if (gm==this) Release(2); else Release();515 Eq2(spm,type());516 503 } 517 504 … … 599 586 if (gmx==gm) gm->Release(2); else gm->Release(); 600 587 GeneralMatrix* gmy = am.Evaluate(); 601 if (gmy != gm) { REPORT delete gm; gm = gmy->Image(); }602 else { REPORT }603 gm->Protect();604 }605 606 void GenericMatrix::SP_eq(const BaseMatrix& X)607 {608 REPORT609 Tracer tr("GenericMatrix::SP_eq");610 if (!gm) Throw(ProgramException("GenericMatrix is null"));611 gm->Protect(); // so it cannot get deleted during Evaluate612 GeneralMatrix* gmx = ((BaseMatrix&)X).Evaluate();613 SPMatrix spm(gm,gmx);614 if (gmx==gm) gm->Release(2); else gm->Release();615 GeneralMatrix* gmy = spm.Evaluate();616 588 if (gmy != gm) { REPORT delete gm; gm = gmy->Image(); } 617 589 else { REPORT } -
trunk/BNC/newmat/newmat7.cpp
r8901 r9434 214 214 } 215 215 216 static void SP(GeneralMatrix* gm, constGeneralMatrix* gm2)217 { 218 REPORT 219 constReal* s2=gm2->Store(); Real* s=gm->Store(); int i=gm->Storage() >> 2;216 static void SP(GeneralMatrix* gm, GeneralMatrix* gm2) 217 { 218 REPORT 219 Real* s2=gm2->Store(); Real* s=gm->Store(); int i=gm->Storage() >> 2; 220 220 while (i--) 221 221 { *s++ *= *s2++; *s++ *= *s2++; *s++ *= *s2++; *s++ *= *s2++; } 222 222 i=gm->Storage() & 3; while (i--) *s++ *= *s2++; 223 }224 225 void GeneralMatrix::SP_Equal(const GeneralMatrix& gm)226 {227 REPORT228 if (nrows_val != gm.nrows_val || ncols_val != gm.ncols_val)229 Throw(IncompatibleDimensionsException(*this, gm));230 SP(this, &gm);231 223 } 232 224 -
trunk/BNC/newmat/newmat9.cpp
r8901 r9434 44 44 MatrixRow mr((GeneralMatrix*)&X, LoadOnEntry); 45 45 int w = s.width(); int nr = X.Nrows(); ios_format_flags f = s.flags(); 46 if (f & ios::scientific) s.setf(ios::scientific, ios::floatfield); 47 else s.setf(ios::fixed, ios::floatfield); 46 s.setf(ios::fixed, ios::floatfield); 48 47 for (int i=1; i<=nr; i++) 49 48 { -
trunk/BNC/newmat/newmatap.h
r8901 r9434 26 26 void QRZ(Matrix&, UpperTriangularMatrix&); 27 27 28 void QRZ(const Matrix&, Matrix&, Matrix&); 29 30 inline void QRZT(Matrix& X, Matrix& Y, LowerTriangularMatrix& L, Matrix& M) 31 { QRZT(X, L); QRZT(X, Y, M); } 32 33 inline void QRZ(Matrix& X, Matrix& Y, UpperTriangularMatrix& U, Matrix& M) 34 { QRZ(X, U); QRZ(X, Y, M); } 28 void QRZ(const Matrix&, Matrix&, Matrix&); 35 29 36 30 inline void HHDecompose(Matrix& X, LowerTriangularMatrix& L) … … 44 38 void updateQRZ(Matrix& X, UpperTriangularMatrix& U); 45 39 46 void updateQRZ(const Matrix& X, Matrix& MX, Matrix& MU);47 48 void updateQRZ(UpperTriangularMatrix& X, UpperTriangularMatrix& U);49 50 void updateQRZ(const UpperTriangularMatrix& X, Matrix& MX, Matrix& MU);51 52 40 inline void UpdateQRZT(Matrix& X, LowerTriangularMatrix& L) 53 41 { updateQRZT(X, L); } … … 55 43 inline void UpdateQRZ(Matrix& X, UpperTriangularMatrix& U) 56 44 { updateQRZ(X, U); } 57 58 inline void UpdateQRZ(UpperTriangularMatrix& X, UpperTriangularMatrix& U)59 { updateQRZ(X, U); }60 61 inline void UpdateQRZ(const UpperTriangularMatrix& X, Matrix& MX, Matrix& MU)62 { updateQRZ(X, MX, MU); }63 64 inline void UpdateQRZ(const Matrix& X, Matrix& MX, Matrix& MU)65 { updateQRZ(X, MX, MU); }66 67 45 68 46 // Matrix A's first n columns are orthonormal … … 78 56 79 57 80 // produces the Cholesky decomposition of A + x.t() * x 81 // where A = chol.t() * choland x is a RowVector58 // produces the Cholesky decomposition of A + x.t() * x where A = chol.t() * chol 59 // and x is a RowVector 82 60 void update_Cholesky(UpperTriangularMatrix& chol, RowVector x); 83 61 inline void UpdateCholesky(UpperTriangularMatrix& chol, const RowVector& x) 84 62 { update_Cholesky(chol, x); } 85 63 86 // produces the Cholesky decomposition of A - x.t() * x 87 // where A = chol.t() * choland x is a RowVector64 // produces the Cholesky decomposition of A - x.t() * x where A = chol.t() * chol 65 // and x is a RowVector 88 66 void downdate_Cholesky(UpperTriangularMatrix &chol, RowVector x); 89 67 inline void DowndateCholesky(UpperTriangularMatrix &chol, const RowVector& x) -
trunk/BNC/newmat/newmatio.h
r8901 r9434 16 16 #include "newmat.h" 17 17 18 #ifdef use_namespace19 namespace NEWMAT { 18 #ifdef USE_STD_NAMESPACE 19 using namespace std; 20 20 #endif 21 22 23 21 24 22 // **************************** input/output *****************************/ -
trunk/BNC/newmat/precisio.h
r8901 r9434 25 25 #endif 26 26 27 using namespace std;28 29 27 /// Floating point precision. 30 28 class FloatingPointPrecision … … 32 30 public: 33 31 static int Dig() // number of decimal digits or precision 34 { return numeric_limits<Real>::digits10 ; }32 { return std::numeric_limits<Real>::digits10 ; } 35 33 36 34 static Real Epsilon() // smallest number such that 1+Eps!=Eps 37 { return numeric_limits<Real>::epsilon(); }35 { return std::numeric_limits<Real>::epsilon(); } 38 36 39 37 static int Mantissa() // bits in mantisa 40 { return numeric_limits<Real>::digits; }38 { return std::numeric_limits<Real>::digits; } 41 39 42 40 static Real Maximum() // maximum value 43 { return numeric_limits<Real>::max(); }41 { return std::numeric_limits<Real>::max(); } 44 42 45 43 static int MaximumDecimalExponent() // maximum decimal exponent 46 { return numeric_limits<Real>::max_exponent10; }44 { return std::numeric_limits<Real>::max_exponent10; } 47 45 48 46 static int MaximumExponent() // maximum binary exponent 49 { return numeric_limits<Real>::max_exponent; }47 { return std::numeric_limits<Real>::max_exponent; } 50 48 51 49 static Real LnMaximum() // natural log of maximum … … 53 51 54 52 static Real Minimum() // minimum positive value 55 { return numeric_limits<Real>::min(); }53 { return std::numeric_limits<Real>::min(); } 56 54 57 55 static int MinimumDecimalExponent() // minimum decimal exponent 58 { return numeric_limits<Real>::min_exponent10; }56 { return std::numeric_limits<Real>::min_exponent10; } 59 57 60 58 static int MinimumExponent() // minimum binary exponent 61 { return numeric_limits<Real>::min_exponent; }59 { return std::numeric_limits<Real>::min_exponent; } 62 60 63 61 static Real LnMinimum() // natural log of minimum … … 65 63 66 64 static int Radix() // exponent radix 67 { return numeric_limits<Real>::radix; }65 { return std::numeric_limits<Real>::radix; } 68 66 69 67 static int Rounds() // addition rounding (1 = does round) 70 68 { 71 return numeric_limits<Real>::round_style ==72 round_to_nearest ? 1 : 0;69 return std::numeric_limits<Real>::round_style == 70 std::round_to_nearest ? 1 : 0; 73 71 } 74 72 -
trunk/BNC/newmat/submat.cpp
r8901 r9434 257 257 if (row_number != gmx->Nrows() || col_number != gmx->Ncols()) 258 258 Throw(IncompatibleDimensionsException()); 259 if (gm->type().is_symmetric() &&260 ( ! gmx->type().is_symmetric() || row_skip != col_skip) )261 Throw(ProgramException("Illegal operation on symmetric"));262 259 MatrixRow mrx(gmx, LoadOnEntry); 263 260 MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart, row_skip); … … 280 277 } 281 278 282 void GetSubMatrix:: SP_eq(const BaseMatrix& bmx)283 { 284 REPORT 285 Tracer tr("SubMatrix( SP_eq)"); GeneralMatrix* gmx = 0;279 void GetSubMatrix::operator-=(const BaseMatrix& bmx) 280 { 281 REPORT 282 Tracer tr("SubMatrix(-=)"); GeneralMatrix* gmx = 0; 286 283 // MatrixConversionCheck mcc; // Check for loss of info 287 284 Try … … 290 287 if (row_number != gmx->Nrows() || col_number != gmx->Ncols()) 291 288 Throw(IncompatibleDimensionsException()); 292 if (gm->type().is_symmetric() &&293 ( ! gmx->type().is_symmetric() || row_skip != col_skip) )294 Throw(ProgramException("Illegal operation on symmetric"));295 MatrixRow mrx(gmx, LoadOnEntry);296 MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart, row_skip);297 // do need LoadOnEntry298 MatrixRowCol sub; int i = row_number;299 while (i--)300 {301 mr.SubRowCol(sub, col_skip, col_number); // put values in sub302 sub.Multiply(mrx); mr.Next(); mrx.Next();303 }304 gmx->tDelete();305 }306 307 CatchAll308 {309 if (gmx) gmx->tDelete();310 ReThrow;311 }312 }313 314 void GetSubMatrix::operator-=(const BaseMatrix& bmx)315 {316 REPORT317 Tracer tr("SubMatrix(-=)"); GeneralMatrix* gmx = 0;318 // MatrixConversionCheck mcc; // Check for loss of info319 Try320 {321 SetUpLHS(); gmx = ((BaseMatrix&)bmx).Evaluate();322 if (row_number != gmx->Nrows() || col_number != gmx->Ncols())323 Throw(IncompatibleDimensionsException());324 if (gm->type().is_symmetric() &&325 ( ! gmx->type().is_symmetric() || row_skip != col_skip) )326 Throw(ProgramException("Illegal operation on symmetric"));327 289 MatrixRow mrx(gmx, LoadOnEntry); 328 290 MatrixRow mr(gm, LoadOnEntry+StoreOnExit+DirectPart, row_skip);
Note:
See TracChangeset
for help on using the changeset viewer.