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,9 +6,7 @@
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/block.hpp>
#include <rotgen/matrix.hpp>
#include <rotgen/extract.hpp>
#include <rotgen/rotgen.hpp>
#include <Eigen/Dense>
template<typename Type1, typename Type2>
@ -16,8 +14,8 @@ void test_comparison(const Type1& t1, const Type2& t2)
{
TTS_EQUAL(static_cast<std::ptrdiff_t>(t1.rows()), static_cast<std::ptrdiff_t>(t2.rows()));
TTS_EQUAL(static_cast<std::ptrdiff_t>(t1.cols()), static_cast<std::ptrdiff_t>(t2.cols()));
for (std::size_t r = 0; r < static_cast<std::size_t>(t1.rows()); ++r)
for (std::size_t c = 0; c < static_cast<std::size_t>(t1.cols()); ++c)
for (rotgen::Index r = 0; r < static_cast<rotgen::Index>(t1.rows()); ++r)
for (rotgen::Index c = 0; c < static_cast<rotgen::Index>(t1.cols()); ++c)
TTS_EQUAL(t1(r, c), t2(r, c));
}
@ -25,6 +23,10 @@ template<typename Matrix1, typename Matrix2, typename Block1, typename Block2>
void test_block_unary_ops(const Matrix1& original_matrix, const Matrix2& ref_matrix,
Block1 original_block, Block2 ref_block)
{
TTS_EXPECT(verify_rotgen_reentrance(original_block.transpose()));
TTS_EXPECT(verify_rotgen_reentrance(original_block.conjugate()));
TTS_EXPECT(verify_rotgen_reentrance(original_block.adjoint()));
test_comparison(original_block.transpose(), ref_block.transpose());
test_comparison(original_block.conjugate(), ref_block.conjugate());
test_comparison(original_block.adjoint(), ref_block.adjoint());
@ -72,8 +74,8 @@ void test_dynamic_block_reductions(rotgen::tests::matrix_block_test_case<MatrixT
MatrixType original(matrix_construct.rows, matrix_construct.cols);
EigenMatrix ref(matrix_construct.rows, matrix_construct.cols);
for (std::size_t r = 0; r < matrix_construct.rows; ++r)
for (std::size_t c = 0; c < matrix_construct.cols; ++c)
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
ref(r, c) = original(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
std::vector<std::pair<rotgen::block<MatrixType>, Eigen::Block<EigenMatrix>>> test_cases {
@ -113,17 +115,17 @@ TTS_CASE_TPL("Test dynamic block reductions", rotgen::tests::types)
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> test_cases =
{
{6, 5, [](auto r, auto c) { return T(r + c); }, 1, 2, 3, 2},
{9, 11, [](auto r, auto c) {return T(r + c); }, 0, 1, 4, 9},
{3, 3, [](auto , auto ) {return T(0.0); }, 1, 1, 1, 1},
{1, 4, [](auto r, auto c) {return T(-r -c*c - 1234); }, 0, 0, 1, 1},
{9, 9, [](auto r, auto c) {return T(-r + 2*c); }, 0, 1, 3, 3},
{11, 13, [](auto r, auto c) {return T(std::tan(r+c)); }, 1, 1, 2, 2},
{4, 1, [](auto , auto ) {return T(7.0); }, 2, 0, 2, 1},
{1, 1, [](auto , auto ) {return T(42.0); }, 0, 0, 1, 1},
{12, 13, [](auto r, auto c) {return T(std::sin(r + c)); }, 2, 3, 4, 5 },
{4, 9, [](auto r, auto c) {return T(-1.5 * r + 2.56 * c); }, 0, 1, 2, 3 },
{2, 5, [](auto r, auto c) {return T(r == c ? 1.0 : 0.0); }, 1, 1, 1, 1},
{6, 5, [](rotgen::Index r, rotgen::Index c) { return T(r + c); }, 1, 2, 3, 2},
{9, 11, [](rotgen::Index r, rotgen::Index c) {return T(r + c); }, 0, 1, 4, 9},
{3, 3, [](rotgen::Index , rotgen::Index ) {return T(0.0); }, 1, 1, 1, 1},
{1, 4, [](rotgen::Index r, rotgen::Index c) {return T(-r -c*c - 1234); }, 0, 0, 1, 1},
{9, 9, [](rotgen::Index r, rotgen::Index c) {return T(-r + 2*c); }, 0, 1, 3, 3},
{11, 13, [](rotgen::Index r, rotgen::Index c) {return T(std::tan(r+c)); }, 1, 1, 2, 2},
{4, 1, [](rotgen::Index , rotgen::Index ) {return T(7.0); }, 2, 0, 2, 1},
{1, 1, [](rotgen::Index , rotgen::Index ) {return T(42.0); }, 0, 0, 1, 1},
{12, 13, [](rotgen::Index r, rotgen::Index c) {return T(std::sin(r + c)); }, 2, 3, 4, 5 },
{4, 9, [](rotgen::Index r, rotgen::Index c) {return T(-1.5 * r + 2.56 * c); }, 0, 1, 2, 3 },
{2, 5, [](rotgen::Index r, rotgen::Index c) {return T(r == c ? 1.0 : 0.0); }, 1, 1, 1, 1},
};
for (const auto& test_case : test_cases)