1 # ifndef CPPAD_CORE_CHECK_FOR_NAN_HPP
2 # define CPPAD_CORE_CHECK_FOR_NAN_HPP
135 # include <cppad/configure.hpp>
138 # if CPPAD_HAS_MKSTEMP
142 # if CPPAD_HAS_TMPNAM_S
158 template <
class Base>
160 { check_for_nan_ = value; }
168 template <
class Base>
170 {
return check_for_nan_; }
181 template <
class Base>
184 size_t char_size =
sizeof(Base) * vec.
size();
185 const char* char_ptr =
reinterpret_cast<const char*
>( vec.
data() );
186 # if CPPAD_HAS_MKSTEMP
187 char pattern[] =
"/tmp/fileXXXXXX";
188 int fd = mkstemp(pattern);
190 write(fd, char_ptr, char_size);
193 # if CPPAD_HAS_TMPNAM_S
194 std::vector<char> name(L_tmpnam_s);
195 if( tmpnam_s( name.data(), L_tmpnam_s ) != 0 )
198 "Cannot create a temporary file name"
201 file_name = name.data();
203 file_name = tmpnam( CPPAD_NULL );
205 std::fstream file_out(file_name.c_str(), std::ios::out|std::ios::binary );
206 file_out.write(char_ptr, char_size);
221 template <
class Base>
224 size_t n = vec.
size();
225 size_t char_size =
sizeof(Base) * n;
226 char* char_ptr =
reinterpret_cast<char*
>( vec.
data() );
228 std::fstream file_in(file_name.c_str(), std::ios::in|std::ios::binary );
229 file_in.read(char_ptr, char_size);
#define CPPAD_ASSERT_KNOWN(exp, msg)
Check that exp is true, if not print msg and terminate execution.
void put_check_for_nan(const CppAD::vector< Base > &vec, std::string &file_name)
Stores a vector in a file when nans occur.
Type * data(void)
raw pointer to the data
bool check_for_nan(void) const
get check_for_nan
size_t size(void) const
number of elements currently in this vector.
File used to define CppAD::vector and CppAD::vectorBool.
void get_check_for_nan(CppAD::vector< Base > &vec, const std::string &file_name)
Gets a vector that was stored by put_check_for_nan.