void TestUpdateQRZ::Reset() { int i, j; // set up Matrices X1.ReSize(m, n1); X2.ReSize(m, n2); X3.ReSize(m, n3); for (i = 1; i <= m; ++i) for (j = 1; j <= n1; ++j) X1(i, j) = 2.0 * (mwc.Next() - 0.5); for (i = 1; i <= m; ++i) for (j = 1; j <= n2; ++j) X2(i, j) = 2.0 * (mwc.Next() - 0.5); for (i = 1; i <= m; ++i) for (j = 1; j <= n3; ++j) X3(i, j) = 2.0 * (mwc.Next() - 0.5); }
static void test(int n) { Tracer et("Test FFT"); MultWithCarry mwc; ColumnVector A(n), B(n), X, Y; for (int i=0; i<n; i++) { A.element(i) = mwc.Next(); B.element(i) = mwc.Next(); } FFT(A, B, X, Y); FFTI(X, Y, X, Y); X = X - A; Y = Y - B; Clean(X,0.000000001); Clean(Y,0.000000001); Print(X); Print(Y); }
static void test2(int n) { Tracer et("cf FFT and slow FT"); MultWithCarry mwc; ColumnVector A(n), B(n), X, Y, X1, Y1; for (int i=0; i<n; i++) { A.element(i) = mwc.Next(); B.element(i) = mwc.Next(); } FFT(A, B, X, Y); SlowFT(A, B, X1, Y1); X = X - X1; Y = Y - Y1; Clean(X,0.000000001); Clean(Y,0.000000001); Print(X); Print(Y); }
static void test9(int m, int n) { Tracer et("cf FFT2 and slow FT2"); MultWithCarry mwc; Matrix A(m,n), B(m,n), X, Y, X1, Y1; for (int i=0; i<m; i++) for (int j=0; j<n; j++) { A.element(i,j) = mwc.Next(); B.element(i,j) = mwc.Next(); } FFT2(A, B, X, Y); SlowFT2(A, B, X1, Y1); X = X - X1; Y = Y - Y1; Clean(X,0.000000001); Clean(Y,0.000000001); Print(X); Print(Y); FFT2I(X1, Y1, X1, Y1); X1 -= A; Y1 -= B; Clean(X1,0.000000001); Clean(Y1,0.000000001); Print(X1); Print(Y1); }
static void test5(int n) { Tracer et("Test DST_II"); MultWithCarry mwc; ColumnVector A1(n); for (int i=0; i<n; i++) A1.element(i) = mwc.Next(); // do DST II by ordinary FFT ColumnVector P(2*n), Q(2*n); P = 0.0; Q = 0.0; P.Rows(1,n) = A1; FFT(P, Q, P, Q); ColumnVector B1(n); for (int k=1; k<=n; k++) { Real arg = k * 6.2831853071795864769 / (4 * n); B1(k) = P(k+1) * sin(arg) - Q(k+1) * cos(arg); } // use DST_II routine ColumnVector B2; DST_II(A1,B2); // test inverse ColumnVector A2; DST_II_inverse(B2,A2); A1 -= A2; B1 -= B2; Clean(A1,0.000000001); Clean(B1,0.000000001); Print(A1); Print(B1); }
static void test3(int n) { Tracer et("cf slow and fast DCT_II and DST_II"); MultWithCarry mwc; ColumnVector A(n), X, Y, X1, Y1; for (int i=0; i<n; i++) A.element(i) = mwc.Next(); DCT_II(A, X); DST_II(A, Y); SlowDTT_II(A, X1, Y1); X -= X1; Y -= Y1; Clean(X,0.000000001); Clean(Y,0.000000001); Print(X); Print(Y); }
static void test1(int n) { Tracer et("Test RealFFT"); MultWithCarry mwc; ColumnVector A(n), B(n), X, Y; for (int i=0; i<n; i++) A.element(i) = mwc.Next(); B = 0.0; FFT(A, B, X, Y); B.CleanUp(); // release some space int n2 = n/2+1; ColumnVector X1,Y1,X2,Y2; RealFFT(A, X1, Y1); X2 = X1 - X.Rows(1,n2); Y2 = Y1 - Y.Rows(1,n2); Clean(X2,0.000000001); Clean(Y2,0.000000001); Print(X2); Print(Y2); X2.CleanUp(); Y2.CleanUp(); // release some more space RealFFTI(X1,Y1,B); B = A - B; Clean(B,0.000000001); Print(B); }
static void test7(int n) { Tracer et("Test DCT"); MultWithCarry mwc; ColumnVector A1(n+1); for (int i=0; i<=n; i++) A1.element(i) = mwc.Next(); // do DCT by ordinary FFT ColumnVector P(2*n), Q(2*n); P = 0.0; Q = 0.0; P.Rows(1,n+1) = A1; P(1) /= 2.0; P(n+1) /= 2.0; FFT(P, Q, P, Q); ColumnVector B1 = P.Rows(1,n+1); // use DCT routine ColumnVector B2; DCT(A1,B2); // test inverse ColumnVector A2; DCT_inverse(B2,A2); A1 -= A2; B1 -= B2; Clean(A1,0.000000001); Clean(B1,0.000000001); Print(A1); Print(B1); }
void trymatd() { Tracer et("Thirteenth test of Matrix package"); Tracer::PrintTrace(); Matrix X(5,20); int i,j; for (j=1;j<=20;j++) X(1,j) = j+1; for (i=2;i<=5;i++) for (j=1;j<=20; j++) X(i,j) = (long)X(i-1,j) * j % 1001; SymmetricMatrix S; S << X * X.t(); Matrix SM = X * X.t() - S; Print(SM); LowerTriangularMatrix L = Cholesky(S); Matrix Diff = L*L.t()-S; Clean(Diff, 0.000000001); Print(Diff); { Tracer et1("Stage 1"); LowerTriangularMatrix L1(5); Matrix Xt = X.t(); Matrix Xt2 = Xt; QRZT(X,L1); Diff = L - L1; Clean(Diff,0.000000001); Print(Diff); UpperTriangularMatrix Ut(5); QRZ(Xt,Ut); Diff = L - Ut.t(); Clean(Diff,0.000000001); Print(Diff); Matrix Y(3,20); for (j=1;j<=20;j++) Y(1,j) = 22-j; for (i=2;i<=3;i++) for (j=1;j<=20; j++) Y(i,j) = (long)Y(i-1,j) * j % 101; Matrix Yt = Y.t(); Matrix M,Mt; Matrix Y2=Y; QRZT(X,Y,M); QRZ(Xt,Yt,Mt); Diff = Xt - X.t(); Clean(Diff,0.000000001); Print(Diff); Diff = Yt - Y.t(); Clean(Diff,0.000000001); Print(Diff); Diff = Mt - M.t(); Clean(Diff,0.000000001); Print(Diff); Diff = Y2 * Xt2 * S.i() - M * L.i(); Clean(Diff,0.000000001); Print(Diff); } ColumnVector C1(5); { Tracer et1("Stage 2"); X.ReSize(5,5); for (j=1;j<=5;j++) X(1,j) = j+1; for (i=2;i<=5;i++) for (j=1;j<=5; j++) X(i,j) = (long)X(i-1,j) * j % 1001; for (i=1;i<=5;i++) C1(i) = i*i; CroutMatrix A = X; ColumnVector C2 = A.i() * C1; C1 = X.i() * C1; X = C1 - C2; Clean(X,0.000000001); Print(X); } { Tracer et1("Stage 3"); X.ReSize(7,7); for (j=1;j<=7;j++) X(1,j) = j+1; for (i=2;i<=7;i++) for (j=1;j<=7; j++) X(i,j) = (long)X(i-1,j) * j % 1001; C1.ReSize(7); for (i=1;i<=7;i++) C1(i) = i*i; RowVector R1 = C1.t(); Diff = R1 * X.i() - ( X.t().i() * R1.t() ).t(); Clean(Diff,0.000000001); Print(Diff); } { Tracer et1("Stage 4"); X.ReSize(5,5); for (j=1;j<=5;j++) X(1,j) = j+1; for (i=2;i<=5;i++) for (j=1;j<=5; j++) X(i,j) = (long)X(i-1,j) * j % 1001; C1.ReSize(5); for (i=1;i<=5;i++) C1(i) = i*i; CroutMatrix A1 = X*X; ColumnVector C2 = A1.i() * C1; C1 = X.i() * C1; C1 = X.i() * C1; X = C1 - C2; Clean(X,0.000000001); Print(X); } { Tracer et1("Stage 5"); int n = 40; SymmetricBandMatrix B(n,2); B = 0.0; for (i=1; i<=n; i++) { B(i,i) = 6; if (i<=n-1) B(i,i+1) = -4; if (i<=n-2) B(i,i+2) = 1; } B(1,1) = 5; B(n,n) = 5; SymmetricMatrix A = B; ColumnVector X(n); X(1) = 429; for (i=2;i<=n;i++) X(i) = (long)X(i-1) * 31 % 1001; X = X / 100000L; // the matrix B is rather ill-conditioned so the difficulty is getting // good agreement (we have chosen X very small) may not be surprising; // maximum element size in B.i() is around 1400 ColumnVector Y1 = A.i() * X; LowerTriangularMatrix C1 = Cholesky(A); ColumnVector Y2 = C1.t().i() * (C1.i() * X) - Y1; Clean(Y2, 0.000000001); Print(Y2); UpperTriangularMatrix CU = C1.t().i(); LowerTriangularMatrix CL = C1.i(); Y2 = CU * (CL * X) - Y1; Clean(Y2, 0.000000001); Print(Y2); Y2 = B.i() * X - Y1; Clean(Y2, 0.000000001); Print(Y2); LowerBandMatrix C2 = Cholesky(B); Matrix M = C2 - C1; Clean(M, 0.000000001); Print(M); ColumnVector Y3 = C2.t().i() * (C2.i() * X) - Y1; Clean(Y3, 0.000000001); Print(Y3); CU = C1.t().i(); CL = C1.i(); Y3 = CU * (CL * X) - Y1; Clean(Y3, 0.000000001); Print(Y3); Y3 = B.i() * X - Y1; Clean(Y3, 0.000000001); Print(Y3); SymmetricMatrix AI = A.i(); Y2 = AI*X - Y1; Clean(Y2, 0.000000001); Print(Y2); SymmetricMatrix BI = B.i(); BandMatrix C = B; Matrix CI = C.i(); M = A.i() - CI; Clean(M, 0.000000001); Print(M); M = B.i() - CI; Clean(M, 0.000000001); Print(M); M = AI-BI; Clean(M, 0.000000001); Print(M); M = AI-CI; Clean(M, 0.000000001); Print(M); M = A; AI << M; M = AI-A; Clean(M, 0.000000001); Print(M); C = B; BI << C; M = BI-B; Clean(M, 0.000000001); Print(M); } { Tracer et1("Stage 5"); SymmetricMatrix A(4), B(4); A << 5 << 1 << 4 << 2 << 1 << 6 << 1 << 0 << 1 << 7; B << 8 << 1 << 5 << 1 << 0 << 9 << 2 << 1 << 0 << 6; LowerTriangularMatrix AB = Cholesky(A) * Cholesky(B); Matrix M = Cholesky(A) * B * Cholesky(A).t() - AB*AB.t(); Clean(M, 0.000000001); Print(M); M = A * Cholesky(B); M = M * M.t() - A * B * A; Clean(M, 0.000000001); Print(M); } { Tracer et1("Stage 6"); int N=49; int i; SymmetricBandMatrix S(N,1); Matrix B(N,N+1); B=0; for (i=1;i<=N;i++) { S(i,i)=1; B(i,i)=1; B(i,i+1)=-1; } for (i=1;i<N; i++) S(i,i+1)=-.5; DiagonalMatrix D(N+1); D = 1; B = B.t()*S.i()*B - (D-1.0/(N+1))*2.0; Clean(B, 0.000000001); Print(B); } { Tracer et1("Stage 7"); // Copying and moving CroutMatrix Matrix A(7,7); A.Row(1) << 3 << 2 << -1 << 4 << -3 << 5 << 9; A.Row(2) << -8 << 7 << 2 << 0 << 7 << 0 << -1; A.Row(3) << 2 << -2 << 3 << 1 << 9 << 0 << 3; A.Row(4) << -1 << 5 << 2 << 2 << 5 << -1 << 2; A.Row(5) << 4 << -4 << 1 << 9 << -8 << 7 << 5; A.Row(6) << 1 << -2 << 5 << -1 << -2 << 5 << 1; A.Row(7) << -6 << 3 << -1 << 8 << -1 << 2 << 2; RowVector D(30); D = 0; Real x = determinant(A); CroutMatrix B = A; D(1) = determinant(B) / x - 1; Matrix C = A * Inverter1(B) - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); // Test copy constructor (in Inverter2 and ordinary copy) CroutMatrix B1; B1 = B; D(2) = determinant(B1) / x - 1; C = A * Inverter2(B1) - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); // Do it again with release B.release(); B1 = B; D(2) = B.nrows(); D(3) = B.ncols(); D(4) = B.size(); D(5) = determinant(B1) / x - 1; B1.release(); C = A * Inverter2(B1) - IdentityMatrix(7); D(6) = B1.nrows(); D(7) = B1.ncols(); D(8) = B1.size(); Clean(C, 0.000000001); Print(C); // see if we get an implicit invert B1 = -A; D(9) = determinant(B1) / x + 1; // odd number of rows - sign will change C = -A * Inverter2(B1) - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); // check for_return B = LU1(A); B1 = LU2(A); CroutMatrix B2 = LU3(A); C = A * B.i() - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); D(10) = (B == B1 ? 0 : 1) + (B == B2 ? 0 : 1); // check lengths D(13) = B.size()-49; // check release(2) B1.release(2); B2 = B1; D(15) = B == B2 ? 0 : 1; CroutMatrix B3 = B1; D(16) = B == B3 ? 0 : 1; D(17) = B1.size(); // some oddments B1 = B; B1 = B1.i(); C = A - B1.i(); Clean(C, 0.000000001); Print(C); B1 = B; B1.release(); B1 = B1; B2 = B1; D(19) = B == B1 ? 0 : 1; D(20) = B == B2 ? 0 : 1; B1.cleanup(); B2 = B1; D(21) = B1.size(); D(22) = B2.size(); GenericMatrix GM = B; C = A.i() - GM.i(); Clean(C, 0.000000001); Print(C); B1 = GM; D(23) = B == B1 ? 0 : 1; B1 = A * 0; B2 = B1; D(24) = B2.is_singular() ? 0 : 1; // check release again - see if memory moves const Real* d = B.const_data(); const int* i = B.const_data_indx(); B1 = B; const Real* d1 = B1.const_data(); const int* i1 = B1.const_data_indx(); B1.release(); B2 = B1; const Real* d2 = B2.const_data(); const int* i2 = B2.const_data_indx(); D(25) = (d != d1 ? 0 : 1) + (d1 == d2 ? 0 : 1) + (i != i1 ? 0 : 1) + (i1 == i2 ? 0 : 1); Clean(D, 0.000000001); Print(D); } { Tracer et1("Stage 8"); // Same for BandLUMatrix BandMatrix A(7,3,2); A.Row(1) << 3 << 2 << -1; A.Row(2) << -8 << 7 << 2 << 0; A.Row(3) << 2 << -2 << 3 << 1 << 9; A.Row(4) << -1 << 5 << 2 << 2 << 5 << -1; A.Row(5) << -4 << 1 << 9 << -8 << 7 << 5; A.Row(6) << 5 << -1 << -2 << 5 << 1; A.Row(7) << 8 << -1 << 2 << 2; RowVector D(30); D = 0; Real x = determinant(A); BandLUMatrix B = A; D(1) = determinant(B) / x - 1; Matrix C = A * Inverter1(B) - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); // Test copy constructor (in Inverter2 and ordinary copy) BandLUMatrix B1; B1 = B; D(2) = determinant(B1) / x - 1; C = A * Inverter2(B1) - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); // Do it again with release B.release(); B1 = B; D(2) = B.nrows(); D(3) = B.ncols(); D(4) = B.size(); D(5) = determinant(B1) / x - 1; B1.release(); C = A * Inverter2(B1) - IdentityMatrix(7); D(6) = B1.nrows(); D(7) = B1.ncols(); D(8) = B1.size(); Clean(C, 0.000000001); Print(C); // see if we get an implicit invert B1 = -A; D(9) = determinant(B1) / x + 1; // odd number of rows - sign will change C = -A * Inverter2(B1) - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); // check for_return B = LU1(A); B1 = LU2(A); BandLUMatrix B2 = LU3(A); C = A * B.i() - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); D(10) = (B == B1 ? 0 : 1) + (B == B2 ? 0 : 1); // check lengths D(11) = B.bandwidth().lower()-3; D(12) = B.bandwidth().upper()-2; D(13) = B.size()-42; D(14) = B.size2()-21; // check release(2) B1.release(2); B2 = B1; D(15) = B == B2 ? 0 : 1; BandLUMatrix B3 = B1; D(16) = B == B3 ? 0 : 1; D(17) = B1.size(); // Compare with CroutMatrix CroutMatrix CM = A; C = CM.i() - B.i(); Clean(C, 0.000000001); Print(C); D(18) = determinant(CM) / x - 1; // some oddments B1 = B; CM = B1.i(); C = A - CM.i(); Clean(C, 0.000000001); Print(C); B1 = B; B1.release(); B1 = B1; B2 = B1; D(19) = B == B1 ? 0 : 1; D(20) = B == B2 ? 0 : 1; B1.cleanup(); B2 = B1; D(21) = B1.size(); D(22) = B2.size(); GenericMatrix GM = B; C = A.i() - GM.i(); Clean(C, 0.000000001); Print(C); B1 = GM; D(23) = B == B1 ? 0 : 1; B1 = A * 0; B2 = B1; D(24) = B2.is_singular() ? 0 : 1; // check release again - see if memory moves const Real* d = B.const_data(); const Real* dd = B.const_data(); const int* i = B.const_data_indx(); B1 = B; const Real* d1 = B1.const_data(); const Real* dd1 = B1.const_data(); const int* i1 = B1.const_data_indx(); B1.release(); B2 = B1; const Real* d2 = B2.const_data(); const Real* dd2 = B2.const_data(); const int* i2 = B2.const_data_indx(); D(25) = (d != d1 ? 0 : 1) + (d1 == d2 ? 0 : 1) + (dd != dd1 ? 0 : 1) + (dd1 == dd2 ? 0 : 1) + (i != i1 ? 0 : 1) + (i1 == i2 ? 0 : 1); Clean(D, 0.000000001); Print(D); } { Tracer et1("Stage 9"); // Modification of Cholesky decomposition int i, j; // Build test matrix Matrix X(100, 10); MultWithCarry mwc; // Uniform random number generator for (i = 1; i <= 100; ++i) for (j = 1; j <= 10; ++j) X(i, j) = 2.0 * (mwc.Next() - 0.5); Matrix X1 = X; // save copy // Form sums of squares and products matrix and Cholesky decompose SymmetricMatrix A; A << X.t() * X; UpperTriangularMatrix U1 = Cholesky(A).t(); // Do QR decomposition of X and check we get same triangular matrix UpperTriangularMatrix U2; QRZ(X, U2); Matrix Diff = U1 - U2; Clean(Diff, 0.000000001); Print(Diff); // Try adding new row to X and updating triangular matrix RowVector NewRow(10); for (j = 1; j <= 10; ++j) NewRow(j) = 2.0 * (mwc.Next() - 0.5); UpdateCholesky(U2, NewRow); X = X1 & NewRow; QRZ(X, U1); Diff = U1 - U2; Clean(Diff, 0.000000001); Print(Diff); // Try removing two rows and updating triangular matrix DowndateCholesky(U2, X1.Row(20)); DowndateCholesky(U2, X1.Row(35)); X = X1.Rows(1,19) & X1.Rows(21,34) & X1.Rows(36,100) & NewRow; QRZ(X, U1); Diff = U1 - U2; Clean(Diff, 0.000000001); Print(Diff); // Circular shifts CircularShift(X, 3,6); CircularShift(X, 5,5); CircularShift(X, 4,5); CircularShift(X, 1,6); CircularShift(X, 6,10); } { Tracer et1("Stage 10"); // Try updating QRZ, QRZT decomposition TestUpdateQRZ tuqrz1(10, 100, 50, 25); tuqrz1.DoTest(); tuqrz1.Reset(); tuqrz1.ClearRow(1); tuqrz1.DoTest(); tuqrz1.Reset(); tuqrz1.ClearRow(1); tuqrz1.ClearRow(2); tuqrz1.DoTest(); tuqrz1.Reset(); tuqrz1.ClearRow(5); tuqrz1.ClearRow(6); tuqrz1.DoTest(); tuqrz1.Reset(); tuqrz1.ClearRow(10); tuqrz1.DoTest(); TestUpdateQRZ tuqrz2(15, 100, 0, 0); tuqrz2.DoTest(); tuqrz2.Reset(); tuqrz2.ClearRow(1); tuqrz2.DoTest(); tuqrz2.Reset(); tuqrz2.ClearRow(1); tuqrz2.ClearRow(2); tuqrz2.DoTest(); tuqrz2.Reset(); tuqrz2.ClearRow(5); tuqrz2.ClearRow(6); tuqrz2.DoTest(); tuqrz2.Reset(); tuqrz2.ClearRow(15); tuqrz2.DoTest(); TestUpdateQRZ tuqrz3(5, 0, 10, 0); tuqrz3.DoTest(); } // cout << "\nEnd of Thirteenth test\n"; }
void trymat9() { Tracer et("Ninth test of Matrix package"); Tracer::PrintTrace(); int i; int j; Matrix A(7,7); Matrix X(7,3); for (i=1;i<=7;i++) for (j=1;j<=7;j++) A(i,j)=i*i+j+((i==j) ? 1 : 0); for (i=1;i<=7;i++) for (j=1;j<=3;j++) X(i,j)=i-j; Matrix B = A.i(); DiagonalMatrix D(7); D=1.0; { Tracer et1("Stage 1"); Matrix Q = B*A-D; Clean(Q, 0.000000001); Print(Q); Q=A; Q = Q.i() * X; Q = A*Q - X; Clean(Q, 0.000000001); Print(Q); Q=X; Q = A.i() * Q; Q = A*Q - X; Clean(Q, 0.000000001); Print(Q); } for (i=1;i<=7;i++) D(i,i)=i*i+1; DiagonalMatrix E(3); for (i=1;i<=3;i++) E(i,i)=i+23; { Tracer et1("Stage 2"); Matrix DXE = D.i() * X * E; DXE = E.i() * DXE.t() * D - X.t(); Clean(DXE, 0.00000001); Print(DXE); E=D; for (i=1;i<=7;i++) E(i,i)=i*3+1; } DiagonalMatrix F=D; { Tracer et1("Stage 3"); F=E.i()*F; F=F*E-D; Clean(F,0.00000001); Print(F); F=E.i()*D; F=F*E-D; Clean(F,0.00000001); Print(F); } { Tracer et1("Stage 4"); F=E; F=F.i()*D; F=F*E-D; Clean(F,0.00000001); Print(F); } { Tracer et1("Stage 5"); // testing equal ColumnVector A(18), B(18); Matrix X(3,3); X << 3 << 5 << 7 << 5 << 8 << 2 << 7 << 2 << 9; SymmetricMatrix S; S << X; B(1) = S == X; A(1) = true; B(2) = S == (X+1); A(2) = false; B(3) = (S+2) == (X+2); A(3) = true; Matrix Y = X; B(4) = X == Y; A(4) = true; B(5) = (X*2) == (Y*2); A(5) = true; Y(3,3) = 10; B(6) = X == Y; A(6) = false; B(7) = (X*2) == (Y*2); A(7) = false; B(8) = S == Y; A(8) = false; B(9) = S == S; A(9) = true; Matrix Z = X.SubMatrix(1,2,2,3); B(10) = X == Z; A(10) = false; GenericMatrix GS = S; GenericMatrix GX = X; GenericMatrix GY = Y; B(11) = GS == GX; A(11) = true; B(12) = GS == GY; A(12) = false; CroutMatrix CS = S; CroutMatrix CX = X; CroutMatrix CY = Y; B(13) = CS == CX; A(13) = true; B(14) = CS == CY; A(14) = false; B(15) = X == CX; A(15) = false; B(16) = X == A; A(16) = false; B(17) = X == (X | X); A(17) = false; B(18) = CX == X; A(18) = false; A = A - B; Print(A); } { Tracer et1("Stage 6"); // testing equal ColumnVector A(22), B(22); BandMatrix X(6,2,1); X(1,1)=23; X(1,2)=21; X(2,1)=12; X(2,2)=17; X(2,3)=45; X(3,1)=35; X(3,2)=19; X(3,3)=24; X(3,4)=29; X(4,2)=17; X(4,3)=11; X(4,4)=19; X(4,5)=35; X(5,3)=10; X(5,4)=44; X(5,5)=23; X(5,6)=31; X(6,4)=49; X(6,5)=41; X(6,6)=17; SymmetricBandMatrix S1(6,2); S1.Inject(X); BandMatrix U(6,2,3); U = 0.0; U.Inject(X); B(1) = U == X; A(1) = true; B(2) = U == (X*3); A(2) = false; B(3) = (U*5) == (X*5); A(3) = true; Matrix Y = X; B(4) = X == Y; A(4) = true; B(5) = (X*2) == (Y*2); A(5) = true; Y(6,6) = 10; B(6) = X == Y; A(6) = false; B(7) = (X*2) == (Y*2); A(7) = false; B(8) = U == Y; A(8) = false; B(9) = U == U; A(9) = true; Matrix Z = X.SubMatrix(1,2,2,3); B(10) = X == Z; A(10) = false; GenericMatrix GU = U; GenericMatrix GX = X; GenericMatrix GY = Y; B(11) = GU == GX; A(11) = true; B(12) = GU == GY; A(12) = false; X = X + X.t(); U = U + U.t(); SymmetricBandMatrix S(6,2); S.Inject(X); Matrix D = S-X; Print(D); BandLUMatrix BS = S; BandLUMatrix BX = X; BandLUMatrix BU = U; CroutMatrix CX = X; B(13) = BS == BX; A(13) = true; B(14) = BX == BU; A(14) = false; B(15) = X == BX; A(15) = false; B(16) = X != BX; A(16) = true; B(17) = BX != BS; A(17) = false; B(18) = (2*X) != (X*2);A(18) = false; B(19) = (X*2) != (X+2);A(19) = true; B(20) = BX == CX; A(20) = false; B(21) = CX == BX; A(21) = false; B(22) = BX == X; A(22) = false; A = A - B; Print(A); DiagonalMatrix I(6); I=1.0; D = BS.i() * X - I; Clean(D,0.00000001); Print(D); D = BX.i() * X - I; Clean(D,0.00000001); Print(D); D = BU.i() * X - I; Clean(D,0.00000001); Print(D); // test row wise load SymmetricBandMatrix X1(6,2); X1.Row(1) << 23; X1.Row(2) << 12 << 17; X1.Row(3) << 35 << 19 << 24; X1.Row(4) << 17 << 11 << 19; X1.Row(5) << 10 << 44 << 23; X1.Row(6) << 49 << 41 << 17; Matrix M = X1 - S1; Print(M); // check out submatrix SymmetricBandMatrix X2(20,3); X2 = 0.0; X2.SubMatrix(2,7,2,7) = X1; X2.SymSubMatrix(11,16) = 2 * X1; Matrix MX1 = X1; Matrix MX2(20,20); MX2 = 0; MX2.SymSubMatrix(2,7) = MX1; MX2.SubMatrix(11,16,11,16) = MX1 * 2; MX2 -= X2; Print(MX2); BandMatrix X4(20,3,3); X4 = 0.0; X4.SubMatrix(2,7,3,8) = X1; X4.SubMatrix(11,16,10,15) = 2 * X1; MX1 = X1; Matrix MX4(20,20); MX4 = 0; MX4.SubMatrix(2,7,3,8) = MX1; MX4.SubMatrix(11,16,10,15) = MX1 * 2; MX4 -= X4; Print(MX4); MX1 = X1.i() * X1 - IdentityMatrix(6); Clean(MX1,0.00000001); Print(MX1); } { Tracer et1("Stage 7"); // testing equal ColumnVector A(12), B(12); BandMatrix X(6,2,1); X(1,1)=23; X(1,2)=21; X(2,1)=12; X(2,2)=17; X(2,3)=45; X(3,1)=35; X(3,2)=19; X(3,3)=24; X(3,4)=29; X(4,2)=17; X(4,3)=11; X(4,4)=19; X(4,5)=35; X(5,3)=10; X(5,4)=44; X(5,5)=23; X(5,6)=31; X(6,4)=49; X(6,5)=41; X(6,6)=17; Matrix Y = X; LinearEquationSolver LX = X; LinearEquationSolver LY = Y; CroutMatrix CX = X; CroutMatrix CY = Y; BandLUMatrix BX = X; B(1) = LX == CX; A(1) = false; B(2) = LY == CY; A(2) = true; B(3) = X == Y; A(3) = true; B(4) = BX == LX; A(4) = true; B(5) = CX == CY; A(5) = true; B(6) = LX == LY; A(6) = false; B(7) = BX == BX; A(7) = true; B(8) = CX == CX; A(8) = true; B(9) = LX == LX; A(9) = true; B(10) = LY == LY; A(10) = true; CroutMatrix CX1 = X.SubMatrix(1,4,1,4); B(11) = CX == CX1; A(11) = false; BandLUMatrix BX1 = X.SymSubMatrix(1,4); // error with SubMatrix B(12) = BX == BX1; A(12) = false; A = A - B; Print(A); DiagonalMatrix I(6); I=1.0; Matrix D; D = LX.i() * X - I; Clean(D,0.00000001); Print(D); D = LY.i() * X - I; Clean(D,0.00000001); Print(D); I.ReSize(4); I = 1; D = CX1.i() * X.SymSubMatrix(1,4) - I; Clean(D,0.00000001); Print(D); D = BX1.i() * X.SubMatrix(1,4,1,4) - I; Clean(D,0.00000001); Print(D); } { Tracer et1("Stage 8"); // test copying CroutMatrix and BandLUMatrix - see also tmtd.cpp MultWithCarry MWC; SymmetricBandMatrix SBM(50, 10); for (int i = 1; i <= 50; ++i) for (int j = 1; j <= i; ++j) if (i - j <= 10) SBM(i, j) = MWC.Next(); CroutMatrix CM = SBM; BandLUMatrix BM = SBM; CroutMatrix CM1 = CM; BandLUMatrix BM1; BM1 = BM; CM1.release(); BM1.release(); CroutMatrix CM2; CM2 = CM1; BandLUMatrix BM2 = BM1; Matrix X = SBM.i(); Matrix Y = CM2.i() - X; Matrix Z = BM2.i() - X; Clean(Y,0.00000001); Print(Y); Clean(Z,0.00000001); Print(Z); X *= SBM; X -= IdentityMatrix(50); Clean(X,0.00000001); Print(X); LogAndSign x = log_determinant(SBM); LogAndSign y = log_determinant(CM2); LogAndSign z = log_determinant(BM2); RowVector D(4); D(1) = y.value() - x.value(); D(2) = z.value() - x.value(); D(3) = y.sign() - x.sign(); D(4) = z.sign() - x.sign(); Clean(D,0.00000001); Print(D); } { Tracer et1("Stage 9"); // do it again odd matrix size MultWithCarry MWC; SymmetricBandMatrix SBM(51, 10); for (int i = 1; i <= 51; ++i) for (int j = 1; j <= i; ++j) if (i - j <= 10) SBM(i, j) = MWC.Next(); CroutMatrix CM = SBM; BandLUMatrix BM = SBM; CroutMatrix CM1 = CM; BandLUMatrix BM1; BM1 = BM; CM1.release(); BM1.release(); CroutMatrix CM2; CM2 = CM1; BandLUMatrix BM2 = BM1; Matrix X = SBM.i(); Matrix Y = CM2.i() - X; Matrix Z = BM2.i() - X; Clean(Y,0.00000001); Print(Y); Clean(Z,0.00000001); Print(Z); X *= SBM; X -= IdentityMatrix(51); Clean(X,0.00000001); Print(X); LogAndSign x = log_determinant(SBM); LogAndSign y = log_determinant(CM2); LogAndSign z = log_determinant(BM2); RowVector D(4); D(1) = y.value() - x.value(); D(2) = z.value() - x.value(); D(3) = y.sign() - x.sign(); D(4) = z.sign() - x.sign(); Clean(D,0.00000001); Print(D); } // cout << "\nEnd of ninth test\n"; }