Resolve "[API-#2] Pseudo-privatization of rotgen entity member functions"

Closes #18

Co-authored-by: Jules Pénuchot <jules@penuchot.com>

See merge request oss/rotgen!50
This commit is contained in:
Jules Pénuchot 2025-12-17 20:48:00 +01:00 committed by Joel Falcou
parent 6489697c05
commit e151e136d6
52 changed files with 2212 additions and 1556 deletions

View file

@ -9,8 +9,9 @@
#include "unit/tests.hpp"
TTS_CASE_TPL("Function size", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
TTS_CASE_TPL("Function size", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> empty_matrix;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix(3, 4);
@ -25,87 +26,87 @@ TTS_CASE_TPL("Function size", rotgen::tests::types)<typename T, typename O>(
TTS_EQUAL(column_vector.size(), rotgen::Index{5});
};
TTS_CASE_TPL("Resizing dynamic matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
TTS_CASE_TPL("Resizing dynamic matrix", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(2, 3);
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = 42 + 2 * c + r;
for (rotgen::Index r = 0; r < rows(a); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = 42 + 2 * c + r;
rotgen::resize(a, 3, 2);
TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(rows(a), rotgen::Index(3));
TTS_EQUAL(cols(a), rotgen::Index(2));
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_GREATER(a(r, c), 0);
for (rotgen::Index r = 0; r < rows(a); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) TTS_GREATER(a(r, c), 0);
rotgen::resize(a, 2, 2);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(rows(a), rotgen::Index(2));
TTS_EQUAL(cols(a), rotgen::Index(2));
};
TTS_CASE_TPL("Dynamix matrix conservative resizing",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(2, 3);
int i = 1;
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = i++;
for (rotgen::Index r = 0; r < rows(a); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = i++;
rotgen::conservativeResize(a, 2, 3);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), rotgen::Index(3));
TTS_EQUAL(rows(a), rotgen::Index(2));
TTS_EQUAL(cols(a), rotgen::Index(3));
i = 1;
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_EQUAL(a(r, c), i++);
for (rotgen::Index r = 0; r < rows(a); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) TTS_EQUAL(a(r, c), i++);
rotgen::conservativeResize(a, 3, 2);
TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(rows(a), rotgen::Index(3));
TTS_EQUAL(cols(a), rotgen::Index(2));
int expected[3][2] = {{1, 2}, {4, 5}};
for (rotgen::Index r = 0; r < 2; ++r)
for (rotgen::Index c = 0; c < 2; ++c) TTS_EQUAL(a(r, c), expected[r][c]);
rotgen::conservativeResize(a, 4, 4);
TTS_EQUAL(a.rows(), rotgen::Index(4));
TTS_EQUAL(a.cols(), rotgen::Index(4));
TTS_EQUAL(rows(a), rotgen::Index(4));
TTS_EQUAL(cols(a), rotgen::Index(4));
TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(3, 3), 0);
rotgen::conservativeResize(a, 2, 2);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(rows(a), rotgen::Index(2));
TTS_EQUAL(cols(a), rotgen::Index(2));
TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(1, 1), 5);
rotgen::conservativeResize(a, 1, 2);
TTS_EQUAL(a.rows(), rotgen::Index(1));
TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(rows(a), rotgen::Index(1));
TTS_EQUAL(cols(a), rotgen::Index(2));
TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(0, 1), 2);
rotgen::conservativeResize(a, 0, 0);
TTS_EQUAL(a.rows(), rotgen::Index(0));
TTS_EQUAL(a.cols(), rotgen::Index(0));
TTS_EQUAL(rows(a), rotgen::Index(0));
TTS_EQUAL(cols(a), rotgen::Index(0));
rotgen::conservativeResize(a, 3, 3);
TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(a.cols(), rotgen::Index(3));
TTS_EQUAL(rows(a), rotgen::Index(3));
TTS_EQUAL(cols(a), rotgen::Index(3));
};
TTS_CASE_TPL("Test coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(3, 5);
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = r + 2 * c + 3;
for (rotgen::Index r = 0; r < rows(a); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = r + 2 * c + 3;
TTS_EQUAL(a(0, 0), 3);
TTS_EQUAL(a(1, 1), 6);
@ -121,9 +122,9 @@ TTS_CASE_TPL("Test coefficient accessors",
TTS_EQUAL(a(2, 2), 17);
};
TTS_CASE_TPL("Test one index coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
auto a = [&]() {
if constexpr (O::value == rotgen::ColMajor)