|
DenseLinAlgPack: Concreate C++ Classes for Dense Blas-Compatible Linear Algebra 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 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #include <ostream> 00030 #include <sstream> 00031 #include <iomanip> 00032 00033 #include "DenseLinAlgPack_assert_print_nan_inf.hpp" 00034 #include "DenseLinAlgPack_DVectorClass.hpp" 00035 #include "DenseLinAlgPack_DMatrixClass.hpp" 00036 #include "check_nan_inf.h" 00037 00038 bool DenseLinAlgPack::assert_print_nan_inf( const value_type& val, char name[] 00039 , bool throw_excpt, std::ostream* out ) 00040 { 00041 00042 if( RTOp_is_nan_inf(val) ) { 00043 std::ostringstream omsg; 00044 omsg 00045 << "The scalar \"" << name 00046 << "\" = " << val << " is not a valid bounded number"; 00047 if(out) 00048 *out << omsg.str() << std::endl; 00049 if( throw_excpt ) { 00050 if(out) 00051 out->flush(); 00052 throw NaNInfException( "assert_print_nan_inf(...) : Error, " 00053 + omsg.str() ); 00054 } 00055 return false; 00056 } 00057 return true; 00058 } 00059 00060 bool DenseLinAlgPack::assert_print_nan_inf( const DVectorSlice& v, char name[] 00061 , bool throw_excpt, std::ostream* out ) 00062 { 00063 00064 bool has_nan_or_inf = false; 00065 bool printed_header = false; 00066 00067 for( DVectorSlice::const_iterator v_itr = v.begin(); v_itr != v.end(); ++v_itr ) { 00068 if( RTOp_is_nan_inf(*v_itr) ) { 00069 if(out) { 00070 if(!printed_header) { 00071 *out 00072 << "The vector \"" << name 00073 << "\" has the following NaN or Inf entries\n"; 00074 printed_header = true; 00075 } 00076 *out 00077 << name << "(" << v_itr - v.begin() + 1 << ") = " 00078 << *v_itr << std::endl; 00079 } 00080 has_nan_or_inf = true; 00081 } 00082 } 00083 if( has_nan_or_inf && throw_excpt ) { 00084 if(out) 00085 out->flush(); 00086 std::ostringstream omsg; 00087 omsg 00088 << "assert_print_nan_inf(...) : Error, the vector named " 00089 << name << " has at least one element which is NaN or Inf"; 00090 throw NaNInfException( omsg.str() ); 00091 } 00092 00093 return !has_nan_or_inf; 00094 } 00095 00096 bool DenseLinAlgPack::assert_print_nan_inf( const DMatrixSlice& m, char name[] 00097 , bool throw_excpt, std::ostream* out ) 00098 { 00099 00100 bool has_nan_or_inf = false; 00101 bool printed_header = false; 00102 00103 for( size_type j = 1; j <= m.cols(); ++j ) { 00104 const DVectorSlice& v = m.col(j); 00105 for( DVectorSlice::const_iterator v_itr = v.begin(); v_itr != v.end(); ++v_itr ) { 00106 if( RTOp_is_nan_inf(*v_itr) ) { 00107 if(out) { 00108 if(!printed_header) { 00109 *out 00110 << "The matrix \"" << name 00111 << "\" has the following NaN or Inf entries\n"; 00112 printed_header = true; 00113 } 00114 *out 00115 << name << "(" << v_itr - v.begin() + 1 << "," << j << ") = " 00116 << *v_itr << std::endl; 00117 } 00118 has_nan_or_inf = true; 00119 } 00120 } 00121 } 00122 00123 if( has_nan_or_inf && throw_excpt ) { 00124 if(out) 00125 out->flush(); 00126 std::ostringstream omsg; 00127 omsg 00128 << "assert_print_nan_inf(...) : Error, the matrix named " 00129 << name << " has at least one element which is NaN or Inf"; 00130 throw NaNInfException( omsg.str() ); 00131 } 00132 00133 return has_nan_or_inf; 00134 }
1.7.4