parent
083ada097e
commit
8e80d1d083
34 changed files with 1171 additions and 416 deletions
123
test/integration/initialize_with.cpp
Normal file
123
test/integration/initialize_with.cpp
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
#include "unit/tests.hpp"
|
||||
#include <Eigen/Core>
|
||||
|
||||
TTS_CASE_TPL("Initialize a matrix with a list of scalars", rotgen::tests::types)
|
||||
|
||||
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
||||
{
|
||||
using eigen_t = Eigen::Matrix<T, -1, -1, O::value>;
|
||||
using rotgen_t = rotgen::matrix<T, -1, -1, O::value>;
|
||||
|
||||
eigen_t reference(3, 3);
|
||||
reference << 1, 2, 3, 4, 5, 6, 7, 8, 9;
|
||||
|
||||
rotgen_t values(3, 3);
|
||||
initialize_with(values, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
|
||||
for (int r = 0; r < 3; r++)
|
||||
for (int c = 0; c < 3; c++) TTS_EQUAL(values(r, c), reference(r, c));
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Initialize a sub-matrix with a list of scalars",
|
||||
rotgen::tests::types)
|
||||
|
||||
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
||||
{
|
||||
using eigen_t = Eigen::Matrix<T, -1, -1, O::value>;
|
||||
using rotgen_t = rotgen::matrix<T, -1, -1, O::value>;
|
||||
|
||||
eigen_t reference(6, 6);
|
||||
reference.block(1, 1, 3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9;
|
||||
|
||||
rotgen_t values(6, 6);
|
||||
initialize_with(extract(values, 1, 1, 3, 3), 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
|
||||
for (int r = 0; r < 3; r++)
|
||||
for (int c = 0; c < 3; c++)
|
||||
TTS_EQUAL(values(r + 1, c + 1), reference(r + 1, c + 1));
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Initialize a map with a list of scalars", rotgen::tests::types)
|
||||
|
||||
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
||||
{
|
||||
using eigen_t = Eigen::Matrix<T, -1, -1, O::value>;
|
||||
using rotgen_t = rotgen::matrix<T, -1, -1, O::value>;
|
||||
|
||||
T eigen_data[9] = {};
|
||||
T rotgen_data[9] = {};
|
||||
|
||||
Eigen::Map<eigen_t> reference(eigen_data, 3, 3);
|
||||
reference << 1, 2, 3, 4, 5, 6, 7, 8, 9;
|
||||
|
||||
rotgen::map<rotgen_t> values(rotgen_data, 3, 3);
|
||||
initialize_with(values, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
|
||||
for (int i = 0; i < 9; i++) TTS_EQUAL(eigen_data[i], rotgen_data[i]);
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Initialize a sub-map with a list of scalars",
|
||||
rotgen::tests::types)
|
||||
|
||||
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
||||
{
|
||||
using eigen_t = Eigen::Matrix<T, -1, -1, O::value>;
|
||||
using rotgen_t = rotgen::matrix<T, -1, -1, O::value>;
|
||||
|
||||
T eigen_data[36] = {};
|
||||
T rotgen_data[36] = {};
|
||||
|
||||
Eigen::Map<eigen_t> reference(eigen_data, 6, 6);
|
||||
reference.block(1, 1, 3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9;
|
||||
|
||||
rotgen::map<rotgen_t> values(rotgen_data, 6, 6);
|
||||
initialize_with(extract(values, 1, 1, 3, 3), 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
|
||||
for (int i = 0; i < 9; i++) TTS_EQUAL(eigen_data[i], rotgen_data[i]);
|
||||
};
|
||||
|
||||
void process(rotgen::ref<rotgen::matrixXf> r)
|
||||
{
|
||||
rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
}
|
||||
|
||||
void process(rotgen::ref<rotgen::matrixXd> r)
|
||||
{
|
||||
rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
}
|
||||
|
||||
void process(rotgen::ref<rotgen::matrix<float, -1, -1, rotgen::RowMajor>> r)
|
||||
{
|
||||
rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
}
|
||||
|
||||
void process(rotgen::ref<rotgen::matrix<double, -1, -1, rotgen::RowMajor>> r)
|
||||
{
|
||||
rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
}
|
||||
|
||||
TTS_CASE_TPL("Initialize a ref with a list of scalars", rotgen::tests::types)
|
||||
|
||||
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
||||
{
|
||||
using eigen_t = Eigen::Matrix<T, -1, -1, O::value>;
|
||||
using rotgen_t = rotgen::matrix<T, -1, -1, O::value>;
|
||||
|
||||
eigen_t reference(3, 3);
|
||||
reference << 1, 2, 3, 4, 5, 6, 7, 8, 9;
|
||||
|
||||
rotgen_t values(3, 3);
|
||||
process(values);
|
||||
|
||||
for (int r = 0; r < 3; r++)
|
||||
for (int c = 0; c < 3; c++) TTS_EQUAL(values(r, c), reference(r, c));
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue