ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
Macros.hpp File Reference
#include "utils/Invariant.hpp"
#include "utils/Math.hpp"
#include <Eigen/Dense>

Go to the source code of this file.

Macros

#define ASSERT_APPROX(a, b)
 Test helper macros for Eigen comparisons and literal construction.
 
#define ASSERT_COLLINEAR(a, b)
 Assert that two Eigen vectors are collinear (parallel or anti-parallel).
 
#define ASSERT_EQ_DATA(a, b)
 Assert that two Eigen objects have identical size and values.
 
#define MAT(T, ROWS, ...)
 
#define VEC(T, ...)
 

Functions

constexpr int rows (int n)
 

Macro Definition Documentation

◆ ASSERT_APPROX

#define ASSERT_APPROX ( a,
b )
Value:
ASSERT_TRUE(a.isApprox(b, APPROX_THRESHOLD)) << "Expected " << std::endl \
<< a << std::endl \
<< " to be approximate to " << std::endl \
<< b
#define APPROX_THRESHOLD
Definition Math.hpp:8

Test helper macros for Eigen comparisons and literal construction.

Provides GTest assertion macros for approximate and collinear comparisons, plus VEC/MAT macros that replace Eigen's comma initializer to work around a GCC miscompilation issue.

Assert that two Eigen objects are approximately equal.

◆ ASSERT_COLLINEAR

#define ASSERT_COLLINEAR ( a,
b )
Value:
ASSERT_TRUE(ppforest2::math::collinear(a, b)) << "Expected columns of " << std::endl \
<< a << std::endl \
<< " to be collinear with its respective column of " << std::endl \
<< b
bool collinear(types::Vector< T > const &a, types::Vector< T > const &b)
Check whether two vectors are collinear (parallel or anti-parallel).
Definition Math.hpp:43

Assert that two Eigen vectors are collinear (parallel or anti-parallel).

◆ ASSERT_EQ_DATA

#define ASSERT_EQ_DATA ( a,
b )
Value:
ASSERT_EQ(a.size(), b.size()); \
ASSERT_EQ(a.rows(), b.rows()); \
ASSERT_EQ(a.cols(), b.cols()); \
ASSERT_EQ(a, b);

Assert that two Eigen objects have identical size and values.

◆ MAT

#define MAT ( T,
ROWS,
... )
Value:
([&]() -> Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> { \
const int _rows = static_cast<int>(ROWS); \
std::vector<T> _vals = {__VA_ARGS__}; \
invariant(_rows > 0, "ROWS must be > 0"); \
invariant(_vals.size() % _rows == 0, "Element count not divisible by ROWS"); \
const int _cols = static_cast<int>(_vals.size()) / _rows; \
return Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>( \
_vals.data(), _rows, _cols); \
})()

◆ VEC

#define VEC ( T,
... )
Value:
([&]() -> Eigen::Matrix<T, Eigen::Dynamic, 1> { \
std::vector<T> _vals = {__VA_ARGS__}; \
return Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>>(_vals.data(), _vals.size()); \
})()

Function Documentation

◆ rows()

int rows ( int n)
constexpr