ppforest2
v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
Macros.hpp
Go to the documentation of this file.
1
#pragma once
2
10
11
#include "
utils/Invariant.hpp
"
// IWYU pragma: keep
12
#include "
utils/Math.hpp
"
13
#include <Eigen/Dense>
14
16
#define ASSERT_APPROX(a, b) \
17
ASSERT_TRUE(a.isApprox(b, APPROX_THRESHOLD)) << "Expected " << std::endl \
18
<< a << std::endl \
19
<< " to be approximate to " << std::endl \
20
<< b
21
23
#define ASSERT_COLLINEAR(a, b) \
24
ASSERT_TRUE(ppforest2::math::collinear(a, b)) << "Expected columns of " << std::endl \
25
<< a << std::endl \
26
<< " to be collinear with its respective column of " << std::endl \
27
<< b
28
30
#define ASSERT_EQ_DATA(a, b) \
31
ASSERT_EQ(a.size(), b.size()); \
32
ASSERT_EQ(a.rows(), b.rows()); \
33
ASSERT_EQ(a.cols(), b.cols()); \
34
ASSERT_EQ(a, b);
35
36
#define EXPECT_EQ_DATA(a, b) \
37
EXPECT_EQ(a.size(), b.size()); \
38
EXPECT_EQ(a.rows(), b.rows()); \
39
EXPECT_EQ(a.cols(), b.cols()); \
40
EXPECT_EQ(a, b);
41
42
// Workaround for GCC miscompilation of long overloaded operator, chains
43
// (see https://stackoverflow.com/questions/79872387).
44
// Use these instead of Eigen's comma initializer (operator<<) for matrices and vectors.
45
46
constexpr
int
rows
(
int
n) {
47
return
n;
48
}
49
50
#define VEC(T, ...) \
51
([&]() -> Eigen::Matrix<T, Eigen::Dynamic, 1> { \
52
std::vector<T> _vals = {__VA_ARGS__}; \
53
return Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>>(_vals.data(), _vals.size()); \
54
})()
55
56
#define MAT(T, ROWS, ...) \
57
([&]() -> Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> { \
58
const int _rows = static_cast<int>(ROWS); \
59
std::vector<T> _vals = {__VA_ARGS__}; \
60
invariant(_rows > 0, "ROWS must be > 0"); \
61
invariant(_vals.size() % _rows == 0, "Element count not divisible by ROWS"); \
62
const int _cols = static_cast<int>(_vals.size()) / _rows; \
63
return Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>( \
64
_vals.data(), _rows, _cols \
65
); \
66
})()
Invariant.hpp
rows
constexpr int rows(int n)
Definition
Macros.hpp:46
Math.hpp
core
src
utils
Macros.hpp
Generated by
1.13.2