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,8 +6,7 @@
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/matrix.hpp>
#include <rotgen/extract.hpp>
#include <rotgen/rotgen.hpp>
#include <Eigen/Dense>
template <typename MatrixType, typename T>
@ -21,9 +20,11 @@ void test_block_matrix_operations(rotgen::tests::matrix_block_test_case<MatrixTy
EigenMatrix ref_a(matrix_construct.rows, matrix_construct.cols);
EigenMatrix ref_b(matrix_construct.rows, matrix_construct.cols);
for (std::size_t r = 0; r < matrix_construct.rows; ++r)
TTS_EXPECT(verify_rotgen_reentrance(ops(a,b)));
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
{
for (std::size_t c = 0; c < matrix_construct.cols; ++c)
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
{
ref_a(r,c) = a(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
ref_b(r,c) = b(r,c) = static_cast<T>(b_init_fn(r, c));
@ -42,20 +43,20 @@ void test_block_matrix_operations(rotgen::tests::matrix_block_test_case<MatrixTy
auto result_block = ops(a_block, b_block);
auto ref_result_block = ops(ref_a_block, ref_b_block);
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
TTS_EQUAL(result_block(r, c), ref_result_block(r, c));
self_ops(a_block,b_block);
self_ops(ref_a_block, ref_b_block);
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
for (std::size_t r = 0; r < matrix_construct.rows; ++r)
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
{
for (std::size_t c = 0; c < matrix_construct.cols; ++c)
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
{
TTS_EQUAL(a(r, c), ref_a(r, c));
TTS_EQUAL(b(r, c), ref_b(r, c));
@ -72,8 +73,10 @@ void test_block_scalar_operations(rotgen::tests::matrix_block_test_case<MatrixTy
MatrixType a(matrix_construct.rows, matrix_construct.cols);
EigenMatrix ref_a(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)
TTS_EXPECT(verify_rotgen_reentrance(ops(a,scalar)));
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
ref_a(r,c) = a(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
auto a_block = rotgen::extract(a, matrix_construct.i0, matrix_construct.j0,
@ -84,19 +87,19 @@ void test_block_scalar_operations(rotgen::tests::matrix_block_test_case<MatrixTy
auto result = ops(a_block, scalar);
auto ref_result = ops(ref_a_block, scalar);
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
TTS_EQUAL(result(r, c), ref_result(r, c));
self_ops(a_block,scalar);
self_ops(ref_a_block, scalar);
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
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)
TTS_EQUAL(a(r, c), ref_a(r, c));
}
@ -109,8 +112,11 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
MatrixType a(matrix_construct.rows, matrix_construct.cols);
EigenMatrix ref_a(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)
TTS_EXPECT(verify_rotgen_reentrance(a * scalar));
TTS_EXPECT(verify_rotgen_reentrance(scalar * a));
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
ref_a(r,c) = a(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
auto a_block = rotgen::extract(a, matrix_construct.i0, matrix_construct.j0,
@ -123,9 +129,9 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
auto a_scalar_multiplication_ref = ref_a_block * scalar;
auto scalar_a_multiplication_ref = scalar * ref_a_block;
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
{
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
{
TTS_EQUAL(a_scalar_multiplication (r, c), a_scalar_multiplication_ref(r, c));
TTS_EQUAL(scalar_a_multiplication(r, c), scalar_a_multiplication_ref(r, c));
@ -135,12 +141,12 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
a_block *= scalar;
ref_a_block *= scalar;
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
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)
TTS_EQUAL(a(r, c), ref_a(r, c));
}
@ -155,12 +161,12 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case<MatrixType>
EigenMatrix ref_a(a_matrix_construct.rows, a_matrix_construct.cols);
EigenMatrix ref_b(b_matrix_construct.rows, b_matrix_construct.cols);
for (std::size_t r = 0; r < a_matrix_construct.rows; ++r)
for (std::size_t c = 0; c < a_matrix_construct.cols; ++c)
for (rotgen::Index r = 0; r < a_matrix_construct.rows; ++r)
for (rotgen::Index c = 0; c < a_matrix_construct.cols; ++c)
ref_a(r,c) = a(r,c) = static_cast<T>(a_matrix_construct.init_fn(r, c));
for (std::size_t r = 0; r < b_matrix_construct.rows; ++r)
for (std::size_t c = 0; c < b_matrix_construct.cols; ++c)
for (rotgen::Index r = 0; r < b_matrix_construct.rows; ++r)
for (rotgen::Index c = 0; c < b_matrix_construct.cols; ++c)
ref_b(r,c) = b(r,c) = static_cast<T>(b_matrix_construct.init_fn(r, c));
@ -173,26 +179,28 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case<MatrixType>
auto ref_b_block = ref_b.block(b_matrix_construct.i0, b_matrix_construct.j0,
b_matrix_construct.ni, b_matrix_construct.nj);
TTS_EXPECT(verify_rotgen_reentrance(a_block * b_block));
auto a_b_product_original = a_block * b_block;
auto a_b_product_ref = ref_a_block * ref_b_block;
for (std::size_t r = 0; r < a_matrix_construct.ni; ++r)
for (std::size_t c = 0; c < a_matrix_construct.nj; ++c)
for (rotgen::Index r = 0; r < a_matrix_construct.ni; ++r)
for (rotgen::Index c = 0; c < a_matrix_construct.nj; ++c)
TTS_EQUAL(a_b_product_original (r, c), a_b_product_ref(r, c));
a_block *= b_block;
ref_a_block *= ref_b_block;
for (std::size_t r = 0; r < a_matrix_construct.ni; ++r)
for (std::size_t c = 0; c < a_matrix_construct.nj; ++c)
for (rotgen::Index r = 0; r < a_matrix_construct.ni; ++r)
for (rotgen::Index c = 0; c < a_matrix_construct.nj; ++c)
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
for (std::size_t r = 0; r < a_matrix_construct.rows; ++r)
for (std::size_t c = 0; c < a_matrix_construct.cols; ++c)
for (rotgen::Index r = 0; r < a_matrix_construct.rows; ++r)
for (rotgen::Index c = 0; c < a_matrix_construct.cols; ++c)
TTS_EQUAL(a(r, c), ref_a(r, c));
for (std::size_t r = 0; r < b_matrix_construct.rows; ++r)
for (std::size_t c = 0; c < b_matrix_construct.cols; ++c)
for (rotgen::Index r = 0; r < b_matrix_construct.rows; ++r)
for (rotgen::Index c = 0; c < b_matrix_construct.cols; ++c)
TTS_EQUAL(b(r, c), ref_b(r, c));
}
@ -244,7 +252,7 @@ TTS_CASE_TPL("Check block multiplications", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
{
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
auto init_id = [](auto r, auto c) { return r == c ? 1 : 0; };
auto init_id = [](rotgen::Index r, rotgen::Index c) { return r == c ? 1 : 0; };
test_block_multiplication<mat_t, T>({1 , 1, init_a, 0, 0, 1, 1}, {1 , 1, init_b, 0, 0, 1, 1});
test_block_multiplication<mat_t, T>({13 , 15, init_b, 1, 2, 4, 4}, {13 , 15, init_b, 0, 1, 4, 4});