47 #include "AbstractLinAlgPack_MatrixOpNonsingTester.hpp"
48 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp"
49 #include "AbstractLinAlgPack_VectorSpace.hpp"
50 #include "AbstractLinAlgPack_VectorMutable.hpp"
51 #include "AbstractLinAlgPack_VectorStdOps.hpp"
52 #include "AbstractLinAlgPack_VectorOut.hpp"
53 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp"
54 #include "AbstractLinAlgPack_MatrixOpOut.hpp"
55 #include "AbstractLinAlgPack_MatrixComposite.hpp"
56 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp"
57 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
59 namespace AbstractLinAlgPack {
66 ,size_type num_random_tests
67 ,value_type warning_tol
70 :test_level_(test_level)
71 ,print_tests_(print_tests)
73 ,throw_exception_(throw_exception)
74 ,num_random_tests_(num_random_tests)
75 ,warning_tol_(warning_tol)
76 ,error_tol_(error_tol)
85 namespace rcp = MemMngPack;
89 using BLAS_Cpp::right;
93 using AbstractLinAlgPack::assert_print_nan_inf;
95 using LinAlgOpPack::V_StMtV;
96 using LinAlgOpPack::V_MtV;
103 bool success =
true, result, lresult;
107 small_num = ::pow(std::numeric_limits<value_type>::epsilon(),0.25),
116 <<
"\nCheck: alpha*op(op(inv("<<M_name<<
"))*op("<<M_name<<
"))*v == alpha*v ...";
127 const BLAS_Cpp::Side a_side[2] = { BLAS_Cpp::left, BLAS_Cpp::right };
131 for(
int side_i = 0; side_i < 2; ++side_i ) {
132 for(
int trans_i = 0; trans_i < 2; ++trans_i ) {
137 <<
"\n" << side_i+1 <<
"." << trans_i+1 <<
") "
138 <<
"Check: (t2 = "<<(t_side==left?
"inv(":
"alpha * ")<< M_name<<(t_trans==
trans?
"\'":
"")<<(t_side==left?
")":
"")
139 <<
" * (t1 = "<<(t_side==right?
"inv(":
"alpha * ")<<M_name<<(t_trans==
trans?
"\'":
"")<<(t_side==right?
")":
"")
140 <<
" * v)) == alpha * v ...";
148 if( (t_side == left && t_trans ==
no_trans) || (t_side == right && t_trans ==
trans) ) {
160 for(
int k = 1; k <= num_random_tests(); ++k ) {
165 <<
"\n"<<side_i+1<<
"."<<trans_i+1<<
"."<<k<<
") random vector " << k
166 <<
" ( ||v||_1 / n = " << (v->
norm_1() / v->
dim()) <<
" )\n";
167 if(dump_all() && print_tests() >=
PRINT_ALL)
168 *out <<
"\nv =\n" << *v;
171 if( t_side == right ) {
177 V_StMtV( t1, alpha, M, t_trans, *v );
180 if( t_side == left ) {
186 V_StMtV( t2, alpha, M, t_trans, *t1 );
190 sum_av = alpha*
sum(*v);
191 assert_print_nan_inf(sum_t2,
"sum(t2)",
true,out);
192 assert_print_nan_inf(sum_av,
"sum(alpha*t1)",
true,out);
194 calc_err = ::fabs( ( sum_av - sum_t2 )
195 /( ::fabs(sum_av) + ::fabs(sum_t2) + small_num ) );
198 <<
"\nrel_err(sum(alpha*v),sum(t2)) = "
199 <<
"rel_err(" << sum_av <<
"," << sum_t2 <<
") = "
200 << calc_err << std::endl;
201 if( calc_err >= warning_tol() ) {
205 << ( calc_err >= error_tol() ?
"Error" :
"Warning" )
206 <<
", rel_err(sum(alpha*v),sum(t2)) = "
207 <<
"rel_err(" << sum_av <<
"," << sum_t2 <<
") = "
210 << ( calc_err >= error_tol() ?
"error_tol" :
"warning_tol" )
212 << ( calc_err >= error_tol() ? error_tol() : warning_tol() )
214 if(calc_err >= error_tol()) {
215 if(dump_all() && print_tests() >=
PRINT_ALL) {
216 *out <<
"\nalpha = " << alpha << std::endl;
217 *out <<
"\nv =\n" << *v;
218 *out <<
"\nt1 =\n" << *t2;
219 *out <<
"\nt2 =\n" << *t2;
224 if(!lresult) result =
false;
226 if(!result) success =
false;
228 *out <<
" : " << ( result ?
"passed" :
"failed" )
234 *out <<
" : " << ( success ?
"passed" :
"failed" );
virtual const VectorSpace & space_rows() const =0
Vector space for vectors that are compatible with the rows of the matrix.
virtual value_type norm_1() const
One norm. ||v||_1 = sum( |v(i)|, i = 1,,,this->dim() )
bool test_matrix(const MatrixOpNonsing &M, const char M_name[], std::ostream *out)
Test a MatrixOpNonsing object.
void Vp_StV(VectorMutable *v_lhs, const value_type &alpha, const Vector &v_rhs)
v_lhs = alpha * v_rhs + v_lhs
void V_StV(VectorMutable *v_lhs, value_type alpha, const V &V_rhs)
v_lhs = alpha * V_rhs.
Print greater detail about the tests.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void V_VpV(VectorMutable *v_lhs, const V1 &V1_rhs1, const V2 &V2_rhs2)
Print only very basic info.
void V_InvMtV(VectorMutable *v_lhs, const MatrixNonsing &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2)
v_lhs = inv(op(M_rhs1)) * v_rhs2
MatrixOpNonsingTester(ETestLevel test_level=TEST_LEVEL_2_BLAS, EPrintTestLevel print_tests=PRINT_NONE, bool dump_all=false, bool throw_exception=true, size_type num_random_tests=1, value_type warning_tol=1e-14, value_type error_tol=1e-8)
Constructor (default options)
value_type dot(const Vector &v_rhs1, const Vector &v_rhs2)
result = v_rhs1' * v_rhs2
virtual index_type dim() const
Return the dimension of this vector.
virtual const VectorSpace & space_cols() const =0
Vector space for vectors that are compatible with the columns of the matrix.
Abstract interface for mutable coordinate vectors {abstract}.
value_type sum(const Vector &v_rhs)
result = sum( v_rhs(i), i = 1,,,dim )
Abstract base class for all nonsingular polymorphic matrices that can be used to compute matrix-vecto...
Print everything all the tests in great detail but output is independent of problem size...
virtual vec_mut_ptr_t create_member() const =0
Create a vector member from the vector space.
void random_vector(value_type l, value_type u, VectorMutable *v)
Generate a random vector with elements uniformly distrubuted elements.
void Vp_V(VectorMutable *v_lhs, const V &V_rhs)
v_lhs += V_rhs.