22 #include <tests/myratest.h> 31 void test_swaps(
int I)
34 std::vector<int> perm = ilinspace(I);
35 std::random_shuffle(perm.begin(),perm.end());
37 std::vector<int> swaps = perm2swaps(perm);
48 swap_rows(swaps,X_copy);
49 double error = frobenius(PX-X_copy);
50 myra::out() <<
" |P*X-swap_rows(X)| = " << error << std::endl;
51 REQUIRE(error < 1.0e-9);
58 iswap_rows(swaps,X_copy);
59 double error = frobenius(PtX-X_copy);
60 myra::out() <<
" |P'*X-iswap_rows(X)| = " << error << std::endl;
61 REQUIRE(error < 1.0e-9);
67 swap_rows(swaps,X_copy);
68 iswap_rows(swaps,X_copy);
69 double error = frobenius(X_copy-X);
70 myra::out() <<
" |iswap_rows(swap_rows(X))-X| = " << error << std::endl;
71 REQUIRE(error < 1.0e-9);
78 swap_columns(swaps,X_copy);
79 double error = frobenius(XP-X_copy);
80 myra::out() <<
" |X*P-swap_columns(X)| = " << error << std::endl;
81 REQUIRE(error < 1.0e-9);
88 iswap_columns(swaps,X_copy);
89 double error = frobenius(XPt-X_copy);
90 myra::out() <<
" |X*P'-iswap_columns(X)| = " << error << std::endl;
91 REQUIRE(error < 1.0e-9);
97 swap_columns(swaps,X_copy);
98 iswap_columns(swaps,X_copy);
99 double error = frobenius(X_copy-X);
100 myra::out() <<
" |iswap_rows(swap_rows(X))-X| = " << error << std::endl;
101 REQUIRE(error < 1.0e-9);
106 std::vector<int> iperm = inverse_perm(perm);
107 std::vector<int> iswaps = perm2swaps(iperm);
110 myra::out() <<
" |I - P'inverse(P))| = " << error << std::endl;
111 REQUIRE(error < 1.0e-9);
118 ADD_TEST(
"swaps",
"[dense]")
120 myra::out() <<
"Testing swaps.." << std::endl;
122 myra::out() << std::endl;
Tabulates an IxJ matrix. Allows random access, has column major layout to be compatible with BLAS/LAP...
Definition: bdsqr.h:20
Routines for computing Frobenius norms of various algebraic containers.
static Matrix< Number > random(int I, int J)
Generates a random Matrix of specified size.
Definition: Matrix.cpp:353
Routines related to swap sequences, often used during pivoting.
Returns a vector of int's, over [min,max)
General purpose dense matrix container, O(i*j) storage.
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.
Interface class for representing subranges of contiguous int's.
Testing swaps..
|P*X-swap_rows(X)| = 0
|P'*X-iswap_rows(X)| = 0
|iswap_rows(swap_rows(X))-X| = 0
|X*P-swap_columns(X)| = 0
|X*P'-iswap_columns(X)| = 0
|iswap_rows(swap_rows(X))-X| = 0
|I - P'inverse(P))| = 0