Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
#ifndef __UTILS__
#define __UTILS__
#include <armadillo>
#include <iomanip>
#include <sstream>
#include <string>
#include <sys/stat.h>
#include <vector>
#ifdef DBG
#define DEBUG(msg) \
std::cout << __FILE__ << " " << __LINE__ << ": " << msg << std::endl
#else
#define DEBUG(msg)
#endif
#define ASSERT(expr, msg) \
m_assert(expr, #expr, __METHOD_NAME__, __FILE__, __LINE__, msg)
#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
std::string scientific_format(double d, int width = 20, int prec = 10);
std::string scientific_format(const std::vector<double> &v, int width = 20,
int prec = 10);
void m_assert(bool expr, std::string expr_str, std::string func,
std::string file, int line, std::string msg);
bool close_to(arma::vec &a, arma::vec &b, double tol = 1e-8);
static inline std::string methodName(const std::string &pretty_function)
{
size_t colons = pretty_function.find("::");
size_t begin = pretty_function.substr(0, colons).rfind(" ") + 1;
size_t end = pretty_function.rfind("(") - begin;
return pretty_function.substr(begin, end) + "()";
}
bool mkpath(std::string path, int mode = 0777);
#endif
m_assert
void m_assert(bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)
Test an expression, confirm that test is ok, or abort execution.
Definition: utils.cpp:40
mkpath
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:72
close_to
bool close_to(arma::vec &a, arma::vec &b, double tol=1e-8)
Test if two armadillo vectors are close to each other.
Definition: utils.cpp:58
scientific_format
std::string scientific_format(double d, int width=20, int prec=10)
Turns a double into a string written in scientific format.
Definition: utils.cpp:15