00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <ostream>
00030 #include <iomanip>
00031
00032 #include <math.h>
00033
00034 #include "AbstractLinAlgPack_TestMatrixSymSecant.hpp"
00035 #include "AbstractLinAlgPack_MatrixOp.hpp"
00036 #include "AbstractLinAlgPack_MatrixNonsing.hpp"
00037 #include "AbstractLinAlgPack_VectorSpace.hpp"
00038 #include "AbstractLinAlgPack_VectorMutable.hpp"
00039 #include "AbstractLinAlgPack_VectorOut.hpp"
00040 #include "AbstractLinAlgPack_VectorStdOps.hpp"
00041 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
00042 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp"
00043
00044 bool AbstractLinAlgPack::TestMatrixSymSecant(
00045 const MatrixOp &B
00046 ,const Vector &s
00047 ,const Vector &y
00048 ,value_type warning_tol
00049 ,value_type error_tol
00050 ,bool print_all_warnings
00051 ,std::ostream *out
00052 ,bool trase
00053 )
00054 {
00055 using std::setw;
00056 using std::endl;
00057 using AbstractLinAlgPack::sum;
00058 using AbstractLinAlgPack::V_InvMtV;
00059 using AbstractLinAlgPack::assert_print_nan_inf;
00060 using LinAlgOpPack::V_MtV;
00061
00062 bool success = true;
00063 const char
00064 sep_line[] = "\n-----------------------------------------------------------------\n";
00065
00066
00067 {
00068 if( out && trase )
00069 *out
00070 << sep_line
00071 << "\n|(sum(B*s)-sum(y))/||y||inf| = ";
00072 VectorSpace::vec_mut_ptr_t
00073 Bs = y.space().create_member();
00074 V_MtV( Bs.get(), B, BLAS_Cpp::no_trans, s );
00075 const value_type
00076 sum_Bs = sum(*Bs),
00077 sum_y = sum(y),
00078 nrm_y = y.norm_inf(),
00079 err = ::fabs( (sum_Bs - sum_y) / nrm_y );
00080 if( out && trase )
00081 *out
00082 <<"|("<<sum_Bs<<"-"<<sum_y<<")/"<<nrm_y<<"| = " << err << std::endl;
00083 if( err >= error_tol ) {
00084 if( out && trase )
00085 *out
00086 << "Error, above error = " << err << " >= error_tol = " << error_tol
00087 << "\nThe test has failed!\n";
00088 if(out && print_all_warnings) {
00089 *out
00090 << "\ns =\n" << s
00091 << "\ny =\n" << y
00092 << "\nBs =\n" << *Bs
00093 << endl;
00094 }
00095 success = false;
00096 }
00097 else if( err >= warning_tol ) {
00098 if( out && trase )
00099 *out
00100 << "Warning!, above error = " << err << " >= warning_tol = " << warning_tol << std::endl;
00101 }
00102 }
00103
00104 const MatrixNonsing
00105 *B_nonsing = dynamic_cast<const MatrixNonsing*>(&B);
00106 if( B_nonsing ) {
00107 if( out && trase )
00108 *out
00109 << sep_line
00110 << "\n|(sum(inv(B)*y)-sum(s))/||s||inf| = ";
00111 VectorSpace::vec_mut_ptr_t
00112 InvBy = s.space().create_member();
00113 V_InvMtV( InvBy.get(), *B_nonsing, BLAS_Cpp::no_trans, y );
00114 const value_type
00115 sum_InvBy = sum(*InvBy),
00116 sum_s = sum(s),
00117 nrm_s = s.norm_inf(),
00118 err = ::fabs( (sum_InvBy - sum_s) / nrm_s );
00119 if( out && trase )
00120 *out
00121 <<"|("<<sum_InvBy<<"-"<<sum_s<<")/"<<nrm_s<<"| = " << err << std::endl;
00122 if( err >= error_tol ) {
00123 if( out && trase )
00124 *out
00125 << "Error, above error = " << err << " >= error_tol = " << error_tol
00126 << "\nThe test has failed!\n";
00127 if(out && print_all_warnings) {
00128 *out
00129 << "\ns =\n" << s
00130 << "\ny =\n" << y
00131 << "\ninv(B)*y =\n" << *InvBy
00132 << endl;
00133 }
00134 success = false;
00135 }
00136 else if( err >= warning_tol ) {
00137 if( out && trase )
00138 *out
00139 << "Warning!, above error = " << err << " >= warning_tol = " << warning_tol << std::endl;
00140 }
00141 }
00142 if( out && trase )
00143 *out << sep_line;
00144 return success;
00145 }