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 <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 arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8);
static inline std::string methodName(const std::string& prettyFunction)
{
size_t colons = prettyFunction.find("::");
size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
size_t end = prettyFunction.rfind("(") - begin;
return prettyFunction.substr(begin,end) + "()";
}
#endif
arma_vector_close_to
bool arma_vector_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:59
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
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:14