60 namespace ConstrainedOptPack {
72 :print_tests_(print_tests)
74 ,throw_exception_(throw_exception)
75 ,num_random_tests_(num_random_tests)
76 ,mult_warning_tol_(mult_warning_tol)
77 ,mult_error_tol_(mult_error_tol)
78 ,solve_warning_tol_(solve_warning_tol)
79 ,solve_error_tol_(solve_error_tol)
87 ,
const MatrixOpNonsing *R
93 namespace rcp = MemMngPack;
108 bool success =
true, result, lresult, llresult;
112 small_num =
::pow(std::numeric_limits<value_type>::epsilon(),0.25),
122 *out <<
"\n**********************************************************"
123 <<
"\n*** DecompositionSystemTester::test_decomp_system(...) ***"
124 <<
"\n**********************************************************\n";
138 <<
"\nds.n() = " << n
139 <<
"\nds.m() = " << m
140 <<
"\nds.r() = " << r
141 <<
"\nds.equ_decomp() = ["<<equ_decomp.lbound()<<
","<<equ_decomp.ubound()<<
"]"
142 <<
"\nds.equ_undecomp() = ["<<equ_undecomp.lbound()<<
","<<equ_undecomp.ubound()<<
"]"
143 <<
"\nds.space_range()->dim() = " << ds.
space_range()->dim()
144 <<
"\nds.space_null()->dim() = " << ds.
space_null()->dim()
150 Z==NULL&&Y==NULL&&R==NULL&&Uz==NULL&&Uy==NULL
151 , std::invalid_argument
152 ,
"DecompositionSystemTester::test_decomp_system(...) : Error, "
153 "at least one of Z, Y, R, Uz or Uy can not be NULL!" );
155 m == r && Uz != NULL, std::invalid_argument
156 ,
"DecompositionSystemTester::test_decomp_system(...) : Error, "
157 "Uz must be NULL if m==r is NULL!" );
159 m == r && Uy != NULL, std::invalid_argument
160 ,
"DecompositionSystemTester::test_decomp_system(...) : Error, "
161 "Uy must be NULL if m==r is NULL!" );
166 *out <<
"\nGc =\n" << Gc;
168 *out <<
"\nZ =\n" << *Z;
170 *out <<
"\nY =\n" << *
Y;
172 *out <<
"\nR =\n" << *R;
174 *out <<
"\nUz =\n" << *Uz;
176 *out <<
"\nUy =\n" << *Uy;
185 *out <<
"\n1) Check the partitioning ranges and vector space dimensions ...";
189 *out <<
"\n\n1.a) check: equ_decomp.size() + equ_undecomp.size() == ds.m() : ";
190 result = equ_decomp.size() + equ_undecomp.size() == ds.
m();
192 *out << ( result ?
"passed" :
"failed" );
193 if(!result) lresult =
false;
196 *out <<
"\n\n1.b) check: equ_decomp.size() == ds.r() : ";
197 result = equ_decomp.size() == ds.
r();
199 *out << ( result ?
"passed" :
"failed" );
200 if(!result) lresult =
false;
203 *out <<
"\n\n1.c) check: ds.space_range()->dim() == ds.r() : ";
206 *out << ( result ?
"passed" :
"failed" );
207 if(!result) lresult =
false;
210 *out <<
"\n\n1.d) check: ds.space_null()->dim() == ds.n() - ds.r() : ";
213 *out << ( result ?
"passed" :
"failed" );
214 if(!result) lresult =
false;
219 if(!lresult) success =
false;
221 *out <<
" : " << ( lresult ?
"passed" :
"failed" );
229 <<
"\n2) Check the compatibility of the vector spaces for Gc, Z, Y, R, Uz and Uy ...";
235 <<
"\n2.a) Check consistency of the vector spaces for:"
236 <<
"\n Z.space_cols() == Gc.space_cols() and Z.space_rows() == ds.space_null()";
239 *out <<
"\n\n2.a.1) Z->space_cols().is_compatible(Gc.space_cols()) == true : ";
240 result = Z->space_cols().is_compatible(Gc.space_cols());
242 *out << ( result ?
"passed" :
"failed" )
244 if(!result) llresult =
false;
246 *out <<
"\n\n2.a.2) Z->space_cols().is_compatible(*ds.space_null()) == true : ";
247 result = Z->space_rows().is_compatible(*ds.
space_null());
249 *out << ( result ?
"passed" :
"failed" )
251 if(!result) llresult =
false;
252 if(!llresult) lresult =
false;
254 *out <<
" : " << ( llresult ?
"passed" :
"failed" );
260 <<
"\n2.b) Check consistency of the vector spaces for:"
261 <<
"\n Y.space_cols() == Gc.space_cols() and Y.space_rows() == ds.space_range()";
264 *out <<
"\n\n2.b.1) Y->space_cols().is_compatible(Gc.space_cols()) == true : ";
265 result = Y->space_cols().is_compatible(Gc.space_cols());
267 *out << ( result ?
"passed" :
"failed" )
269 if(!result) llresult =
false;
271 *out <<
"\n\n2.b.2) Y->space_cols().is_compatible(*ds.space_range()) == true : ";
272 result = Y->space_rows().is_compatible(*ds.
space_range());
274 *out << ( result ?
"passed" :
"failed" )
276 if(!result) llresult =
false;
277 if(!llresult) lresult =
false;
279 *out <<
" : " << ( llresult ?
"passed" :
"failed" );
285 <<
"\n2.c) Check consistency of the vector spaces for:"
286 <<
"\n R.space_cols() == Gc.space_cols()(equ_decomp) and R.space_rows() == ds.space_range()";
289 *out <<
"\n\n2.c.1) R->space_cols().is_compatible(*Gc.space_cols().sub_space(equ_decomp)) == true : ";
290 result = R->space_cols().is_compatible(*Gc.space_cols().sub_space(equ_decomp));
292 *out << ( result ?
"passed" :
"failed" )
294 if(!result) llresult =
false;
296 *out <<
"\n\n2.c.2) R->space_cols().is_compatible(*ds.space_range()) == true : ";
297 result = R->space_rows().is_compatible(*ds.
space_range());
299 *out << ( result ?
"passed" :
"failed" )
301 if(!result) llresult =
false;
302 if(!llresult) lresult =
false;
304 *out <<
" : " << ( llresult ?
"passed" :
"failed" );
310 <<
"\n2.d) Check consistency of the vector spaces for:"
311 <<
"\n Uz.space_cols() == Gc.space_cols()(equ_undecomp) and Uz.space_rows() == ds.space_null()";
314 *out <<
"\n\n2.d.1) Uz->space_cols().is_compatible(*Gc.space_cols().sub_space(equ_undecomp)) == true : ";
315 result = Uz->space_cols().is_compatible(*Gc.space_cols().sub_space(equ_undecomp));
317 *out << ( result ?
"passed" :
"failed" )
319 if(!result) llresult =
false;
321 *out <<
"\n\n2.d.2) Uz->space_cols().is_compatible(*ds.space_null()) == true : ";
322 result = Uz->space_rows().is_compatible(*ds.
space_null());
324 *out << ( result ?
"passed" :
"failed" )
326 if(!result) llresult =
false;
327 if(!llresult) lresult =
false;
329 *out <<
" : " << ( llresult ?
"passed" :
"failed" );
335 <<
"\n2.e) Check consistency of the vector spaces for:"
336 <<
"\n Uy.space_cols() == Gc.space_cols()(equ_undecomp) and Uy.space_rows() == ds.space_range()";
339 *out <<
"\n\n2.e.1) Uy->space_cols().is_compatible(*Gc.space_cols().sub_space(equ_undecomp)) == true : ";
340 result = Uy->space_cols().is_compatible(*Gc.space_cols().sub_space(equ_undecomp));
342 *out << ( result ?
"passed" :
"failed" )
344 if(!result) llresult =
false;
346 *out <<
"\n\n2.e.2) Uy->space_cols().is_compatible(*ds.space_range()) == true : ";
347 result = Uy->space_rows().is_compatible(*ds.
space_range());
349 *out << ( result ?
"passed" :
"failed" )
351 if(!result) llresult =
false;
352 if(!llresult) lresult =
false;
354 *out <<
" : " << ( llresult ?
"passed" :
"failed" );
357 if(!lresult) success =
false;
359 *out <<
" : " << ( lresult ?
"passed" :
"failed" );
363 <<
"\n3) Check the compatibility of the matrices Gc, Z, Y, R, Uz and Uy numerically ...";
370 <<
"\n3.a) Check consistency of:"
371 <<
"\n op ( alpha* Gc(:,equ_decomp)' * beta*Z ) * v"
372 <<
"\n \\__________________________________/"
374 <<
"\n == op( alpha*beta*Uz * v"
375 <<
"\n \\___________/"
377 <<
"\nfor random vectors v ...";
379 VectorSpace::vec_mut_ptr_t
380 v_c = Gc.space_rows().create_member(),
381 v_c_tmp = v_c->space().create_member(),
382 v_x = Gc.space_cols().create_member(),
383 v_x_tmp = v_x->space().create_member(),
385 v_z_tmp = v_z->space().create_member();
388 *out <<
"\n\n3.a.1) Testing non-transposed A*v == B*v ...";
392 {
for(
int k = 1; k <= num_random_tests(); ++k ) {
396 <<
"\n3.a.1."<<k<<
") random vector " << k <<
" ( ||v_z||_1 / n = " << (v_z->norm_1() / v_z->dim()) <<
" )\n";
397 if(dump_all() && print_tests >=
PRINT_ALL)
398 *out <<
"\nv_z =\n" << *v_z;
402 *v_c_tmp->sub_view(equ_decomp) = 0.0;
403 if(equ_undecomp.size()) {
405 V_StMtV( v_c_tmp->sub_view(equ_undecomp).get(), alpha*beta, *Uz,
no_trans, *v_z );
407 *v_c_tmp->sub_view(equ_undecomp).get() = *v_c->sub_view(equ_undecomp);
410 sum_Bv =
sum(*v_c_tmp),
415 calc_err = ::fabs( ( sum_Av - sum_Bv )
416 /( ::fabs(sum_Av) + ::fabs(sum_Bv) + (equ_undecomp.size() ? small_num : 1.0) ) );
419 <<
"\nrel_err(sum(A*v_z),sum(B*v_z)) = "
420 <<
"rel_err(" << sum_Av <<
"," << sum_Bv <<
") = "
421 << calc_err << std::endl;
422 if( calc_err >= mult_warning_tol() ) {
426 << ( calc_err >= mult_error_tol() ?
"Error" :
"Warning" )
427 <<
", rel_err(sum(A*v_z),sum(B*v_z)) = "
428 <<
"rel_err(" << sum_Av <<
"," << sum_Bv <<
") = "
431 << ( calc_err >= mult_error_tol() ?
"mult_error_tol" :
"mult_warning_tol" )
433 << ( calc_err >= mult_error_tol() ? mult_error_tol() : mult_warning_tol() )
435 if(calc_err >= mult_error_tol()) {
436 if(dump_all() && print_tests >=
PRINT_ALL) {
437 *out <<
"\nalpha = " << alpha << std::endl;
438 *out <<
"\nbeta = " << beta << std::endl;
439 *out <<
"\nv_z =\n" << *v_z;
440 *out <<
"\nbeta*Z*v_z =\n" << *v_x;
441 *out <<
"\nA*v_z =\n" << *v_c;
442 *out <<
"\nB*v_z =\n" << *v_c_tmp;
448 if(!llresult) lresult =
false;
450 *out <<
" : " << ( llresult ?
"passed" :
"failed" )
454 *out <<
"\n\n3.a.2) Testing transposed A'*v == B'*v ...";
458 {
for(
int k = 1; k <= num_random_tests(); ++k ) {
462 <<
"\n3.a.2."<<k<<
") random vector " << k <<
" ( ||v_c||_1 / n = " << (v_c->norm_1() / v_c->dim()) <<
" )\n";
463 if(dump_all() && print_tests >=
PRINT_ALL)
464 *out <<
"\nv_c =\n" << *v_c;
469 if(equ_undecomp.size()) {
471 V_StMtV( v_z_tmp.get(), alpha*beta, *Uz,
trans, *v_c->sub_view(equ_undecomp) );
476 sum_Bv =
sum(*v_z_tmp),
481 calc_err = ::fabs( ( sum_Av - sum_Bv )
482 /( ::fabs(sum_Av) + ::fabs(sum_Bv) + (equ_undecomp.size() ? small_num : 1.0) ) );
485 <<
"\nrel_err(sum(A'*v_c),sum(B'*v_c)) = "
486 <<
"rel_err(" << sum_Av <<
"," << sum_Bv <<
") = "
487 << calc_err << std::endl;
488 if( calc_err >= mult_warning_tol() ) {
492 << ( calc_err >= mult_error_tol() ?
"Error" :
"Warning" )
493 <<
", rel_err(sum(A'*v_c),sum(B'*v_c)) = "
494 <<
"rel_err(" << sum_Av <<
"," << sum_Bv <<
") = "
497 << ( calc_err >= mult_error_tol() ?
"mult_error_tol" :
"mult_warning_tol" )
499 << ( calc_err >= mult_error_tol() ? mult_error_tol() : mult_warning_tol() )
501 if(calc_err >= mult_error_tol()) {
502 if(dump_all() && print_tests >=
PRINT_ALL) {
503 *out <<
"\nalpha = " << alpha << std::endl;
504 *out <<
"\nbeta = " << beta << std::endl;
505 *out <<
"\nv_c =\n" << *v_c;
506 *out <<
"\nalpha*Gc*v_c =\n" << *v_x;
507 *out <<
"\nA'*v_c =\n" << *v_z;
508 *out <<
"\nB'*v_c =\n" << *v_z_tmp;
514 if(!llresult) lresult =
false;
516 *out <<
" : " << ( llresult ?
"passed" :
"failed" )
524 <<
"\n3.a) Warning! Z ==NULL; Z, and Uz are not checked numerically ...\n";
532 <<
"\n3.b) Check consistency of:"
533 <<
"\n op ( alpha*[ Gc(:,equ_decomp)' ]"
534 <<
"\n [ Gc(:,equ_undecomp)' ] * beta*Y ) * v"
535 <<
"\n \\_____________________________________/"
537 <<
"\n == op( alpha*beta*[ R ]"
539 <<
"\n \\_______________/"
541 <<
"\nfor random vectors v ...";
543 VectorSpace::vec_mut_ptr_t
544 v_c = Gc.space_rows().create_member(),
545 v_c_tmp = v_c->space().create_member(),
546 v_x = Gc.space_cols().create_member(),
547 v_x_tmp = v_x->space().create_member(),
549 v_y_tmp = v_y->space().create_member();
552 *out <<
"\n\n3.b.1) Testing non-transposed A*v == B*v ...";
556 {
for(
int k = 1; k <= num_random_tests(); ++k ) {
560 <<
"\n3.b.1."<<k<<
") random vector " << k <<
" ( ||v_y||_1 / n = " << (v_y->norm_1() / v_y->dim()) <<
" )\n";
561 if(dump_all() && print_tests >=
PRINT_ALL)
562 *out <<
"\nv_y =\n" << *v_y;
566 V_StMtV( v_c_tmp->sub_view(equ_decomp).get(), alpha*beta, *R,
no_trans, *v_y );
567 if(equ_undecomp.size()) {
569 V_StMtV( v_c_tmp->sub_view(equ_undecomp).get(), alpha*beta, *Uy,
no_trans, *v_y );
571 *v_c_tmp->sub_view(equ_undecomp) = *v_c->sub_view(equ_undecomp);
574 sum_Bv =
sum(*v_c_tmp),
579 calc_err = ::fabs( ( sum_Av - sum_Bv )
580 /( ::fabs(sum_Av) + ::fabs(sum_Bv) + small_num ) );
583 <<
"\nrel_err(sum(A*v_y),sum(B*v_y)) = "
584 <<
"rel_err(" << sum_Av <<
"," << sum_Bv <<
") = "
585 << calc_err << std::endl;
586 if( calc_err >= mult_warning_tol() ) {
590 << ( calc_err >= mult_error_tol() ?
"Error" :
"Warning" )
591 <<
", rel_err(sum(A*v_y),sum(B*v_y)) = "
592 <<
"rel_err(" << sum_Av <<
"," << sum_Bv <<
") = "
595 << ( calc_err >= mult_error_tol() ?
"mult_error_tol" :
"mult_warning_tol" )
597 << ( calc_err >= mult_error_tol() ? mult_error_tol() : mult_warning_tol() )
599 if(calc_err >= mult_error_tol()) {
600 if(dump_all() && print_tests >=
PRINT_ALL) {
601 *out <<
"\nalpha = " << alpha << std::endl;
602 *out <<
"\nbeta = " << beta << std::endl;
603 *out <<
"\nv_y =\n" << *v_y;
604 *out <<
"\nbeta*Y*v_y =\n" << *v_x;
605 *out <<
"\nA*v_y =\n" << *v_c;
606 *out <<
"\nB*v_y =\n" << *v_c_tmp;
612 if(!llresult) lresult =
false;
614 *out <<
" : " << ( llresult ?
"passed" :
"failed" )
618 *out <<
"\n\n3.b.2) Testing transposed A'*v == B'*v ...";
622 {
for(
int k = 1; k <= num_random_tests(); ++k ) {
626 <<
"\n3.a.2."<<k<<
") random vector " << k <<
" ( ||v_c||_1 / n = " << (v_c->norm_1() / v_c->dim()) <<
" )\n";
627 if(dump_all() && print_tests >=
PRINT_ALL)
628 *out <<
"\nv_c =\n" << *v_c;
632 V_StMtV( v_y_tmp.get(), alpha*beta, *R,
trans, *v_c->sub_view(equ_decomp) );
633 if(equ_undecomp.size()) {
635 Vp_StMtV( v_y_tmp.get(), alpha*beta, *Uy,
trans, *v_c->sub_view(equ_undecomp) );
637 Vp_V( v_y_tmp.get(), *v_y );
640 sum_Bv =
sum(*v_y_tmp),
645 calc_err = ::fabs( ( sum_Av - sum_Bv )
646 /( ::fabs(sum_Av) + ::fabs(sum_Bv) + small_num ) );
649 <<
"\nrel_err(sum(A'*v_c),sum(B'*v_c)) = "
650 <<
"rel_err(" << sum_Av <<
"," << sum_Bv <<
") = "
651 << calc_err << std::endl;
652 if( calc_err >= mult_warning_tol() ) {
656 << ( calc_err >= mult_error_tol() ?
"Error" :
"Warning" )
657 <<
", rel_err(sum(A'*v_c),sum(B'*v_c)) = "
658 <<
"rel_err(" << sum_Av <<
"," << sum_Bv <<
") = "
661 << ( calc_err >= mult_error_tol() ?
"mult_error_tol" :
"mult_warning_tol" )
663 << ( calc_err >= mult_error_tol() ? mult_error_tol() : mult_warning_tol() )
665 if(calc_err >= mult_error_tol()) {
666 if(dump_all() && print_tests >=
PRINT_ALL) {
667 *out <<
"\nalpha = " << alpha << std::endl;
668 *out <<
"\nbeta = " << beta << std::endl;
669 *out <<
"\nv_c =\n" << *v_c;
670 *out <<
"\nalpha*Gc*v_c =\n" << *v_x;
671 *out <<
"\nA'*v_c =\n" << *v_y;
672 *out <<
"\nB'*v_c =\n" << *v_y_tmp;
678 if(!llresult) lresult =
false;
680 *out <<
" : " << ( llresult ?
"passed" :
"failed" )
688 <<
"\n3.b) Warning! Y ==NULL; Y, R and Uy are not checked numerically ...\n";
695 <<
"\n3.b) Check consistency of: op(op(inv(R))*op(R)) == I ...\n";
696 typedef MatrixOpNonsingTester MWONST_t;
697 MWONST_t::EPrintTestLevel
699 switch(print_tests) {
702 olevel = MWONST_t::PRINT_NONE;
705 olevel = MWONST_t::PRINT_MORE;
708 olevel = MWONST_t::PRINT_ALL;
715 MWONST_t::TEST_LEVEL_2_BLAS
723 lresult = R_tester.test_matrix(*R,
"R",out);
726 if(!lresult) success =
false;
728 *out <<
" : " << ( lresult ?
"passed" :
"failed" );
732 *out <<
"\nCongradulations! The DecompositionSystem object and its associated matrix objects seem to check out!\n";
734 *out <<
"\nOops! At least one of the tests did not check out!\n";
736 *out <<
"\nEnd DecompositionSystemTester::test_decomp_system(...)\n";
f_dbl_prec const f_int f_dbl_prec * Y
AbstractLinAlgPack::size_type size_type
virtual Range1D equ_undecomp() const
Returns the range of the undecomposed equalities.
void pow(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
vs_lhs = pow(vs_rhs1,vs_rhs2)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void Vp_StV(VectorMutable *v_lhs, const value_type &alpha, const Vector &v_rhs)
v_lhs = alpha * v_rhs + v_lhs
bool test_decomp_system(const DecompositionSystem &decomp_sys, const MatrixOp &Gc, const MatrixOp *Z, const MatrixOp *Y, const MatrixOpNonsing *R, const MatrixOp *Uz, const MatrixOp *Uy, std::ostream *out)
Test a DecompositionSystem object after DecompositionSystem::update_basis() is called.
virtual size_type r() const
Returns the rank of Gc(:,equ_decomp()).
void V_StV(VectorMutable *v_lhs, value_type alpha, const V &V_rhs)
v_lhs = alpha * V_rhs.
DecompositionSystemTester(EPrintTestLevel print_tests=PRINT_NOT_SELECTED, bool dump_all=false, bool throw_exception=true, size_type num_random_tests=1, value_type mult_warning_tol=1e-14, value_type mult_error_tol=1e-8, value_type solve_warning_tol=1e-14, value_type solve_error_tol=1e-8)
Constructor (default options)
void V_StMtV(VectorMutable *v_lhs, value_type alpha, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const V &V_rhs2)
v_lhs = alpha * op(M_rhs1) * V_rhs2.
Print everything all the tests in great detail but output is independent of problem size...
virtual const VectorSpace::space_ptr_t space_range() const =0
Return a VectorSpace object for the range space.
virtual Range1D equ_decomp() const
Returns the range of the decomposed equalities.
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)
This class abstracts a decomposition choice for the quasi-range space Y and null space Z matrices for...
void Vp_StMtV(VectorMutable *v_lhs, value_type alpha, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta=1.0)
v_lhs = alpha * op(M_rhs1) * v_rhs2 + beta * v_lhs (BLAS xGEMV)
bool assert_print_nan_inf(const value_type &val, const char name[], bool throw_excpt, std::ostream *out)
This function asserts if a value_type scalare is a NaN or Inf and optionally prints out these entires...
value_type dot(const Vector &v_rhs1, const Vector &v_rhs2)
result = v_rhs1' * v_rhs2
virtual size_type n() const
Return the number of rows in Gc.
Print only very basic info.
void V_MtV(VectorMutable *v_lhs, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const V &V_rhs2)
v_lhs = op(M_rhs1) * V_rhs2.
AbstractLinAlgPack::value_type value_type
virtual const VectorSpace::space_ptr_t space_null() const =0
Return a VectorSpace object for the range space.
value_type sum(const Vector &v_rhs)
result = sum( v_rhs(i), i = 1,,,dim )
The print option has not been selected (will default to PRINT_NONE if not set)
virtual size_type m() const =0
Return the number of columns in Gc.
RangePack::Range1D Range1D
Print greater detail about the tests.
void random_vector(value_type l, value_type u, VectorMutable *v)
Generate a random vector with elements uniformly distrubuted elements.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
void Vp_V(VectorMutable *v_lhs, const V &V_rhs)
v_lhs += V_rhs.