18 ss << std::setw(width) << std::setprecision(prec) << std::scientific << d;
25 for (
double elem : v) {
31static void print_message(std::string msg)
34 std::cout <<
"message: " << msg <<
"\n\n";
40void m_assert(
bool expr, std::string expr_str, std::string f, std::string file,
41 int line, std::string msg)
43 std::string new_assert(f.size() + (expr ? 4 : 6),
'-');
44 std::cout <<
"\x1B[36m" << new_assert <<
"\033[0m\n";
45 std::cout << f <<
": ";
47 std::cout <<
"\x1B[32mOK\033[0m\n";
50 std::cout <<
"\x1B[31mFAIL\033[0m\n";
52 std::cout << file <<
" " << line <<
": Assertion \"" << expr_str
58bool close_to(arma::vec &a, arma::vec &b,
double tol)
60 if (a.n_elem != b.n_elem) {
64 for (
size_t i = 0; i < a.n_elem; i++) {
65 if (std::abs(a(i) - b(i)) >= tol) {
72bool mkpath(std::string path,
int mode)
75 std::string::size_type pos = -1;
78 if (path.back() !=
'/') {
83 pos = path.find(
'/', pos);
84 if (pos != std::string::npos) {
85 cur_dir = path.substr(0, pos);
86 if (mkdir(cur_dir.c_str(), mode) != 0
87 && stat(cur_dir.c_str(), &buf) != 0) {
bool close_to(arma::vec &a, arma::vec &b, double tol)
Test if two armadillo vectors are close to each other.
std::string scientific_format(double d, int width, int prec)
Turns a double into a string written in scientific format.
bool mkpath(std::string path, int mode)
Make path given.
void m_assert(bool expr, std::string expr_str, std::string f, std::string file, int line, std::string msg)
Test an expression, confirm that test is ok, or abort execution.
Function prototypes and macros that are useful.