43 #include <tests/myratest.h> 54 throw eprintf(
"make_minres_A(N), must have N even [%d]",N);
61 for (
int k = 0; k < K; ++k)
63 A_builder(k,k) = -D(k);
64 A_builder(N-k-1,N-k-1) = D(k);
66 for (
int n = 0; n < N-1; ++n)
68 A_builder(n,n+1) = -one;
69 A_builder(n+1,n) = -one;
71 return A_builder.make_SparseMatrix();
75 template<
class Precision>
void test1(
int N, Precision tol)
77 using myra_stlprint::operator<<;
79 myra::out() << typestring<Precision>() << std::endl;
80 auto A = make_minres_A<Precision>(N);
84 for (
int n = 0; n < N; ++n)
85 M(n) = std::abs(one/M(n));
90 auto M_action = make_DimmAction(M);
91 auto A_action = make_GemmAction(A);
92 auto output1 = minres(M_action,A_action,b,x,tol);
94 Precision error1 = euclidean( M_action*(A_action*x-b) ) / euclidean(b);
95 myra::out() <<
"history = " << output1.history << std::endl;
96 myra::out() <<
"|M*(A*x-b)|/|b| = " << error1 << std::endl;
97 REQUIRE( error1 < tol );
101 auto output2 = minres(M_action,A_action,B,X,tol);
103 Precision error2 = frobenius( M_action*(A_action*X-B) ) / frobenius(B);
104 myra::out() <<
"history = " << output2.history << std::endl;
105 myra::out() <<
"|M*(A*X-B)|/|B| = " << error2 << std::endl;
106 REQUIRE( error2 < tol );
110 template<
class Precision>
void test2(
int N, Precision tol)
114 myra::out() << typestring<Number>() << std::endl;
115 auto A = make_minres_A<Number>(N);
120 for (
int n = 0; n < N; ++n)
121 M(n) = std::abs(one/M(n));
126 auto M_action = make_DimmAction(M);
127 auto A_action = make_GemmAction(A);
128 auto output1 = minres(M_action,A_action,b,x,tol);
130 Precision error1 = euclidean( M_action*(A_action*x-b) ) / euclidean(b);
131 using myra_stlprint::operator<<;
132 myra::out() <<
"history = " << output1.history << std::endl;
133 myra::out() <<
"|M*(A*x-b)|/|b| = " << error1 << std::endl;
134 REQUIRE( error1 < tol );
138 auto output2 = minres(M_action,A_action,B,X,tol);
140 Precision error2 = frobenius( M_action*(A_action*X-B) ) / frobenius(B);
141 myra::out() <<
"history = " << output2.history << std::endl;
142 myra::out() <<
"|M*(A*X-B)|/|B| = " << error2 << std::endl;
143 REQUIRE( error2 < tol );
148 ADD_TEST(
"minres_real",
"[iterative]")
150 test1<float>(100,1.0e-3f);
151 test1<double>(100,1.0e-6);
154 ADD_TEST(
"minres_complex",
"[iterative]")
156 test2<float>(100,1.0e-3f);
157 test2<double>(100,1.0e-6);
Routines for computing euclidean norm of a Vector/VectorRange, or normalizing a Vector/VectorRange to...
Interface class for representing subranges of DiagonalMatrix's.
Returns a std::runtime_error() whose message has been populated using printf()-style formatting...
Interface class for representing subranges of dense Matrix's.
Generators for basic Expression's (constant, random, linspace, etc).
static Vector< Number > ones(int N)
Generates a ones Vector of specified size.
Definition: Vector.cpp:284
Interface class for representing subranges of dense Vector's.
Applies the "Action" of a linear operator, b := A*x, used in iterative solution algorithms.
static Matrix< Number > zeros(int I, int J)
Generates a zeros Matrix of specified size.
Definition: Matrix.cpp:357
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 for multiplying by a DiagonalMatrix.
An interface used to fill containers from Expression's (see Matrix::evaluate(), for example)...
General purpose compressed-sparse-column (CSC) container.
Variety of routines all for dense Matrix*Vector multiplies. All just delegate to gemm() ...
Reflects a Precision type into a complex type.
Definition: Number.h:46
Routines for printing the contents of various std::container's to a std::ostream using operator <<...
Various utility functions/classes related to scalar Number types.
static Vector< Number > zeros(int N)
Generates a zeros Vector of specified size.
Definition: Vector.cpp:280
General purpose dense matrix container, O(i*j) storage.
Container for either a column vector or row vector (depends upon the usage context) ...
Convenience type for building SparseMatrix's, uses coordinate/triplet format.
Definition: SparseMatrix.h:32
An Action for multiplying by a dense Matrix or SparseMatrix using gemm().
Convenience type for building SparseMatrix's, uses coordinate/triplet format. Note that SparseMatrixB...
Returns the diagonal of a SparseMatrix.
An Action for multiplying by a DiagonalMatrix using dimm()
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.
Stores an IxJ matrix A in compressed sparse column format.
Definition: bothcat.h:23
static DiagonalMatrix< Number > evaluate(const Expression< 1, Number > &e)
Generates a DiagonalMatrix by evaluating an arity-1 Expression of Number.
Definition: DiagonalMatrix.cpp:258
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.
Applies random phase shifts to a complex square SparseMatrix.
Linear system solution via minimum residual method (symmetric action A, can be indefinite) ...
Range/Iterator types associated with SparseMatrix.
std::complex<float>
history = [ 0.370527 0.089801 0.0881976 0.0274258 0.0268242 0.0100926 0.00990909 0.00374722 0.00369557 0.0014238 0.00140456 0.000520099 ] (12)
|M*(A*x-b)|/|b| = 0.00037029
history = [ 0.355903 0.0608088 0.0605837 0.0202432 0.0201083 0.00733785 0.0072879 0.00280633 0.00279597 0.00104344 0.00103963 0.000370742 ] (12)
|M*(A*X-B)|/|B| = 0.000378027
std::complex<double>
history = [ 0.371143 0.090826 0.0897114 0.0311435 0.0303255 0.0118155 0.011417 0.00443448 0.00438151 0.00159859 0.00157597 0.000520615 0.000513226 0.000175812 0.000173959 5.63975e-05 5.54209e-05 1.78631e-05 1.76299e-05 6.36678e-06 6.31986e-06 2.16545e-06 2.11853e-06 6.80687e-07 ] (24)
|M*(A*x-b)|/|b| = 5.20129e-07
history = [ 0.353645 0.0633671 0.0631533 0.0210318 0.0209579 0.00767153 0.00764574 0.00290698 0.00289398 0.00109641 0.00109227 0.000392763 0.000390975 0.000137503 0.000137032 4.70734e-05 4.69283e-05 1.64386e-05 1.63875e-05 5.47276e-06 5.45639e-06 1.7953e-06 1.78959e-06 5.85076e-07 ] (24)
|M*(A*X-B)|/|B| = 6.0409e-07