More specific fixes

See merge request oss/rotgen!47
This commit is contained in:
Joel Falcou 2025-12-02 14:40:01 +01:00
parent 083ada097e
commit 8e80d1d083
34 changed files with 1171 additions and 416 deletions

View file

@ -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));
};

View 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));
};

View 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);
};

View file

@ -9,9 +9,9 @@
#include "unit/tests.hpp"
TTS_CASE_TPL("SVD decomposition - Dynamic case",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
TTS_CASE_TPL("SVD decomposition - Dynamic case", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
int rank, i = 5;
auto eps = std::numeric_limits<T>::epsilon();
@ -24,10 +24,10 @@ TTS_CASE_TPL("SVD decomposition - Dynamic case",
{
rank = decomp.rank();
auto u = decomp.U(rank);
auto d = decomp.singular_values(rank);
auto dd = decomp.D(rank);
auto v = decomp.V(rank);
auto u = decomp.matrixU(rank);
auto d = decomp.singularValues(rank);
auto dd = decomp.matrixD(rank);
auto v = decomp.matrixV(rank);
TTS_EQUAL(rank, i);
@ -48,9 +48,9 @@ TTS_CASE_TPL("SVD decomposition - Dynamic case",
} while (rank != 1);
};
TTS_CASE_TPL("SVD decomposition - Static case",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
TTS_CASE_TPL("SVD decomposition - Static case", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
int rank, i = 5;
auto eps = std::numeric_limits<T>::epsilon();
@ -62,10 +62,10 @@ TTS_CASE_TPL("SVD decomposition - Static case",
{
rank = decomp.rank();
auto u = decomp.U(rank);
auto d = decomp.singular_values(rank);
auto dd = decomp.D(rank);
auto v = decomp.V(rank);
auto u = decomp.matrixU(rank);
auto d = decomp.singularValues(rank);
auto dd = decomp.matrixD(rank);
auto v = decomp.matrixV(rank);
TTS_EQUAL(rank, i);