8#include <tracking/trackFindingCDC/numerics/PlainMatrixUtil.h>
9#include <tracking/trackFindingCDC/numerics/PlainMatrix.h>
11#include <tracking/trackFindingCDC/numerics/EigenView.h>
13#include <gtest/gtest.h>
16using namespace TrackFindingCDC;
19TEST(TrackFindingCDCTest, PlainMatrix_zero)
24 for (
int i = 0; i < result.rows(); ++i) {
25 for (
int j = 0; j < result.cols(); ++j) {
26 EXPECT_EQ(0, (result(i, j)));
34 for (
int i = 0; i < result.rows(); ++i) {
35 for (
int j = 0; j < result.cols(); ++j) {
36 EXPECT_EQ(0, (result(i, j)));
43TEST(TrackFindingCDCTest, PlainMatrix_id)
46 for (
int i = 0; i < result.rows(); ++i) {
47 for (
int j = 0; j < result.cols(); ++j) {
49 EXPECT_EQ(1, (result(i, j)));
51 EXPECT_EQ(0, (result(i, j)));
58TEST(TrackFindingCDCTest, PlainMatrix_diag)
63 EXPECT_EQ(5, result.cols());
64 EXPECT_EQ(5, result.rows());
66 for (
int i = 0; i < result.rows(); ++i) {
67 for (
int j = 0; j < result.cols(); ++j) {
69 EXPECT_EQ(i, result(i, j));
71 EXPECT_EQ(0, result(i, j));
78TEST(TrackFindingCDCTest, PlainMatrix_constant)
81 for (
int i = 0; i < result.rows(); ++i) {
82 for (
int j = 0; j < result.cols(); ++j) {
83 EXPECT_EQ(3, (result(i, j)));
89TEST(TrackFindingCDCTest, PlainMatrix_aggregate_initialization)
92 EXPECT_EQ(-1, result(0, 0));
93 EXPECT_EQ(1, result(1, 0));
99 EXPECT_EQ(-1, result2(0, 0));
100 EXPECT_EQ(1, result2(1, 0));
104TEST(TrackFindingCDCTest, PlainMatrix_vstack)
112 EXPECT_EQ(1, result.cols());
113 EXPECT_EQ(5, result.rows());
115 EXPECT_EQ(1, result(0, 0));
116 EXPECT_EQ(2, result(1, 0));
117 EXPECT_EQ(3, result(2, 0));
118 EXPECT_EQ(4, result(3, 0));
119 EXPECT_EQ(5, result(4, 0));
122TEST(TrackFindingCDCTest, PlainMatrix_hstack)
130 EXPECT_EQ(2, result.cols());
131 EXPECT_EQ(2, result.rows());
133 EXPECT_EQ(1, result(0, 0));
134 EXPECT_EQ(2, result(1, 0));
135 EXPECT_EQ(3, result(0, 1));
136 EXPECT_EQ(4, result(1, 1));
141TEST(TrackFindingCDCTest, PlainMatrix_blockstack)
149 EXPECT_EQ(2, result.cols());
150 EXPECT_EQ(5, result.rows());
151 EXPECT_EQ(1, result(0, 0));
152 EXPECT_EQ(2, result(1, 0));
153 EXPECT_EQ(0, result(2, 0));
154 EXPECT_EQ(0, result(3, 0));
155 EXPECT_EQ(0, result(4, 0));
157 EXPECT_EQ(0, result(0, 1));
158 EXPECT_EQ(0, result(1, 1));
159 EXPECT_EQ(3, result(2, 1));
160 EXPECT_EQ(4, result(3, 1));
161 EXPECT_EQ(5, result(4, 1));
164TEST(TrackFindingCDCTest, PlainMatrix_element_access)
172 EXPECT_EQ(2, a(1, 0));
176TEST(TrackFindingCDCTest, PlainMatrix_minus)
182 for (
int i = 0; i < result.rows(); ++i) {
183 for (
int j = 0; j < result.cols(); ++j) {
184 EXPECT_EQ(1 , result(i, j));
189TEST(TrackFindingCDCTest, PlainMatrix_plus)
195 for (
int i = 0; i < result.rows(); ++i) {
196 for (
int j = 0; j < result.cols(); ++j) {
197 EXPECT_EQ(3, result(i, j));
202TEST(TrackFindingCDCTest, PlainMatrix_divide)
206 auto result = a / 2.0;
207 for (
int i = 0; i < result.rows(); ++i) {
208 for (
int j = 0; j < result.cols(); ++j) {
209 EXPECT_EQ(1, result(i, j));
215TEST(TrackFindingCDCTest, PlainMatrix_inverse_divide)
219 auto result = 2.0 / a;
220 for (
int i = 0; i < result.rows(); ++i) {
221 for (
int j = 0; j < result.cols(); ++j) {
222 EXPECT_EQ(1, result(i, j));
227TEST(TrackFindingCDCTest, PlainMatrix_muliplication)
234 EXPECT_EQ(1, result.cols());
235 EXPECT_EQ(1, result.rows());
237 EXPECT_EQ(1, result(0, 0));
239 auto result2 = a * b;
241 EXPECT_EQ(2, result2.cols());
242 EXPECT_EQ(2, result2.rows());
244 EXPECT_EQ(1.0 / 2.0, result2(0, 0));
245 EXPECT_EQ(1.0 / 2.0, result2(1, 0));
246 EXPECT_EQ(1.0 / 2.0, result2(0, 1));
247 EXPECT_EQ(1.0 / 2.0, result2(1, 1));
250TEST(TrackFindingCDCTest, PlainMatrix_block)
257 auto aNew = result.block<2, 1>(0, 0);
258 auto bNew = result.block<3, 1>(2, 1);
260 EXPECT_TRUE(std::equal(a.data(), a.data() + a.size(), aNew.data()));
261 EXPECT_TRUE(std::equal(b.data(), b.data() + b.size(), bNew.data()));
264TEST(TrackFindingCDCTest, PlainMatrixEigenMap_mapToEigen)
270 auto eigenMap = mapToEigen(result);
272 for (
int i = 0; i < result.rows(); ++i) {
273 for (
int j = 0; j < result.cols(); ++j) {
274 EXPECT_EQ(result(i, j) , eigenMap(i, j));
280 EXPECT_EQ(0, eigenMap(0, 0)) <<
"write back test " << 0 <<
", " << 0;
281 EXPECT_EQ(0, result(0, 0)) <<
"write back test " << 0 <<
", " << 0;
284 eigenMap = Eigen::Matrix<double, 5, 2>::Zero();
286 for (
int i = 0; i < result.rows(); ++i) {
287 for (
int j = 0; j < result.cols(); ++j) {
288 EXPECT_EQ(0, result(i, j)) <<
"write back test " << i <<
", " << j;
293TEST(TrackFindingCDCTest, PlainMatrixEigenMap_output_operator)
296 std::stringstream oss;
A matrix implementation to be used as an interface typ through out the track finder.
static PlainMatrix< T, M, N > Constant(T t)
Construct a matrix with all elements set to a constant.
static PlainMatrix< T, M, N > Identity()
Construct an identity matrix.
static PlainMatrix< T, M, N > Zero()
Construct a matrix initialized with zeros.
Abstract base class for different kinds of events.
static PlainMatrix< T, K+M, N > VStack(const PlainMatrix< T, K, N > &a, const PlainMatrix< T, M, N > &b)
Construct a matrix from two independent blocks stacked vertically.
static PlainMatrix< T, M, M > Diag(const PlainMatrix< T, M, 1 > &diagEntries)
Construct a diagonal matrix - currently private as it is unused.
static PlainMatrix< T, M, L+N > HStack(const PlainMatrix< T, M, L > &a, const PlainMatrix< T, M, N > &b)
Construct a matrix from two independent blocks stacked horizontally.
static PlainMatrix< T, K+M, L+N > BlockStack(const PlainMatrix< T, K, L > &a, const PlainMatrix< T, M, N > &b)
Construct a matrix from two independent blocks stacked along the diagonal.