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 "AbstractLinAlgPack_assert_print_nan_inf.hpp"
00033 #include "AbstractLinAlgPack_Vector.hpp"
00034 #include "RTOp_ROp_find_nan_inf.h"
00035 #include "RTOpPack_RTOpC.hpp"
00036 #include "check_nan_inf.h"
00037 #include "Teuchos_TestForException.hpp"
00038
00039 namespace {
00040
00041
00042 static RTOpPack::RTOpC find_nan_inf_op;
00043 static Teuchos::RCP<RTOpPack::ReductTarget> find_nan_inf_targ;
00044
00045 class init_rtop_server_t {
00046 public:
00047 init_rtop_server_t() {
00048 TEST_FOR_EXCEPT(0!=RTOp_ROp_find_nan_inf_construct(&find_nan_inf_op.op() ));
00049 find_nan_inf_targ = find_nan_inf_op.reduct_obj_create();
00050 }
00051 };
00052
00053 init_rtop_server_t init_rtop_server;
00054
00055 }
00056
00057 bool AbstractLinAlgPack::assert_print_nan_inf( const value_type& val, char name[]
00058 , bool throw_excpt, std::ostream* out )
00059 {
00060 if( RTOp_is_nan_inf(val) ) {
00061 std::ostringstream omsg;
00062 omsg
00063 << "The scalar \"" << name
00064 << "\" = " << val << " is not a valid bounded number";
00065 if(out)
00066 *out << omsg.str() << std::endl;
00067 TEST_FOR_EXCEPTION(
00068 throw_excpt,NaNInfException
00069 ,"assert_print_nan_inf(...) : Error, " << omsg.str() );
00070 return false;
00071 }
00072 return true;
00073 }
00074
00075 bool AbstractLinAlgPack::assert_print_nan_inf(
00076 const Vector& v, char name[]
00077 ,bool throw_excpt, std::ostream* out
00078 )
00079 {
00080 find_nan_inf_op.reduct_obj_reinit(&*find_nan_inf_targ);
00081 const Vector* vecs[1] = { &v };
00082 apply_op(find_nan_inf_op,1,vecs,0,NULL,&*find_nan_inf_targ);
00083 RTOp_ROp_find_nan_inf_reduct_obj_t
00084 ele =RTOp_ROp_find_nan_inf_val(find_nan_inf_op(*find_nan_inf_targ));
00085 if(out && ele.i) {
00086 *out
00087 << "The vector \"" << name << "\" has the first following NaN or Inf element\n"
00088 << name << "(" << ele.i << ") = " << ele.v0_i << std::endl;
00089 }
00090 TEST_FOR_EXCEPTION(
00091 ele.i && throw_excpt, NaNInfException
00092 ,"assert_print_nan_inf(...) : Error, the vector named "
00093 << name << " has at least one element which is NaN or Inf" );
00094
00095 return ele.i == 0;
00096 }