46 #include "DenseLinAlgPack_assert_print_nan_inf.hpp"
47 #include "DenseLinAlgPack_DVectorClass.hpp"
48 #include "DenseLinAlgPack_DMatrixClass.hpp"
49 #include "check_nan_inf.h"
51 bool DenseLinAlgPack::assert_print_nan_inf(
const value_type& val
52 ,
const std::string & name,
bool throw_excpt, std::ostream* out )
55 if( RTOp_is_nan_inf(val) ) {
56 std::ostringstream omsg;
58 <<
"The scalar \"" << name
59 <<
"\" = " << val <<
" is not a valid bounded number";
61 *out << omsg.str() << std::endl;
65 throw NaNInfException(
"assert_print_nan_inf(...) : Error, "
73 bool DenseLinAlgPack::assert_print_nan_inf(
const DVectorSlice& v
74 ,
const std::string & name,
bool throw_excpt, std::ostream* out )
77 bool has_nan_or_inf =
false;
78 bool printed_header =
false;
80 for( DVectorSlice::const_iterator v_itr = v.begin(); v_itr != v.end(); ++v_itr ) {
81 if( RTOp_is_nan_inf(*v_itr) ) {
85 <<
"The vector \"" << name
86 <<
"\" has the following NaN or Inf entries\n";
87 printed_header =
true;
90 << name <<
"(" << v_itr - v.begin() + 1 <<
") = "
91 << *v_itr << std::endl;
93 has_nan_or_inf =
true;
96 if( has_nan_or_inf && throw_excpt ) {
99 std::ostringstream omsg;
101 <<
"assert_print_nan_inf(...) : Error, the vector named "
102 << name <<
" has at least one element which is NaN or Inf";
103 throw NaNInfException( omsg.str() );
106 return !has_nan_or_inf;
109 bool DenseLinAlgPack::assert_print_nan_inf(
const DMatrixSlice& m
110 ,
const std::string & name,
bool throw_excpt, std::ostream* out )
113 bool has_nan_or_inf =
false;
114 bool printed_header =
false;
116 for(
size_type j = 1; j <= m.cols(); ++j ) {
117 const DVectorSlice& v = m.col(j);
118 for( DVectorSlice::const_iterator v_itr = v.begin(); v_itr != v.end(); ++v_itr ) {
119 if( RTOp_is_nan_inf(*v_itr) ) {
121 if(!printed_header) {
123 <<
"The matrix \"" << name
124 <<
"\" has the following NaN or Inf entries\n";
125 printed_header =
true;
128 << name <<
"(" << v_itr - v.begin() + 1 <<
"," << j <<
") = "
129 << *v_itr << std::endl;
131 has_nan_or_inf =
true;
136 if( has_nan_or_inf && throw_excpt ) {
139 std::ostringstream omsg;
141 <<
"assert_print_nan_inf(...) : Error, the matrix named "
142 << name <<
" has at least one element which is NaN or Inf";
143 throw NaNInfException( omsg.str() );
146 return has_nan_or_inf;