14 #ifndef MLPACK_CORE_DATA_HAS_NANINF_HPP 15 #define MLPACK_CORE_DATA_HAS_NANINF_HPP 27 inline bool IsNaNInf(T& val,
const std::string& token)
30 if ((token.length() == 3) || (token.length() == 4))
32 const bool neg = (token[0] ==
'-');
33 const bool pos = (token[0] ==
'+');
35 const size_t offset = ((neg || pos) && (token.length() == 4)) ? 1 : 0;
37 const std::string token2 = token.substr(offset, 3);
39 if ((token2 ==
"inf") || (token2 ==
"Inf") || (token2 ==
"INF"))
41 if (std::numeric_limits<T>::has_infinity)
43 val = (!neg) ? std::numeric_limits<T>::infinity() :
44 -1 * std::numeric_limits<T>::infinity();
48 val = (!neg) ? std::numeric_limits<T>::max() :
49 -1 * std::numeric_limits<T>::max();
54 else if ((token2 ==
"nan") || (token2 ==
"Nan") || (token2 ==
"NaN") ||
57 if (std::numeric_limits<T>::has_quiet_NaN)
58 val = std::numeric_limits<T>::quiet_NaN();
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
bool IsNaNInf(T &val, const std::string &token)
See if the token is a NaN or an Inf, and if so, set the value accordingly and return a boolean repres...