|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include <math.h> 00043 00044 #include <ostream> 00045 00046 #include "AbstractLinAlgPack_VectorSpaceTester.hpp" 00047 #include "AbstractLinAlgPack_VectorSpace.hpp" 00048 #include "AbstractLinAlgPack_VectorMutable.hpp" 00049 #include "AbstractLinAlgPack_VectorStdOps.hpp" 00050 #include "AbstractLinAlgPack_VectorOut.hpp" 00051 #include "TestingHelperPack_update_success.hpp" 00052 #include "Teuchos_Assert.hpp" 00053 00054 00055 //#define ALAP_VECTOR_SPACE_TESTER_DUMP 00056 00057 #ifdef ALAP_VECTOR_SPACE_TESTER_DUMP 00058 # include "RTOpPack_SPMD_apply_op.hpp" 00059 #endif // ALAP_VECTOR_SPACE_TESTER_DUMP 00060 00061 00062 namespace { 00063 template< class T > 00064 inline 00065 T my_max( const T& v1, const T& v2 ) { return v1 > v2 ? v1 : v2; } 00066 template< class T > 00067 inline 00068 T my_min( const T& v1, const T& v2 ) { return v1 < v2 ? v1 : v2; } 00069 } // end namespace 00070 00071 00072 namespace AbstractLinAlgPack { 00073 00074 00075 VectorSpaceTester::VectorSpaceTester( 00076 bool print_all_tests 00077 ,bool print_vectors 00078 ,bool throw_exception 00079 ,size_type num_random_tests 00080 ,value_type warning_tol 00081 ,value_type error_tol 00082 ) 00083 :print_all_tests_(print_all_tests) 00084 ,print_vectors_(print_vectors) 00085 ,throw_exception_(throw_exception) 00086 ,num_random_tests_(num_random_tests) 00087 ,warning_tol_(warning_tol) 00088 ,error_tol_(error_tol) 00089 {} 00090 00091 bool VectorSpaceTester::check_vector_space( 00092 const VectorSpace &space, 00093 std::ostream *out 00094 ) const 00095 { 00096 00097 using Teuchos::as; 00098 00099 bool success = true, result = false; 00100 00101 try { 00102 00103 // Adapted from test_my_vector_library(...) 00104 00105 const value_type 00106 rand_l = -10.0, 00107 rand_u = +10.0; 00108 00109 typedef VectorMutable::vec_ptr_t vec_ptr_t; 00110 typedef VectorMutable::vec_mut_ptr_t vec_mut_ptr_t; 00111 00112 // Create three random non-mutable vectors 00113 vec_ptr_t v_array[3]; 00114 const Vector* v[3]; 00115 {for(int k = 0; k < 3; ++k) { 00116 vec_mut_ptr_t r = space.create_member(); 00117 random_vector( rand_l, rand_u, r.get() ); 00118 v_array[k] = r; 00119 v[k] = v_array[k].get(); 00120 }} 00121 00122 // Create six random mutable vectors 00123 vec_mut_ptr_t z_array[6]; 00124 VectorMutable* z[6]; 00125 {for(int k = 0; k < 6; ++k) { 00126 random_vector( rand_l, rand_u, (z_array[k]= space.create_member()).get() ); 00127 z[k] = z_array[k].get(); 00128 }} 00129 00130 if(out && print_all_tests()) 00131 *out << std::boolalpha 00132 << "\n**************************************************" 00133 << "\n*** VectorSpaceTester::check_vector_space(...) ***" 00134 << "\n**************************************************\n"; 00135 00136 index_type 00137 n = space.dim(); 00138 RTOp_value_type 00139 err = 0.0, 00140 max_err = 0.0, 00141 sum_err = 0.0; 00142 char z_name[20], v_name[20]; 00143 00144 // Print the vector space dimension 00145 if(out && print_all_tests()) 00146 *out << "\nspace->dim() = " << n << std::endl; 00147 00148 // Print the initial vectors 00149 if(out && print_vectors()) { 00150 *out << "\n*** Printing the immutable vectors\n"; 00151 {for(int j = 0; j < 3; ++j) { 00152 sprintf( v_name, "v[%d]", j ); 00153 *out << std::endl << v_name << " : " << typeName(*v[j]) << std::endl 00154 << *v[j]; 00155 }} 00156 *out << "\n*** Printing the mutable vectors\n"; 00157 {for(int k = 0; k < 6; ++k) { 00158 sprintf( z_name, "z[%d]", k ); 00159 *out << std::endl << z_name << " : " << typeName(*z[k]) << std::endl 00160 << *z[k]; 00161 }} 00162 } 00163 00165 if(out && print_all_tests()) 00166 *out << "\n*** Testing the obvious assertions\n"; 00167 { 00168 {for(int k = 0; k < 6; ++k) { 00169 const Vector *vec = NULL; 00170 if( k < 3 ) { 00171 sprintf( v_name, "v[%d]", k ); 00172 vec = v[k]; 00173 } 00174 else { 00175 sprintf( v_name, "z[%d]", k-3 ); 00176 vec = z[k-3]; 00177 } 00178 00179 result = vec->space().is_compatible(space); 00180 if(out && (print_all_tests() || !result)) 00181 *out << "\ncheck: " << v_name << "->space().is_compatible(space) : " << result << std::endl; 00182 check_test( result ? 0.0 : -10.0 , out, &success ); 00183 00184 result = space.is_compatible(vec->space()); 00185 if(out && (print_all_tests() || !result)) 00186 *out << "check: space.is_compatible(" << v_name << "->space()) : " << result << std::endl; 00187 check_test( result ? 0.0 : -10.0 , out, &success ); 00188 00189 err = vec->dim() - space.dim(); 00190 if(out && (print_all_tests() || !result)) 00191 *out << "check: " << v_name << "->dim() - space.dim() = " << vec->dim() << " - " 00192 << space.dim() << " = " << err << std::endl; 00193 check_test( err , out, &success ); 00194 00195 result = vec->nz() <= space.dim(); 00196 if(out && (print_all_tests() || !result)) 00197 *out << "check: " << v_name << "->nz() <= space.dim() = " << vec->nz() << " <= " << space.dim() 00198 << " : " << result << std::endl; 00199 check_test( result ? 0.0 : -10.0 , out, &success ); 00200 00201 }} 00202 } 00203 00205 if(out && print_all_tests()) 00206 *out << "\n*** Testing scalar assignment and element access methods\n"; 00207 { 00208 const index_type k = 0; 00209 sprintf( z_name, "z[%d]", (int)k ); 00210 if(out && print_all_tests()) 00211 *out << "\n0.0 -> " << z_name << std::endl; 00212 *z[k] = 0.0; 00213 if(out && print_vectors()) 00214 *out << std::endl << z_name << " =\n" << *z[k]; 00215 {for(index_type r = 0; r < num_random_tests(); ++r) { 00216 std::srand( n / (1+r) + r ); // This is very important in a parallel program! 00217 const index_type 00218 i = my_min( 00219 n, 00220 my_max( 00221 as<index_type>(((double)std::rand() / RAND_MAX) * n + 1.0), 00222 as<index_type>(1) 00223 ) 00224 ); 00225 const RTOp_value_type 00226 val = 10.0; 00227 00228 if(out && print_all_tests()) 00229 *out << std::endl << z_name << ".set_ele("<<i<<","<<val<<")\n"; 00230 #ifdef ALAP_VECTOR_SPACE_TESTER_DUMP 00231 RTOpPack::show_spmd_apply_op_dump = true; 00232 #endif 00233 z[k]->set_ele(i,val); 00234 #ifdef ALAP_VECTOR_SPACE_TESTER_DUMP 00235 RTOpPack::show_spmd_apply_op_dump = false; 00236 #endif 00237 if(out && print_vectors()) 00238 *out << std::endl << z_name << " =\n" << *z[k]; 00239 #ifdef ALAP_VECTOR_SPACE_TESTER_DUMP 00240 RTOpPack::show_spmd_apply_op_dump = true; 00241 #endif 00242 RTOp_value_type 00243 val_get = z[k]->get_ele(i); 00244 #ifdef ALAP_VECTOR_SPACE_TESTER_DUMP 00245 RTOpPack::show_spmd_apply_op_dump = false; 00246 #endif 00247 err = val - val_get; 00248 if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) ) 00249 *out << "check: " << val << " - " << z_name << ".get_ele(" << i << ") = " 00250 << val << " - " << val_get << " = " << err << std::endl; 00251 check_test(err,out,&success); 00252 00253 RTOp_value_type 00254 z_k_sum = sum(*z[k]); 00255 err = val - z_k_sum; 00256 if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) ) 00257 *out << "check: " << val << " - sum(" << z_name << ") = " 00258 << val << " - " << z_k_sum << " = " << err << std::endl; 00259 check_test(err,out,&success); 00260 00261 if(out && print_all_tests()) 00262 *out << z_name << ".set_ele("<<i<<",0.0)\n"; 00263 z[k]->set_ele(i,0.0); 00264 if(out && print_vectors()) 00265 *out << std::endl << z_name << " =\n" << *z[k]; 00266 z_k_sum = sum(*z[k]); 00267 err = z_k_sum; 00268 if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) ) 00269 *out << "check: sum(" << z_name << ") = " << z_k_sum << std::endl; 00270 check_test(err,out,&success); 00271 }} 00272 } 00273 00275 if(out && print_all_tests()) 00276 *out << "\n*** Testing vector assignment\n"; 00277 { 00278 {for( int k = 0; k < 3; ++k ) { 00279 sprintf( z_name, "z[%d]", k ); 00280 sprintf( v_name, "v[%d]", k ); 00281 if(out && print_all_tests()) 00282 *out << "\n" << v_name << " -> " << z_name << "\n"; 00283 *z[k] = *v[k]; 00284 const RTOp_value_type 00285 sum_z_k = sum(*z[k]), 00286 sum_v_k = sum(*v[k]); 00287 err = (sum_z_k - sum_v_k)/n; 00288 if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) ) 00289 *out << "check: (sum(" << z_name << ") - sum(" << v_name << "))/n = (" 00290 << sum_z_k << " - " << sum_v_k << ")/" << n << " = " << err << std::endl; 00291 check_test(err,out,&success); 00292 }} 00293 } 00294 00295 /* 00296 00298 if(out && print_all_tests()) 00299 *out << "\n*** Testing sub-vector and sub-space access\n"; 00300 { 00301 const index_type k = 0; 00302 sprintf( z_name, "z[%d]", k ); 00303 if(out && print_all_tests()) 00304 *out << "\n0.0 -> " << z_name << std::endl; 00305 *z[k] = 0.0; 00306 if(out && print_vectors()) 00307 *out << std::endl << z_name << " =\n" << *z[k]; 00308 {for(int r = 0; r < num_random_tests(); ++r) { 00309 index_type 00310 i1 = my_min( n, (index_type)(((double)rand() / RAND_MAX) * n + 1) ), 00311 i2 = my_min( n, (index_type)(((double)rand() / RAND_MAX) * n + 1) ); 00312 if( i1 > i2 ) std::swap( i1, i2 ); 00313 index_type 00314 sub_vec_dim = i2-i1+1; 00315 const RTOp_value_type 00316 val = 10.0; 00317 00318 if(out && print_all_tests()) 00319 *out << "\nsub_vec_mut = " << z_name 00320 << ".sub_view(" << i1 << "," << i2 << ")\n"; 00321 VectorMutable::vec_mut_ptr_t 00322 sub_vec_mut = z[k]->sub_view(i1,i2); 00323 if(out && print_all_tests()) 00324 *out << "sub_vec_mut = " << val << std::endl; 00325 *sub_vec_mut = val; 00326 if(out && print_vectors()) 00327 *out << std::endl << z_name << " =\n" << *z[k]; 00328 00329 err = sub_vec_dim - sub_vec_mut->dim(); 00330 if(out && (print_all_tests() || ::fabs(err) >= warning_tol())) 00331 *out << "check: ("<<i2<<"-"<<i1<<"+1) - sub_vec_mut.dim() = " 00332 << sub_vec_dim <<" - " << sub_vec_mut->dim() << " = " << err << std::endl; 00333 check_test(err,out,&success); 00334 00335 if(out && print_all_tests()) 00336 *out << "\nsub_space = space.sub_space(" << i1 << "," << i2 << ")\n"; 00337 VectorSpace::space_ptr_t 00338 sub_space = space.sub_space(i1,i2); 00339 00340 result = sub_vec_mut->space().is_compatible(*sub_space); 00341 if(out && (print_all_tests() || !result)) 00342 *out << "check: sub_vec_mut->space().is_compatible(*sub_space) : " << result << std::endl; 00343 check_test( result ? 0.0 : -10.0 , out, &success ); 00344 00345 result = sub_space->is_compatible(sub_vec_mut->space()); 00346 if(out && (print_all_tests() || !result)) 00347 *out << "check: sub_space->is_compatible(*sub_vec_mut->space()) : " << result << std::endl; 00348 check_test( result ? 0.0 : -10.0 , out, &success ); 00349 00350 RTOp_value_type 00351 expected_sum = val*sub_vec_dim, 00352 z_k_sum = sum( *z[k] ); 00353 err = (expected_sum - z_k_sum)/sub_vec_mut->dim(); 00354 if(out && (print_all_tests() || ::fabs(err) >= warning_tol())) 00355 *out << "check: ("<<val<<"*("<<i2<<"-"<<i1<<"+1) - sum("<<z_name<<"))/"<<sub_vec_dim 00356 << " = ("<<expected_sum<<" - "<<z_k_sum<<")/"<<sub_vec_dim<<" = "<<err<<std::endl; 00357 check_test(err,out,&success); 00358 00359 if(out && print_all_tests()) 00360 *out << "sub_vec = "<<z_name<<"{const}.sub_view("<<i1<<","<<i2<<")\n"; 00361 Vector::vec_ptr_t 00362 sub_vec = static_cast<const Vector*>(z[k])->sub_view(i1,i2); 00363 00364 err = sub_vec_dim - sub_vec->dim(); 00365 if(out && print_all_tests()) 00366 *out << "check: ("<<i2<<"-"<<i1<<"+1) - sub_vec.dim() = " 00367 << sub_vec_dim << " - " << sub_vec->dim() << " = " << err << std::endl; 00368 check_test(err,out,&success); 00369 00370 expected_sum = val*sub_vec_dim; 00371 z_k_sum = sum(*sub_vec); 00372 err = (expected_sum - z_k_sum)/sub_vec_mut->dim(); 00373 if(out && print_all_tests()) 00374 *out << "check: ("<<val<<"*("<<i2<<"-"<<i1<<"+1) - sum(sub_vec))/"<<sub_vec_dim 00375 << " = ("<<expected_sum<<" - "<<z_k_sum<<")/"<<sub_vec_dim<<" = "<<err<<std::endl; 00376 00377 if(out && print_all_tests()) 00378 *out << "sub_vec_mut = 0.0\n"; 00379 *sub_vec_mut = 0.0; 00380 if(out && print_vectors()) 00381 *out << std::endl << z_name << " =\n" << *z[k]; 00382 }} 00383 } 00384 00386 if(out && print_all_tests()) 00387 *out << "\n*** Testing explicit sub-vector access\n"; 00388 { 00389 const index_type k = 0; 00390 const Vector 00391 &v_from = *v[k]; 00392 sprintf( v_name, "v[%d]", k ); 00393 VectorMutable 00394 &z_to = *z[k]; 00395 sprintf( z_name, "z[%d]", k ); 00396 00397 if(out && print_all_tests()) 00398 *out << "\n0.0 -> " << z_name << std::endl; 00399 *z[k] = 0.0; 00400 if(out && print_vectors()) 00401 *out << std::endl << z_name << " =\n" << *z[k]; 00402 00403 {for(int r = 0; r < num_random_tests(); ++r) { 00404 const index_type // Get random small sub-vectors so parallel efficiency will be good 00405 i1 = my_min( n, (index_type)(((double)rand() / RAND_MAX) * n + 1) ), 00406 i2 = my_min( (index_type)(i1 + ((double)rand() / RAND_MAX) * 9), n ); 00407 const index_type 00408 sub_vec_dim = i2-i1+1; 00409 00410 if(out && print_all_tests()) 00411 *out << std::endl << v_name << ".get_sub_vector(Rang1D("<<i1<<","<<i2<<"),SPARSE,&sub_vec)\n"; 00412 RTOpPack::SubVector sub_vec; 00413 v_from.get_sub_vector(Range1D(i1,i2),&sub_vec); 00414 00415 err = sub_vec_dim - sub_vec.subDim(); 00416 if(out && (print_all_tests() || ::fabs(err) >= warning_tol())) 00417 *out << "check: ("<<i2<<"-"<<i1<<"+1) - sub_vec.subDim() = " 00418 << sub_vec_dim << " - " << sub_vec.subDim() << " = " << err << std::endl; 00419 check_test(err,out,&success); 00420 00421 if(out && print_all_tests()) 00422 *out << z_name << ".set_sub_vector(sub_vec)\n"; 00423 RTOpPack::SparseSubVector spc_sub_vec( sub_vec ); 00424 z_to.set_sub_vector(spc_sub_vec); 00425 if(out && print_vectors()) 00426 *out << std::endl << z_name << " =\n" << z_to; 00427 00428 const RTOp_value_type 00429 v_sub_vec_sum = sum(*v_from.sub_view(i1,i2)), 00430 z_sum = sum(z_to); 00431 err = (v_sub_vec_sum - z_sum)/sub_vec_dim; 00432 if(out && (print_all_tests() || ::fabs(err) >= warning_tol())) 00433 *out << "check: (sum(*"<<v_name<<".sub_view("<<i1<<","<<i2<<"))-sum("<<z_name<<"))/sub_vec.subDim()" 00434 " = ("<<v_sub_vec_sum<<"-"<<z_sum<<")/"<<sub_vec_dim<<" = "<<err<<std::endl; 00435 00436 if(out && print_all_tests()) 00437 *out << v_name << ".free_sub_vector(&sub_vec)\n"; 00438 v_from.free_sub_vector(&sub_vec); 00439 00440 if(out && print_all_tests()) 00441 *out << "*" << z_name<<".sub_view("<<i1<<","<<i2<<") = 0.0\n"; 00442 *z_to.sub_view(i1,i2) = 0.0; 00443 if(out && print_vectors()) 00444 *out << std::endl << z_name << " =\n" << z_to; 00445 00446 }} 00447 } 00448 00449 */ 00450 00452 if(out && print_all_tests()) 00453 *out << "\n*** Testing norms\n"; 00454 if(n > 1) { 00455 const index_type k = 0; 00456 sprintf( z_name, "z[%d]", (int)k ); 00457 00458 const value_type val1 = -2.0, val2 = 3.0; 00459 const index_type i_mid = n/2; 00460 00461 if(out && print_all_tests()) 00462 *out << std::endl << val1 << " -> *" << z_name << ".sub_view(1,"<<i_mid<<")\n"; 00463 *z[k]->sub_view(1,i_mid) = val1; 00464 if(out && print_all_tests()) 00465 *out << val2 << " -> *" << z_name << ".sub_view("<<i_mid+1<<","<<n<<")\n"; 00466 *z[k]->sub_view(i_mid+1,n) = val2; 00467 if(out && print_vectors()) 00468 *out << std::endl << z_name << " =\n" << *z[k] << std::endl; 00469 00470 value_type 00471 norm_1 = z[k]->norm_1(), 00472 expect_norm_1 = (::fabs(val1)*(i_mid) + ::fabs(val2)*(n-i_mid)); 00473 err = (norm_1 - expect_norm_1)/n; 00474 if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) ) 00475 *out << "check: (" << z_name << "->norm_1() - |"<<val1<<"|*("<<i_mid<<")+" 00476 << "|"<<val2<<"|*("<<n<<"-"<<i_mid<<"))/"<<n 00477 <<" = ("<<norm_1<<" - "<<expect_norm_1<<")/"<<n<<" = "<<err<<std::endl; 00478 check_test(err,out,&success); 00479 00480 value_type 00481 norm_2 = z[k]->norm_2(), 00482 expect_norm_2 = ::sqrt(val1*val1*(i_mid) + val2*val2*(n-i_mid)); 00483 err = (norm_2 - expect_norm_2)/n; 00484 if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) ) 00485 *out << "check: (" << z_name << "->norm_2() - ("<<val1<<")^2*("<<i_mid<<")+" 00486 << "("<<val2<<")^2*("<<n<<"-"<<i_mid<<"))/"<<n 00487 <<" = ("<<norm_2<<" - "<<expect_norm_2<<")/"<<n<<" = "<<err<<std::endl; 00488 check_test(err,out,&success); 00489 00490 value_type 00491 norm_inf = z[k]->norm_inf(), 00492 expect_norm_inf = my_max(::fabs(val1),::fabs(val2)); 00493 err = (norm_inf - expect_norm_inf)/n; 00494 if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) ) 00495 *out << "check: (" << z_name << "->norm_inf() - max(|"<<val1<<"|," 00496 << "|"<<val2<<"|)/"<<n<<" = ("<<norm_inf<<" - "<<expect_norm_inf<<")/"<<n 00497 <<" = "<<err<<std::endl; 00498 check_test(err,out,&success); 00499 00500 } 00501 else { 00502 if(out && print_all_tests()) 00503 *out << "space.dim() <= 1, can't test the norms...\n"; 00504 } 00505 00507 if(out && print_all_tests()) 00508 *out << "\n*** Testing clone() method\n"; 00509 { 00510 if(out && print_all_tests()) 00511 *out << "\n(*vec = space.create_member()) = v[0]\n"; 00512 VectorSpace::vec_mut_ptr_t 00513 vec = space.create_member(); 00514 *vec = *v[0]; 00515 if(out && print_all_tests()) 00516 *out << "vec_clone = vec->clone()\n"; 00517 VectorSpace::vec_mut_ptr_t 00518 vec_clone = vec->clone(); 00519 if(out && print_all_tests()) 00520 *out << "vec = NULL\n"; 00521 vec = Teuchos::null; 00522 const value_type 00523 sum_vec = sum(*v[0]), 00524 sum_vec_clone = sum(*vec_clone); 00525 err = (sum_vec - sum_vec_clone)/n; 00526 if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) ) 00527 *out << "check: (sum(v[0]) - sum(vec_clone))/n = (" 00528 << sum_vec << " - " << sum_vec_clone << ")/" << n 00529 << " = " << err << std::endl; 00530 check_test(err,out,&success); 00531 } 00532 00533 } // end try 00534 catch(const std::exception& except) { 00535 if(out) 00536 *out << "Caught a std::exception: " << except.what() << std::endl; 00537 success = false; 00538 if(throw_exception()) 00539 throw; 00540 } 00541 catch(...) { 00542 if(out) 00543 *out << "Caught an unknown exception!\n"; 00544 success = false; 00545 if(throw_exception()) 00546 throw; 00547 } 00548 00549 return success; 00550 } 00551 00552 void VectorSpaceTester::check_test(value_type err, std::ostream* out, bool* success) const 00553 { 00554 if( ::fabs(err) >= error_tol() ) *success = false; 00555 if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) ) { 00556 if( ::fabs(err) >= error_tol() ) 00557 *out << "Error! |" << err << "| = " << ::fabs(err) << " >= error_tol = " 00558 << error_tol() << std::endl; 00559 else if( ::fabs(err) >= warning_tol() ) 00560 *out << "Warning! |" << err << "| = " << ::fabs(err) << " >= warning_tol = " 00561 << warning_tol() << std::endl; 00562 } 00563 TEUCHOS_TEST_FOR_EXCEPTION( 00564 !*success && this->throw_exception(), std::logic_error 00565 ,"VectorSpaceTester::check_test(...): Error! |" << err << "| = " << ::fabs(err) << " >= error_tol = " 00566 << error_tol() << std::endl ); 00567 } 00568 00569 } // end namespace AbstractLinAlgPack
1.7.6.1