13 #ifndef MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_IMPL_HPP 14 #define MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_IMPL_HPP 38 typename std::enable_if<!arma::is_arma_type<T>::value>::type
39 PrefixedOutStream::BaseLogic(
const T& val)
43 bool newlined =
false;
49 std::ostringstream convert;
60 destination <<
"Failed type conversion to string for output; output not " 61 "shown." << std::endl;
71 if (line.length() == 0)
83 while ((nl = line.find(
'\n', pos)) != std::string::npos)
95 carriageReturned =
true;
100 if (pos != line.length())
109 if (fatal && newlined)
123 while ((nl = btLine.find(
'\n', pos)) != std::string::npos)
133 carriageReturned =
true;
140 throw std::runtime_error(
"fatal error; see Log::Fatal output");
146 typename std::enable_if<arma::is_arma_type<T>::value>::type
147 PrefixedOutStream::BaseLogic(
const T& val)
150 const arma::Mat<typename T::elem_type>& printVal(val);
154 bool newlined =
false;
160 std::ostringstream convert;
166 printVal.print(convert);
175 const arma::Mat<typename T::elem_type>& absVal(arma::abs(printVal));
176 double maxVal = absVal.max();
181 const int maxLog = int(log10(maxVal)) + 1;
182 const int padding = 4;
183 convert.width(convert.precision() + maxLog + padding);
184 printVal.raw_print(convert);
192 destination <<
"Failed type conversion to string for output; output not " 193 "shown." << std::endl;
199 line = convert.str();
203 if (line.length() == 0)
215 while ((nl = line.find(
'\n', pos)) != std::string::npos)
227 carriageReturned =
true;
232 if (pos != line.length())
241 if (fatal && newlined)
255 while ((nl = btLine.find(
'\n', pos)) != std::string::npos)
265 carriageReturned =
true;
272 throw std::runtime_error(
"fatal error; see Log::Fatal output");
277 void PrefixedOutStream::PrefixIfNeeded()
280 if (carriageReturned)
285 carriageReturned =
false;
292 #endif // MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_IMPL_HPP std::ostream & destination
The output stream that all data is to be sent to; example: MLPACK_COUT_STREAM.
Definition: prefixedoutstream.hpp:116
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
PrefixedOutStream & operator<<(bool val)
Write a bool to the stream.
Definition: prefixedoutstream.cpp:25
bool ignoreInput
Discards input, prints nothing if true.
Definition: prefixedoutstream.hpp:119
std::string ToString()
Returns string of backtrace.
Definition: backtrace.cpp:168
Allows us to output to an ostream with a prefix at the beginning of each line, in the same way we wou...
Definition: prefixedoutstream.hpp:46
bool backtrace
If true, on a fatal error, a backtrace will be printed if HAS_BFD_DL is defined.
Definition: prefixedoutstream.hpp:123
Provides a backtrace.
Definition: backtrace.hpp:46