Implement fixed size options for rotgen containers

See merge request oss/rotgen!11
This commit is contained in:
Joel Falcou 2025-07-20 20:23:51 +02:00
parent 8e545dd51a
commit 2084874b1b
39 changed files with 1247 additions and 323 deletions

View file

@ -6,22 +6,21 @@
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/matrix.hpp>
#include <rotgen/extract.hpp>
#include <rotgen/rotgen.hpp>
template<typename EigenType, typename F>
void for_each_element(EigenType const& m, F&& f)
{
for(std::size_t i = 0; i < m.rows(); ++i)
for(std::size_t j = 0; j < m.cols(); ++j)
for(rotgen::Index i = 0; i < m.rows(); ++i)
for(rotgen::Index j = 0; j < m.cols(); ++j)
f(i, j, m(i,j));
}
template<typename EigenType, typename F>
void for_each_element(EigenType& m, F&& f)
{
for(std::size_t i = 0; i < m.rows(); ++i)
for(std::size_t j = 0; j < m.cols(); ++j)
for(rotgen::Index i = 0; i < m.rows(); ++i)
for(rotgen::Index j = 0; j < m.cols(); ++j)
f(i, j, m(i,j));
}
@ -30,8 +29,8 @@ MatrixType make_initialized_matrix(rotgen::tests::matrix_block_test_case<MatrixT
{
MatrixType matrix(matrix_construct.rows, matrix_construct.cols);
for(std::size_t i = 0; i < matrix_construct.rows; ++i)
for(std::size_t j = 0; j < matrix_construct.cols; ++j)
for(rotgen::Index i = 0; i < matrix_construct.rows; ++i)
for(rotgen::Index j = 0; j < matrix_construct.cols; ++j)
matrix(i, j) = static_cast<T>(matrix_construct.init_fn(i, j));
return matrix;
@ -39,8 +38,8 @@ MatrixType make_initialized_matrix(rotgen::tests::matrix_block_test_case<MatrixT
template<typename MatrixType, typename BlockType, typename T>
void validate_block_behavior(MatrixType& matrix, BlockType& block,
std::size_t i0, std::size_t j0,
std::size_t ni, std::size_t nj)
rotgen::Index i0, rotgen::Index j0,
rotgen::Index ni, rotgen::Index nj)
{
TTS_EQUAL(block.rows(), ni);
TTS_EQUAL(block.cols(), nj);
@ -125,13 +124,13 @@ void test_dynamic_block_extraction(rotgen::tests::matrix_block_test_case<MatrixT
}
template<typename MatrixType, typename T, std::size_t NI, std::size_t NJ>
template<typename MatrixType, typename T, rotgen::Index NI, rotgen::Index NJ>
void test_static_block_extraction(rotgen::tests::static_matrix_block_test_case<MatrixType, NI, NJ> const& matrix_construct)
{
MatrixType matrix(matrix_construct.rows, matrix_construct.cols);
for (std::size_t i = 0; i < matrix_construct.rows; ++i)
for (std::size_t j = 0; j < matrix_construct.cols; ++j)
for (rotgen::Index i = 0; i < matrix_construct.rows; ++i)
for (rotgen::Index j = 0; j < matrix_construct.cols; ++j)
matrix(i, j) = static_cast<T>(matrix_construct.init_fn(i, j));
auto block_main = rotgen::extract<NI, NJ>(matrix, matrix_construct.i0, matrix_construct.j0);
@ -206,10 +205,10 @@ TTS_CASE_TPL("Check all dynamic block extractions on a dynamic row-major matrix"
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value, 1>;
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> cases = {
{ 6, 11, [](std::size_t i, std::size_t j) { return T(i * 10 + j); }, 1, 2, 3, 2 },
{ 7, 10, [](std::size_t i, std::size_t j) { return T(std::sin(i + j)); }, 4, 4, 3, 3 },
{ 5, 5, [](std::size_t i, std::size_t j) { return T((i + j) % 7); }, 0, 0, 5, 5 },
{ 9, 14, [](std::size_t i, std::size_t j) { return T(i+j + 3*j); }, 3, 7, 1, 1 }
{ 6, 11, [](rotgen::Index i, rotgen::Index j) { return T(i * 10 + j); }, 1, 2, 3, 2 },
{ 7, 10, [](rotgen::Index i, rotgen::Index j) { return T(std::sin(i + j)); }, 4, 4, 3, 3 },
{ 5, 5, [](rotgen::Index i, rotgen::Index j) { return T((i + j) % 7); }, 0, 0, 5, 5 },
{ 9, 14, [](rotgen::Index i, rotgen::Index j) { return T(i+j + 3*j); }, 3, 7, 1, 1 }
};
for (auto const& matrix_case : cases) {
@ -224,9 +223,9 @@ TTS_CASE_TPL("Check all dynamic block extractions on a static column-major matri
using mat_t = rotgen::matrix<T,4,5,O::value, 0>;
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> cases = {
{ 4, 5, [](std::size_t i, std::size_t j) { return T(2*i + j*j*j - 42); }, 1, 2, 3, 2 },
{ 4, 5, [](std::size_t i, std::size_t j) { return T(std::tan(i*i*j)); }, 0, 1, 2, 1 },
{ 4, 5, [](std::size_t i, std::size_t j) { return T((i*i + j*j) / 6); }, 2, 0, 0, 0 }
{ 4, 5, [](auto i, auto j) { return T(2*i + j*j*j - 42); }, 1, 2, 3, 2 },
{ 4, 5, [](auto i, auto j) { return T(std::tan(i*i*j)); }, 0, 1, 2, 1 },
{ 4, 5, [](auto i, auto j) { return T((i*i + j*j) / 6); }, 2, 0, 0, 0 }
};
for (auto const& matrix_case : cases) {
@ -241,26 +240,26 @@ TTS_CASE_TPL("Check all static block extractions", rotgen::tests::types)
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value, 1>;
test_static_block_extraction<mat_t, T, 1, 2>(
rotgen::tests::static_matrix_block_test_case<mat_t, 1, 2>{
11, 11,
[](std::size_t i, std::size_t j) { return T(i*i*i + 3*j - 127); },
3, 2
rotgen::tests::static_matrix_block_test_case<mat_t, 1, 2>{
11, 11,
[](rotgen::Index i, rotgen::Index j) { return T(i*i*i + 3*j - 127); },
3, 2
}
);
test_static_block_extraction<mat_t, double, 4, 3>(
rotgen::tests::static_matrix_block_test_case<mat_t, 4, 3>{
14, 15,
[](std::size_t i, std::size_t j) { return T(std::cos(i * j * 2)); },
5, 1
rotgen::tests::static_matrix_block_test_case<mat_t, 4, 3>{
14, 15,
[](rotgen::Index i, rotgen::Index j) { return T(std::cos(i * j * 2)); },
5, 1
}
);
test_static_block_extraction<mat_t, double, 0, 0>(
rotgen::tests::static_matrix_block_test_case<mat_t, 0, 0>{
5, 5,
[](std::size_t i, std::size_t j) { return T((i + j) % 9); },
0, 0
rotgen::tests::static_matrix_block_test_case<mat_t, 0, 0>{
5, 5,
[](rotgen::Index i, rotgen::Index j) { return T((i + j) % 9); },
0, 0
}
);
};