parent
083ada097e
commit
8e80d1d083
34 changed files with 1171 additions and 416 deletions
|
|
@ -77,3 +77,39 @@ TTS_CASE("Extraction of ref/ref const")
|
|||
for (rotgen::Index r = 0; r < 4; r++)
|
||||
for (rotgen::Index c = 0; c < 3; c++) TTS_EQUAL(sliced(r, c), 5.f);
|
||||
};
|
||||
|
||||
void process_col(rotgen::matrix<float, 3, 4>& m,
|
||||
rotgen::matrix<float, 3, 1> const& n,
|
||||
int c)
|
||||
{
|
||||
col(m, c) += n;
|
||||
}
|
||||
|
||||
TTS_CASE("Compound operators on extractions")
|
||||
{
|
||||
rotgen::matrix<float, 3, 4> m;
|
||||
rotgen::matrix<float, 3, 4> reference;
|
||||
rotgen::matrix<float, 3, 1> n;
|
||||
setZero(m);
|
||||
setConstant(n, 10);
|
||||
setConstant(reference, 10);
|
||||
|
||||
for (int i = 0; i < m.cols(); i++) process_col(m, n, i);
|
||||
|
||||
TTS_EQUAL(m, reference);
|
||||
};
|
||||
|
||||
TTS_CASE("Compatibility of 1D blocks")
|
||||
{
|
||||
rotgen::matrix<float, 4, 2> V;
|
||||
setConstant(V, 99);
|
||||
rotgen::matrix<float, 3, 1> C{12, 34, 56};
|
||||
|
||||
extract<1, 2>(V, 0, 0) = segment<2>(C, 0);
|
||||
extract<2, 1>(V, 1, 0) = segment<2>(C, 1);
|
||||
|
||||
TTS_EQUAL(V(0, 0), C(0));
|
||||
TTS_EQUAL(V(0, 1), C(1));
|
||||
TTS_EQUAL(V(1, 0), C(1));
|
||||
TTS_EQUAL(V(2, 0), C(2));
|
||||
};
|
||||
|
|
|
|||
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));
|
||||
};
|
||||
50
test/integration/specifics.cpp
Normal file
50
test/integration/specifics.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
#include "unit/tests.hpp"
|
||||
|
||||
bool categorize_as_scalar(double)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool categorize_as_scalar(rotgen::ref<rotgen::matrix<double, 1, 1>>)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TTS_CASE("Matrix product of 1xN by Nx1 yields a scalar-convertible object")
|
||||
{
|
||||
rotgen::matrix<double, 1, 2> a = {1, 2};
|
||||
rotgen::matrix<double, 2, 1> b = {10, 20};
|
||||
|
||||
double n = a * b;
|
||||
|
||||
TTS_EQUAL(n, 50);
|
||||
TTS_EXPECT(categorize_as_scalar(a * b));
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Static 1x1 matrix-like objects can be assigned as-if",
|
||||
rotgen::tests::types)
|
||||
|
||||
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
||||
{
|
||||
rotgen::matrix<T, 1, 2> a = {1, 2};
|
||||
rotgen::matrix<T, 2, 1> b = {10, 20};
|
||||
|
||||
rotgen::matrix<T, -1, -1, O::value> big(10, 10);
|
||||
auto bk = extract<1, 1>(big, 2, 2);
|
||||
bk = a * b;
|
||||
TTS_EQUAL(big(2, 2), 50);
|
||||
|
||||
rotgen::map<rotgen::matrix<T, 1, 1, O::value>> big_map(big.data(), 1, 1);
|
||||
|
||||
big_map = a * b;
|
||||
TTS_EQUAL(big(0, 0), 50);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue