Adding clang-format configuration file and formatting all source files

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

See merge request oss/rotgen!41
This commit is contained in:
Jules Pénuchot 2025-10-14 16:19:03 +02:00
parent e92e824a18
commit 648dd768ee
94 changed files with 6778 additions and 4722 deletions

View file

@ -9,88 +9,90 @@
#include "unit/common/arithmetic.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic matrix transposition-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic matrix transposition-like operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> input(rows, cols);
rotgen::tests::prepare(rows,cols,fn,input);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> input(rows,
cols);
rotgen::tests::prepare(rows, cols, fn, input);
rotgen::tests::check_shape_functions(input);
}
};
TTS_CASE_TPL("Test static matrix transposition-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static matrix transposition-like operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = []<typename D>(D const& desc)
{
rotgen::matrix<T,D::rows,D::cols,O::value> input;
rotgen::tests::prepare(input.rows(),input.cols(),desc.init_fn,input);
auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, D::rows, D::cols, O::value> input;
rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input);
rotgen::tests::check_shape_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};
TTS_CASE_TPL("Test dynamic matrix reduction-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic matrix reduction-like operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> input(rows, cols);
rotgen::tests::prepare(rows,cols,fn,input);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> input(rows,
cols);
rotgen::tests::prepare(rows, cols, fn, input);
rotgen::tests::check_reduction_functions(input);
}
};
TTS_CASE_TPL("Test static matrix reduction-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static matrix reduction-like operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = []<typename D>(D const& desc)
{
rotgen::matrix<T,D::rows,D::cols,O::value> input;
rotgen::tests::prepare(input.rows(),input.cols(),desc.init_fn,input);
auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, D::rows, D::cols, O::value> input;
rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input);
rotgen::tests::check_reduction_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};
TTS_CASE_TPL("Test dot product", float, double)
<typename T>( tts::type<T> )
TTS_CASE_TPL("Test dot product", float, double)<typename T>(tts::type<T>){
{auto a = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 8, 2);
auto b = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 8, 2);
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
{
auto a = rotgen::setConstant<rotgen::matrix<T,1,rotgen::Dynamic>>(1,8,2);
auto b = rotgen::setConstant<rotgen::matrix<T,1,rotgen::Dynamic>>(1,8,2);
auto a = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(8, 1, 2);
auto b = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(8, 1, 2);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
auto a = rotgen::setConstant<rotgen::matrix<T,rotgen::Dynamic,1>>(8,1,2);
auto b = rotgen::setConstant<rotgen::matrix<T,rotgen::Dynamic,1>>(8,1,2);
{
auto a = rotgen::setConstant<rotgen::matrix<T, 1, 8>>(2);
auto b = rotgen::setConstant<rotgen::matrix<T, 1, 8>>(2);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
auto a = rotgen::setConstant<rotgen::matrix<T,1,8>>(2);
auto b = rotgen::setConstant<rotgen::matrix<T,1,8>>(2);
{
auto a = rotgen::setConstant<rotgen::matrix<T, 8, 1>>(2);
auto b = rotgen::setConstant<rotgen::matrix<T, 8, 1>>(2);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
{
auto a = rotgen::setConstant<rotgen::matrix<T,8,1>>(2);
auto b = rotgen::setConstant<rotgen::matrix<T,8,1>>(2);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
};
TTS_EQUAL(rotgen::dot(a, b), 32);
}
}
;

View file

@ -8,13 +8,15 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.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);
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> row_vector(9,1);
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> column_vector(1,5);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> empty_matrix;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix(3, 4);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> row_vector(9,
1);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> column_vector(
1, 5);
TTS_EQUAL(empty_matrix.size(), rotgen::Index{0});
TTS_EQUAL(matrix.size(), rotgen::Index{12});
@ -22,72 +24,69 @@ TTS_CASE_TPL("Function size", rotgen::tests::types)
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);
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 < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = 42 + 2 * c + r;
a.resize(3, 2);
TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(a.cols(), 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 < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_GREATER(a(r, c), 0);
a.resize(2,2);
a.resize(2, 2);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), 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);
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 < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = i++;
a.conservativeResize(2, 3);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), 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 < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_EQUAL(a(r, c), i++);
a.conservativeResize(3, 2);
TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(a.cols(), 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]);
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]);
a.conservativeResize(4, 4);
TTS_EQUAL(a.rows(), rotgen::Index(4));
TTS_EQUAL(a.cols(), rotgen::Index(4));
TTS_EQUAL(a(0,0), 1);
TTS_EQUAL(a(3,3), 0);
TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(3, 3), 0);
a.conservativeResize(2, 2);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(a(0,0), 1);
TTS_EQUAL(a(1,1), 5);
TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(1, 1), 5);
a.conservativeResize(1, 2);
TTS_EQUAL(a.rows(), rotgen::Index(1));
TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(a(0,0), 1);
TTS_EQUAL(a(0,1), 2);
TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(0, 1), 2);
a.conservativeResize(0, 0);
TTS_EQUAL(a.rows(), rotgen::Index(0));
@ -98,50 +97,48 @@ TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types)
TTS_EQUAL(a.cols(), 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);
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 < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = r + 2 * c + 3;
TTS_EQUAL(a(0,0), 3);
TTS_EQUAL(a(1,1), 6);
TTS_EQUAL(a(1,0), 4);
TTS_EQUAL(a(2,2), 9);
TTS_EQUAL(a(2,4), 13);
TTS_EQUAL(a(0, 0), 3);
TTS_EQUAL(a(1, 1), 6);
TTS_EQUAL(a(1, 0), 4);
TTS_EQUAL(a(2, 2), 9);
TTS_EQUAL(a(2, 4), 13);
a(1, 1) = 42;
TTS_EQUAL(a(1,1), 42);
TTS_EQUAL(a(1, 1), 42);
T& ref = a(2, 2);
ref = 17;
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) return rotgen::matrix<T,1,rotgen::Dynamic>(1,8);
else return rotgen::matrix<T,rotgen::Dynamic,1>(8,1);
auto a = [&]() {
if constexpr (O::value == rotgen::ColMajor)
return rotgen::matrix<T, 1, rotgen::Dynamic>(1, 8);
else return rotgen::matrix<T, rotgen::Dynamic, 1>(8, 1);
}();
TTS_EXPECT(a.IsVectorAtCompileTime);
for(rotgen::Index s=0;s<a.size();++s)
a(s) = s+1;
for (rotgen::Index s = 0; s < a.size(); ++s) a(s) = s + 1;
int i = 1;
for(rotgen::Index s=0;s<a.size();++s)
TTS_EQUAL(a(s), i++) << a;
for (rotgen::Index s = 0; s < a.size(); ++s) TTS_EQUAL(a(s), i++) << a;
i = 1;
for(rotgen::Index s=0;s<a.size();++s)
TTS_EQUAL(a[s], i++) << a;
for (rotgen::Index s = 0; s < a.size(); ++s) TTS_EQUAL(a[s], i++) << a;
T& ref = a(2);
ref = 999.5;
@ -150,4 +147,4 @@ TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types)
T& bref = a[3];
bref = 42.5;
TTS_EQUAL(a[3], 42.5);
};
};

View file

@ -8,38 +8,42 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Default matrix dynamic constructor", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Default matrix dynamic constructor",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> matrix;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix;
TTS_EQUAL(matrix.rows(), rotgen::Index{0});
TTS_EQUAL(matrix.cols(), rotgen::Index{0});
};
TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Default matrix static constructor",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,4,9,O::value> matrix;
rotgen::matrix<T, 4, 9, O::value> matrix;
TTS_EQUAL(matrix.rows(), rotgen::Index{4});
TTS_EQUAL(matrix.cols(), rotgen::Index{9});
};
TTS_CASE_TPL("Dynamic matrix constructor with row and columns", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Dynamic matrix constructor with row and columns",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> matrix(10, 5);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix(10, 5);
TTS_EQUAL(matrix.rows(), rotgen::Index{10});
TTS_EQUAL(matrix.cols(), rotgen::Index{5});
};
TTS_CASE_TPL("Static matrix constructor with row and columns", float, double)
<typename T>( tts::type<T> )
TTS_CASE_TPL("Static matrix constructor with row and columns",
float,
double)<typename T>(tts::type<T>)
{
rotgen::matrix<T,1,2> v2(6, 11);
rotgen::matrix<T,2,1> w2(6, 11);
rotgen::matrix<T, 1, 2> v2(6, 11);
rotgen::matrix<T, 2, 1> w2(6, 11);
TTS_EQUAL(v2(0), T{6});
TTS_EQUAL(v2(1), T{11});
@ -47,8 +51,8 @@ TTS_CASE_TPL("Static matrix constructor with row and columns", float, double)
TTS_EQUAL(w2(0), T{6});
TTS_EQUAL(w2(1), T{11});
rotgen::matrix<T,1,3> v3(6, 11, 125);
rotgen::matrix<T,3,1> w3(6, 11, 125);
rotgen::matrix<T, 1, 3> v3(6, 11, 125);
rotgen::matrix<T, 3, 1> w3(6, 11, 125);
TTS_EQUAL(v3(0), T{6});
TTS_EQUAL(v3(1), T{11});
@ -59,52 +63,54 @@ TTS_CASE_TPL("Static matrix constructor with row and columns", float, double)
TTS_EQUAL(w3(2), T{125});
};
TTS_CASE_TPL("Copy constructor produces identical but independent matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor produces identical but independent matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(3, 3);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(3, 3);
for(rotgen::Index r=0;r<a.rows();r++)
for(rotgen::Index c=0;c<a.cols();c++)
a(r,c) = r + c;
for (rotgen::Index r = 0; r < a.rows(); r++)
for (rotgen::Index c = 0; c < a.cols(); c++) a(r, c) = r + c;
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a;
TTS_EQUAL(b.rows(), a.rows());
TTS_EQUAL(b.cols(), a.cols());
for(rotgen::Index r=0;r<a.rows();r++)
for(rotgen::Index c=0;c<a.cols();c++)
TTS_EQUAL(b(r,c), a(r,c));
for (rotgen::Index r = 0; r < a.rows(); r++)
for (rotgen::Index c = 0; c < a.cols(); c++) TTS_EQUAL(b(r, c), a(r, c));
TTS_EQUAL(b(0, 0), 0.0);
TTS_EQUAL(b(1, 0), 1.0);
TTS_EQUAL(b(2, 1), 3.0);
a(0,0) = 42.0;
TTS_NOT_EQUAL(b(0,0), a(0,0));
a(0, 0) = 42.0;
TTS_NOT_EQUAL(b(0, 0), a(0, 0));
};
TTS_CASE_TPL("Copy constructor on default matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor on default matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a;
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a;
TTS_EQUAL(b.rows(), rotgen::Index{0});
TTS_EQUAL(b.cols(), rotgen::Index{0});
};
TTS_CASE_TPL("Copy constructor from const matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor from const matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
const rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 2);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> const a(2, 2);
auto b = a;
TTS_EQUAL(b.rows(), rotgen::Index{2});
TTS_EQUAL(b.cols(), rotgen::Index{2});
};
TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor on static matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T, 2, 5> a;
rotgen::matrix<T, 2, 5> b = a;
@ -112,93 +118,100 @@ TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types)
TTS_EQUAL(b.cols(), rotgen::Index{5});
};
TTS_CASE_TPL("Copy constructor on static/dynamic matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor on static/dynamic matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T, 11, 4,O::value> a;
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = a;
rotgen::matrix<T, 11, 4, O::value> a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a;
TTS_EQUAL(b.rows(), 11);
TTS_EQUAL(b.cols(), 4);
};
TTS_CASE_TPL("Copy constructor on dynamic/static matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor on dynamic/static matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(5, 7);
rotgen::matrix<T, 5, 7,O::value> b = a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(5, 7);
rotgen::matrix<T, 5, 7, O::value> b = a;
TTS_EQUAL(b.rows(), 5);
TTS_EQUAL(b.cols(), 7);
};
TTS_CASE_TPL("Move constructor transfers contents", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Move constructor transfers contents",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(3, 3);
a(1,1) = 7;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(3, 3);
a(1, 1) = 7;
auto ptr = a.data();
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = std::move(a);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b =
std::move(a);
TTS_EQUAL(b(1,1), 7);
TTS_EQUAL(b(1, 1), 7);
TTS_EQUAL(b.rows(), rotgen::Index{3});
TTS_EQUAL(b.cols(), rotgen::Index{3});
TTS_EXPECT(b.data() == ptr);
};
TTS_CASE_TPL("Move constructor from Rvalue", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Move constructor from Rvalue",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>(2, 2);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b =
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>(2, 2);
TTS_EQUAL(b.rows(), rotgen::Index{2});
TTS_EQUAL(b.cols(), rotgen::Index{2});
};
TTS_CASE_TPL("Constructor from Initializer list", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Constructor from Initializer list",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,1,1,O::value> b1{3.5};
rotgen::matrix<T, 1, 1, O::value> b1{3.5};
TTS_EQUAL(b1.rows(), rotgen::Index{1});
TTS_EQUAL(b1.cols(), rotgen::Index{1});
TTS_EQUAL(b1(0) , 3.5);
TTS_EQUAL(b1(0), 3.5);
rotgen::matrix<T,5,1,rotgen::ColMajor> b9{0.25, 0.5, 1, 2, 4};
rotgen::matrix<T, 5, 1, rotgen::ColMajor> b9{0.25, 0.5, 1, 2, 4};
TTS_EQUAL(b9.rows(), rotgen::Index{5});
TTS_EQUAL(b9.cols(), rotgen::Index{1});
T i = 0.25;
for(rotgen::Index r=0;r<b9.rows();++r)
for (rotgen::Index r = 0; r < b9.rows(); ++r)
{
TTS_EQUAL(b9(r,0), i);
TTS_EQUAL(b9(r, 0), i);
i *= 2;
}
rotgen::matrix<T,1,3,rotgen::RowMajor> b13{1.2,2.3,3.4};
rotgen::matrix<T, 1, 3, rotgen::RowMajor> b13{1.2, 2.3, 3.4};
TTS_EQUAL(b13.rows(), rotgen::Index{1});
TTS_EQUAL(b13.cols(), rotgen::Index{3});
TTS_EQUAL(b13(0) , T(1.2));
TTS_EQUAL(b13(1) , T(2.3));
TTS_EQUAL(b13(2) , T(3.4));
TTS_EQUAL(b13(0), T(1.2));
TTS_EQUAL(b13(1), T(2.3));
TTS_EQUAL(b13(2), T(3.4));
};
TTS_CASE_TPL("Constructor from Initializer list of rows", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Constructor from Initializer list of rows",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b1{{3.5}};
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b1{{3.5}};
TTS_EQUAL(b1.rows(), rotgen::Index{1});
TTS_EQUAL(b1.cols(), rotgen::Index{1});
TTS_EQUAL(b1(0,0) , T(3.5));
TTS_EQUAL(b1(0, 0), T(3.5));
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>
b23 { {1.2,2.3,3.4}
, {10,200,3000}
};
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b23{
{1.2, 2.3, 3.4},
{10, 200, 3000}};
TTS_EQUAL(b23.rows(), rotgen::Index{2});
TTS_EQUAL(b23.cols(), rotgen::Index{3});
TTS_EQUAL(b23(0,0) , T(1.2));
TTS_EQUAL(b23(0,1) , T(2.3));
TTS_EQUAL(b23(0,2) , T(3.4));
TTS_EQUAL(b23(1,0) , T(10));
TTS_EQUAL(b23(1,1) , T(200));
TTS_EQUAL(b23(1,2) , T(3000));
};
TTS_EQUAL(b23(0, 0), T(1.2));
TTS_EQUAL(b23(0, 1), T(2.3));
TTS_EQUAL(b23(0, 2), T(3.4));
TTS_EQUAL(b23(1, 0), T(10));
TTS_EQUAL(b23(1, 1), T(200));
TTS_EQUAL(b23(1, 2), T(3000));
};

View file

@ -9,29 +9,31 @@
#include "unit/common/cwise.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic matrix cwise operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic matrix cwise operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> input(rows, cols);
rotgen::tests::prepare(rows,cols,fn,input);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> input(rows,
cols);
rotgen::tests::prepare(rows, cols, fn, input);
rotgen::tests::check_cwise_functions(input);
}
};
TTS_CASE_TPL("Test static matrix cwise operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static matrix cwise operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = []<typename D>(D const& desc)
{
rotgen::matrix<T,D::rows,D::cols,O::value> input;
rotgen::tests::prepare(input.rows(),input.cols(),desc.init_fn,input);
auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, D::rows, D::cols, O::value> input;
rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input);
rotgen::tests::check_cwise_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
};
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -8,134 +8,141 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
void test_value(const auto& matrix, std::size_t rows, std::size_t cols, auto constant)
void test_value(auto const& matrix,
std::size_t rows,
std::size_t cols,
auto constant)
{
TTS_EXPECT(verify_rotgen_reentrance(matrix));
for(std::size_t r=0;r<rows;++r)
for(std::size_t c=0;c<cols;++c)
TTS_EQUAL(matrix(r, c), constant);
for (std::size_t r = 0; r < rows; ++r)
for (std::size_t c = 0; c < cols; ++c) TTS_EQUAL(matrix(r, c), constant);
}
void test_random(const auto& matrix, std::size_t rows, std::size_t cols)
void test_random(auto const& matrix, std::size_t rows, std::size_t cols)
{
TTS_EXPECT(verify_rotgen_reentrance(matrix));
for(std::size_t r=0;r<rows;++r)
for(std::size_t c=0;c<cols;++c)
for (std::size_t r = 0; r < rows; ++r)
for (std::size_t c = 0; c < cols; ++c)
{
TTS_GREATER_EQUAL(matrix(r, c), -1.0);
TTS_LESS_EQUAL(matrix(r, c), 1.0);
}
}
void test_identity(const auto& matrix, std::size_t rows, std::size_t cols)
void test_identity(auto const& matrix, std::size_t rows, std::size_t cols)
{
TTS_EXPECT(verify_rotgen_reentrance(matrix));
for(std::size_t r=0;r<rows;++r)
for(std::size_t c=0;c<cols;++c)
TTS_EQUAL(matrix(r, c), r==c ? 1 : 0);
for (std::size_t r = 0; r < rows; ++r)
for (std::size_t c = 0; c < cols; ++c)
TTS_EQUAL(matrix(r, c), r == c ? 1 : 0);
}
TTS_CASE_TPL("Test zero", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test zero", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using namespace rotgen;
test_value(setZero<matrix<T, 3, 4, O::value> >(), 3, 4, 0);
test_value(setZero<matrix<T, 1, 1, O::value> >(), 1, 1, 0);
test_value(setZero<matrix<T, 10, 10, O::value> >(), 10, 10, 0);
test_value(setZero<matrix<T,Dynamic,Dynamic, O::value>>(3, 4), 3, 4, 0);
test_value(setZero<matrix<T, 7, 5, O::value> >(7, 5), 7, 5, 0);
test_value(setZero<matrix<T, 9,Dynamic> >(9, 3), 9, 3, 0);
test_value(setZero<matrix<T,Dynamic, 3> >(2, 3), 2, 3, 0);
test_value(setZero<matrix<T, 3, 4, O::value>>(), 3, 4, 0);
test_value(setZero<matrix<T, 1, 1, O::value>>(), 1, 1, 0);
test_value(setZero<matrix<T, 10, 10, O::value>>(), 10, 10, 0);
test_value(setZero<matrix<T, Dynamic, Dynamic, O::value>>(3, 4), 3, 4, 0);
test_value(setZero<matrix<T, 7, 5, O::value>>(7, 5), 7, 5, 0);
test_value(setZero<matrix<T, 9, Dynamic>>(9, 3), 9, 3, 0);
test_value(setZero<matrix<T, Dynamic, 3>>(2, 3), 2, 3, 0);
test_value(setZero(matrix<T, 3, 4, O::value>{} ), 3, 4, 0);
test_value(setZero(matrix<T, 1, 1, O::value>{} ), 1, 1, 0);
test_value(setZero(matrix<T, 10, 10, O::value>{} ), 10, 10, 0);
test_value(setZero(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4, 0);
test_value(setZero(matrix<T, 7, 5, O::value>{} ), 7, 5, 0);
test_value(setZero(matrix<T, 9,Dynamic>{9, 3} ), 9, 3, 0);
test_value(setZero(matrix<T,Dynamic, 3>{2, 3} ), 2, 3, 0);
test_value(setZero(matrix<T, 3, 4, O::value>{}), 3, 4, 0);
test_value(setZero(matrix<T, 1, 1, O::value>{}), 1, 1, 0);
test_value(setZero(matrix<T, 10, 10, O::value>{}), 10, 10, 0);
test_value(setZero(matrix<T, Dynamic, Dynamic, O::value>{3, 4}), 3, 4, 0);
test_value(setZero(matrix<T, 7, 5, O::value>{}), 7, 5, 0);
test_value(setZero(matrix<T, 9, Dynamic>{9, 3}), 9, 3, 0);
test_value(setZero(matrix<T, Dynamic, 3>{2, 3}), 2, 3, 0);
};
TTS_CASE_TPL("Test ones", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test ones", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using namespace rotgen;
test_value(setOnes<matrix<T, 3, 4, O::value> >(), 3, 4, 1);
test_value(setOnes<matrix<T, 1, 1, O::value> >(), 1, 1, 1);
test_value(setOnes<matrix<T, 10, 10, O::value> >(), 10, 10, 1);
test_value(setOnes<matrix<T,Dynamic,Dynamic, O::value>>(3, 4), 3, 4, 1);
test_value(setOnes<matrix<T, 7, 5, O::value> >(7, 5), 7, 5, 1);
test_value(setOnes<matrix<T, 9,Dynamic> >(9, 3), 9, 3, 1);
test_value(setOnes<matrix<T,Dynamic, 3> >(2, 3), 2, 3, 1);
test_value(setOnes<matrix<T, 3, 4, O::value>>(), 3, 4, 1);
test_value(setOnes<matrix<T, 1, 1, O::value>>(), 1, 1, 1);
test_value(setOnes<matrix<T, 10, 10, O::value>>(), 10, 10, 1);
test_value(setOnes<matrix<T, Dynamic, Dynamic, O::value>>(3, 4), 3, 4, 1);
test_value(setOnes<matrix<T, 7, 5, O::value>>(7, 5), 7, 5, 1);
test_value(setOnes<matrix<T, 9, Dynamic>>(9, 3), 9, 3, 1);
test_value(setOnes<matrix<T, Dynamic, 3>>(2, 3), 2, 3, 1);
test_value(setOnes(matrix<T, 3, 4, O::value>{} ), 3, 4, 1);
test_value(setOnes(matrix<T, 1, 1, O::value>{} ), 1, 1, 1);
test_value(setOnes(matrix<T, 10, 10, O::value>{} ), 10, 10, 1);
test_value(setOnes(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4, 1);
test_value(setOnes(matrix<T, 7, 5, O::value>{} ), 7, 5, 1);
test_value(setOnes(matrix<T, 9,Dynamic>{9, 3} ), 9, 3, 1);
test_value(setOnes(matrix<T,Dynamic, 3>{2, 3} ), 2, 3, 1);
test_value(setOnes(matrix<T, 3, 4, O::value>{}), 3, 4, 1);
test_value(setOnes(matrix<T, 1, 1, O::value>{}), 1, 1, 1);
test_value(setOnes(matrix<T, 10, 10, O::value>{}), 10, 10, 1);
test_value(setOnes(matrix<T, Dynamic, Dynamic, O::value>{3, 4}), 3, 4, 1);
test_value(setOnes(matrix<T, 7, 5, O::value>{}), 7, 5, 1);
test_value(setOnes(matrix<T, 9, Dynamic>{9, 3}), 9, 3, 1);
test_value(setOnes(matrix<T, Dynamic, 3>{2, 3}), 2, 3, 1);
};
TTS_CASE_TPL("Test constant", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test constant", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using namespace rotgen;
test_value(setConstant<matrix<T, 3, 4, O::value> >(T(5.12)), 3, 4, T(5.12));
test_value(setConstant<matrix<T, 1, 1, O::value> >(T(5.12)), 1, 1, T(5.12));
test_value(setConstant<matrix<T, 10, 10, O::value> >(T(5.12)), 10, 10, T(5.12));
test_value(setConstant<matrix<T,Dynamic,Dynamic, O::value>>(3, 4, T(5.12)), 3, 4, T(5.12));
test_value(setConstant<matrix<T, 7, 5, O::value> >(7, 5, T(5.12)), 7, 5, T(5.12));
test_value(setConstant<matrix<T, 9,Dynamic> >(9, 3, T(5.12)), 9, 3, T(5.12));
test_value(setConstant<matrix<T,Dynamic, 3> >(2, 3, T(5.12)), 2, 3, T(5.12));
test_value(setConstant<matrix<T, 3, 4, O::value>>(T(5.12)), 3, 4, T(5.12));
test_value(setConstant<matrix<T, 1, 1, O::value>>(T(5.12)), 1, 1, T(5.12));
test_value(setConstant<matrix<T, 10, 10, O::value>>(T(5.12)), 10, 10,
T(5.12));
test_value(setConstant<matrix<T, Dynamic, Dynamic, O::value>>(3, 4, T(5.12)),
3, 4, T(5.12));
test_value(setConstant<matrix<T, 7, 5, O::value>>(7, 5, T(5.12)), 7, 5,
T(5.12));
test_value(setConstant<matrix<T, 9, Dynamic>>(9, 3, T(5.12)), 9, 3, T(5.12));
test_value(setConstant<matrix<T, Dynamic, 3>>(2, 3, T(5.12)), 2, 3, T(5.12));
test_value(setConstant(matrix<T, 3, 4, O::value>{} , T(5.12)), 3, 4, T(5.12));
test_value(setConstant(matrix<T, 1, 1, O::value>{} , T(5.12)), 1, 1, T(5.12));
test_value(setConstant(matrix<T, 10, 10, O::value>{} , T(5.12)), 10, 10, T(5.12));
test_value(setConstant(matrix<T,Dynamic,Dynamic, O::value>{3, 4}, T(5.12)), 3, 4, T(5.12));
test_value(setConstant(matrix<T, 7, 5, O::value>{} , T(5.12)), 7, 5, T(5.12));
test_value(setConstant(matrix<T, 9,Dynamic>{9, 3} , T(5.12)), 9, 3, T(5.12));
test_value(setConstant(matrix<T,Dynamic, 3>{2, 3} , T(5.12)), 2, 3, T(5.12));
test_value(setConstant(matrix<T, 3, 4, O::value>{}, T(5.12)), 3, 4, T(5.12));
test_value(setConstant(matrix<T, 1, 1, O::value>{}, T(5.12)), 1, 1, T(5.12));
test_value(setConstant(matrix<T, 10, 10, O::value>{}, T(5.12)), 10, 10,
T(5.12));
test_value(setConstant(matrix<T, Dynamic, Dynamic, O::value>{3, 4}, T(5.12)),
3, 4, T(5.12));
test_value(setConstant(matrix<T, 7, 5, O::value>{}, T(5.12)), 7, 5, T(5.12));
test_value(setConstant(matrix<T, 9, Dynamic>{9, 3}, T(5.12)), 9, 3, T(5.12));
test_value(setConstant(matrix<T, Dynamic, 3>{2, 3}, T(5.12)), 2, 3, T(5.12));
};
TTS_CASE_TPL("Test random", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test random", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using namespace rotgen;
test_random(setRandom<matrix<T, 3, 4, O::value> >(), 3, 4);
test_random(setRandom<matrix<T, 1, 1, O::value> >(), 1, 1);
test_random(setRandom<matrix<T, 10, 10, O::value> >(), 10, 10);
test_random(setRandom<matrix<T,Dynamic,Dynamic, O::value>>(3, 4), 3, 4);
test_random(setRandom<matrix<T, 7, 5, O::value> >(7, 5), 7, 5);
test_random(setRandom<matrix<T, 9,Dynamic> >(9, 3), 9, 3);
test_random(setRandom<matrix<T,Dynamic, 3> >(2, 3), 2, 3);
test_random(setRandom<matrix<T, 3, 4, O::value>>(), 3, 4);
test_random(setRandom<matrix<T, 1, 1, O::value>>(), 1, 1);
test_random(setRandom<matrix<T, 10, 10, O::value>>(), 10, 10);
test_random(setRandom<matrix<T, Dynamic, Dynamic, O::value>>(3, 4), 3, 4);
test_random(setRandom<matrix<T, 7, 5, O::value>>(7, 5), 7, 5);
test_random(setRandom<matrix<T, 9, Dynamic>>(9, 3), 9, 3);
test_random(setRandom<matrix<T, Dynamic, 3>>(2, 3), 2, 3);
test_random(setRandom(matrix<T, 3, 4, O::value>{} ), 3, 4);
test_random(setRandom(matrix<T, 1, 1, O::value>{} ), 1, 1);
test_random(setRandom(matrix<T, 10, 10, O::value>{} ), 10, 10);
test_random(setRandom(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4);
test_random(setRandom(matrix<T, 7, 5, O::value>{} ), 7, 5);
test_random(setRandom(matrix<T, 9,Dynamic>{9, 3} ), 9, 3);
test_random(setRandom(matrix<T,Dynamic, 3>{2, 3} ), 2, 3);
test_random(setRandom(matrix<T, 3, 4, O::value>{}), 3, 4);
test_random(setRandom(matrix<T, 1, 1, O::value>{}), 1, 1);
test_random(setRandom(matrix<T, 10, 10, O::value>{}), 10, 10);
test_random(setRandom(matrix<T, Dynamic, Dynamic, O::value>{3, 4}), 3, 4);
test_random(setRandom(matrix<T, 7, 5, O::value>{}), 7, 5);
test_random(setRandom(matrix<T, 9, Dynamic>{9, 3}), 9, 3);
test_random(setRandom(matrix<T, Dynamic, 3>{2, 3}), 2, 3);
};
TTS_CASE_TPL("Test identity", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test identity", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using namespace rotgen;
test_identity(setIdentity<matrix<T, 3, 4, O::value> >(), 3, 4);
test_identity(setIdentity<matrix<T, 1, 1, O::value> >(), 1, 1);
test_identity(setIdentity<matrix<T, 10, 10, O::value> >(), 10, 10);
test_identity(setIdentity<matrix<T,Dynamic,Dynamic, O::value>>(3, 4), 3, 4);
test_identity(setIdentity<matrix<T, 7, 5, O::value> >(7, 5), 7, 5);
test_identity(setIdentity<matrix<T, 9,Dynamic> >(9, 3), 9, 3);
test_identity(setIdentity<matrix<T,Dynamic, 3> >(2, 3), 2, 3);
test_identity(setIdentity<matrix<T, 3, 4, O::value>>(), 3, 4);
test_identity(setIdentity<matrix<T, 1, 1, O::value>>(), 1, 1);
test_identity(setIdentity<matrix<T, 10, 10, O::value>>(), 10, 10);
test_identity(setIdentity<matrix<T, Dynamic, Dynamic, O::value>>(3, 4), 3, 4);
test_identity(setIdentity<matrix<T, 7, 5, O::value>>(7, 5), 7, 5);
test_identity(setIdentity<matrix<T, 9, Dynamic>>(9, 3), 9, 3);
test_identity(setIdentity<matrix<T, Dynamic, 3>>(2, 3), 2, 3);
test_identity(setIdentity(matrix<T, 3, 4, O::value>{} ), 3, 4);
test_identity(setIdentity(matrix<T, 1, 1, O::value>{} ), 1, 1);
test_identity(setIdentity(matrix<T, 10, 10, O::value>{} ), 10, 10);
test_identity(setIdentity(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4);
test_identity(setIdentity(matrix<T, 7, 5, O::value>{} ), 7, 5);
test_identity(setIdentity(matrix<T, 9,Dynamic>{9, 3} ), 9, 3);
test_identity(setIdentity(matrix<T,Dynamic, 3>{2, 3} ), 2, 3);
};
test_identity(setIdentity(matrix<T, 3, 4, O::value>{}), 3, 4);
test_identity(setIdentity(matrix<T, 1, 1, O::value>{}), 1, 1);
test_identity(setIdentity(matrix<T, 10, 10, O::value>{}), 10, 10);
test_identity(setIdentity(matrix<T, Dynamic, Dynamic, O::value>{3, 4}), 3, 4);
test_identity(setIdentity(matrix<T, 7, 5, O::value>{}), 7, 5);
test_identity(setIdentity(matrix<T, 9, Dynamic>{9, 3}), 9, 3);
test_identity(setIdentity(matrix<T, Dynamic, 3>{2, 3}), 2, 3);
};

View file

@ -9,54 +9,59 @@
#include "unit/common/arithmetic.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic matrix inverse", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic matrix inverse",
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>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto eps = std::numeric_limits<T>::epsilon();
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [r, c, fn] : cases)
for (auto const& [r, c, fn] : cases)
{
if(r == c)
if (r == c)
{
auto input = mat_t::Random(r, c);
auto inv = rotgen::inverse(input);
auto rec = input * inv;
auto id = mat_t::Identity(rotgen::rows(rec),rotgen::cols(rec));
auto error = rec - id;
auto rec = input * inv;
auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec));
auto error = rec - id;
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 64.)
<< "Result:\n" << rec << "\n"
<< "Residuals:\n" << error << "\n";
<< "Result:\n"
<< rec << "\n"
<< "Residuals:\n"
<< error << "\n";
}
}
};
TTS_CASE_TPL("Test static matrix inverse", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static matrix inverse",
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>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto eps = std::numeric_limits<T>::epsilon();
auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = [&]<typename D>(D const&)
{
if constexpr(D::rows == D::cols)
auto process = [&]<typename D>(D const&) {
if constexpr (D::rows == D::cols)
{
auto input = rotgen::matrix<T,D::rows,D::cols,O::value>::Random();
auto input = rotgen::matrix<T, D::rows, D::cols, O::value>::Random();
auto inv = rotgen::inverse(input);
auto rec = input * inv;
auto id = mat_t::Identity(rotgen::rows(rec),rotgen::cols(rec));
auto error = rec - id;
auto rec = input * inv;
auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec));
auto error = rec - id;
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 64.)
<< "Result:\n" << rec << "\n"
<< "Residuals:\n" << error << "\n";
<< "Result:\n"
<< rec << "\n"
<< "Residuals:\n"
<< error << "\n";
}
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -9,29 +9,31 @@
#include "unit/common/norms.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic matrix norm operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic matrix norm operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> input(rows, cols);
rotgen::tests::prepare(rows,cols,fn,input);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> input(rows,
cols);
rotgen::tests::prepare(rows, cols, fn, input);
rotgen::tests::check_norms_functions(input);
}
};
TTS_CASE_TPL("Test static matrix norm operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static matrix norm operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = []<typename D>(D const& desc)
{
rotgen::matrix<T,D::rows,D::cols,O::value> input;
rotgen::tests::prepare(input.rows(),input.cols(),desc.init_fn,input);
auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, D::rows, D::cols, O::value> input;
rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input);
rotgen::tests::check_norms_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
};
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -8,8 +8,13 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
template <typename MatrixType>
void test_matrix_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn, auto ops, auto self_ops)
template<typename MatrixType>
void test_matrix_operations(rotgen::Index rows,
rotgen::Index cols,
auto a_init_fn,
auto b_init_fn,
auto ops,
auto self_ops)
{
MatrixType a(rows, cols);
MatrixType b(rows, cols);
@ -19,22 +24,27 @@ void test_matrix_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_
{
for (rotgen::Index c = 0; c < cols; ++c)
{
a(r,c) = a_init_fn(r, c);
b(r,c) = b_init_fn(r, c);
ref(r, c) = ops(a(r,c),b(r,c));
a(r, c) = a_init_fn(r, c);
b(r, c) = b_init_fn(r, c);
ref(r, c) = ops(a(r, c), b(r, c));
}
}
TTS_EQUAL(ops(a, b), ref);
self_ops(a,b);
self_ops(a, b);
TTS_EQUAL(a, ref);
TTS_EXPECT(verify_rotgen_reentrance(ops(a, b)));
TTS_EXPECT(verify_rotgen_reentrance(self_ops(a, b)));
}
template <typename MatrixType>
void test_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto s, auto ops, auto self_ops)
template<typename MatrixType>
void test_scalar_operations(rotgen::Index rows,
rotgen::Index cols,
auto a_init_fn,
auto s,
auto ops,
auto self_ops)
{
MatrixType a(rows, cols);
MatrixType ref(rows, cols);
@ -43,21 +53,24 @@ void test_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_
{
for (rotgen::Index c = 0; c < cols; ++c)
{
a(r,c) = a_init_fn(r, c);
ref(r, c) = ops(a(r,c),s);
a(r, c) = a_init_fn(r, c);
ref(r, c) = ops(a(r, c), s);
}
}
TTS_EQUAL(ops(a, s), ref);
self_ops(a,s);
self_ops(a, s);
TTS_EQUAL(a, ref);
TTS_EXPECT(verify_rotgen_reentrance(ops(a, s)));
TTS_EXPECT(verify_rotgen_reentrance(self_ops(a, s)));
}
template <typename MatrixType>
void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn, auto s)
template<typename MatrixType>
void test_scalar_multiplications(rotgen::Index rows,
rotgen::Index cols,
auto fn,
auto s)
{
MatrixType a(rows, cols);
MatrixType ref(rows, cols);
@ -66,8 +79,8 @@ void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn
{
for (rotgen::Index c = 0; c < cols; ++c)
{
a(r,c) = fn(r, c);
ref(r, c) = a(r,c) * s;
a(r, c) = fn(r, c);
ref(r, c) = a(r, c) * s;
}
}
@ -76,25 +89,26 @@ void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn
a *= s;
TTS_EQUAL(a, ref);
TTS_EXPECT(verify_rotgen_reentrance(a*s));
TTS_EXPECT(verify_rotgen_reentrance(s*a));
TTS_EXPECT(verify_rotgen_reentrance(a*=s));
TTS_EXPECT(verify_rotgen_reentrance(a * s));
TTS_EXPECT(verify_rotgen_reentrance(s * a));
TTS_EXPECT(verify_rotgen_reentrance(a *= s));
}
template <typename MatrixType>
void test_matrix_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn)
template<typename MatrixType>
void test_matrix_multiplication(rotgen::Index rows,
rotgen::Index cols,
auto a_init_fn,
auto b_init_fn)
{
MatrixType a(rows, cols);
MatrixType b(cols, rows);
MatrixType ref(rows, rows);
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c)
a(r,c) = a_init_fn(r, c);
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = a_init_fn(r, c);
for (rotgen::Index r = 0; r < b.rows(); ++r)
for (rotgen::Index c = 0; c < b.cols(); ++c)
b(r,c) = b_init_fn(r, c);
for (rotgen::Index c = 0; c < b.cols(); ++c) b(r, c) = b_init_fn(r, c);
for (rotgen::Index i = 0; i < a.rows(); ++i)
{
@ -107,98 +121,107 @@ void test_matrix_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_i
}
TTS_EQUAL(a * b, ref);
TTS_EXPECT(verify_rotgen_reentrance(a*b));
TTS_EXPECT(verify_rotgen_reentrance(a * b));
}
// Basic initializers
inline constexpr auto init_a = [](auto r, auto c) { return 9.9*r*r*r - 6*c -12; };
inline constexpr auto init_b = [](auto r, auto c) { return 3.1*r + 4.2*c - 12.3; };
inline constexpr auto init_0 = [](auto , auto ) { return 0; };
inline constexpr auto init_a = [](auto r, auto c) {
return 9.9 * r * r * r - 6 * c - 12;
};
inline constexpr auto init_b = [](auto r, auto c) {
return 3.1 * r + 4.2 * c - 12.3;
};
inline constexpr auto init_0 = [](auto, auto) { return 0; };
TTS_CASE_TPL("Check matrix addition", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check matrix addition",
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 op = [](auto a, auto b) { return a + b; };
auto s_op = [](auto& a, auto b) { return a += b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a + b; };
auto s_op = [](auto& a, auto b) { return a += b; };
test_matrix_operations<mat_t>(1 , 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(3 , 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 3, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_b, init_a, op, s_op);
test_matrix_operations<mat_t>(1, 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(3, 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 3, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_b, init_a, op, s_op);
test_matrix_operations<mat_t>(10, 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(1 ,10, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_0, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_a, init_0, op, s_op);
test_matrix_operations<mat_t>(1, 10, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_0, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_a, init_0, op, s_op);
};
TTS_CASE_TPL("Check matrix substraction", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check matrix substraction",
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 op = [](auto a, auto b) { return a - b; };
auto s_op = [](auto& a, auto b) { return a -= b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a - b; };
auto s_op = [](auto& a, auto b) { return a -= b; };
test_matrix_operations<mat_t>(1 , 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(3 , 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 3, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_b, init_a, op, s_op);
test_matrix_operations<mat_t>(1, 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(3, 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 3, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_b, init_a, op, s_op);
test_matrix_operations<mat_t>(10, 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(1 ,10, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_0, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_a, init_0, op, s_op);
test_matrix_operations<mat_t>(1, 10, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_0, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_a, init_0, op, s_op);
};
TTS_CASE_TPL("Check matrix multiplications", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check matrix 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; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto init_id = [](auto r, auto c) { return r == c ? 1 : 0; };
test_matrix_multiplication<mat_t>(1 , 1, init_a , init_b );
test_matrix_multiplication<mat_t>(3 , 5, init_a , init_b );
test_matrix_multiplication<mat_t>(5 , 3, init_a , init_b );
test_matrix_multiplication<mat_t>(5 , 5, init_a , init_b );
test_matrix_multiplication<mat_t>(5 , 5, init_b , init_a );
test_matrix_multiplication<mat_t>(5 , 5, init_a , init_a );
test_matrix_multiplication<mat_t>(5 , 5, init_a , init_id);
test_matrix_multiplication<mat_t>(5 , 5, init_id, init_a );
test_matrix_multiplication<mat_t>(10, 1, init_a , init_b );
test_matrix_multiplication<mat_t>(1 ,10, init_a , init_b );
test_matrix_multiplication<mat_t>(5 , 5, init_0 , init_b );
test_matrix_multiplication<mat_t>(5 , 5, init_a , init_0 );
test_matrix_multiplication<mat_t>(1, 1, init_a, init_b);
test_matrix_multiplication<mat_t>(3, 5, init_a, init_b);
test_matrix_multiplication<mat_t>(5, 3, init_a, init_b);
test_matrix_multiplication<mat_t>(5, 5, init_a, init_b);
test_matrix_multiplication<mat_t>(5, 5, init_b, init_a);
test_matrix_multiplication<mat_t>(5, 5, init_a, init_a);
test_matrix_multiplication<mat_t>(5, 5, init_a, init_id);
test_matrix_multiplication<mat_t>(5, 5, init_id, init_a);
test_matrix_multiplication<mat_t>(10, 1, init_a, init_b);
test_matrix_multiplication<mat_t>(1, 10, init_a, init_b);
test_matrix_multiplication<mat_t>(5, 5, init_0, init_b);
test_matrix_multiplication<mat_t>(5, 5, init_a, init_0);
};
TTS_CASE_TPL("Check matrix multiplication with scalar", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check matrix multiplication with scalar",
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>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
test_scalar_multiplications<mat_t>(1 , 1, init_a, T{ 3.5});
test_scalar_multiplications<mat_t>(3 , 5, init_a, T{-2.5});
test_scalar_multiplications<mat_t>(5 , 3, init_a, T{ 4. });
test_scalar_multiplications<mat_t>(5 , 5, init_a, T{-5. });
test_scalar_multiplications<mat_t>(5 , 5, init_a, T{ 1. });
test_scalar_multiplications<mat_t>(5 , 5, init_a, T{ 6. });
test_scalar_multiplications<mat_t>(10, 1, init_a, T{ 10.});
test_scalar_multiplications<mat_t>(1 ,10, init_a, T{-0.5});
test_scalar_multiplications<mat_t>(1, 1, init_a, T{3.5});
test_scalar_multiplications<mat_t>(3, 5, init_a, T{-2.5});
test_scalar_multiplications<mat_t>(5, 3, init_a, T{4.});
test_scalar_multiplications<mat_t>(5, 5, init_a, T{-5.});
test_scalar_multiplications<mat_t>(5, 5, init_a, T{1.});
test_scalar_multiplications<mat_t>(5, 5, init_a, T{6.});
test_scalar_multiplications<mat_t>(10, 1, init_a, T{10.});
test_scalar_multiplications<mat_t>(1, 10, init_a, T{-0.5});
};
TTS_CASE_TPL("Check matrix division with scalar", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check matrix division with scalar",
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 op = [](auto a, auto b) { return a / b; };
auto s_op = [](auto& a, auto b) { return a /= b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a / b; };
auto s_op = [](auto& a, auto b) { return a /= b; };
test_scalar_operations<mat_t>(1 , 1, init_a, T{ 3.5}, op, s_op);
test_scalar_operations<mat_t>(3 , 5, init_a, T{-2.5}, op, s_op);
test_scalar_operations<mat_t>(5 , 3, init_a, T{ 4. }, op, s_op);
test_scalar_operations<mat_t>(5 , 5, init_a, T{-5. }, op, s_op);
test_scalar_operations<mat_t>(5 , 5, init_a, T{ 1. }, op, s_op);
test_scalar_operations<mat_t>(5 , 5, init_a, T{ 6. }, op, s_op);
test_scalar_operations<mat_t>(10, 1, init_a, T{ 10.}, op, s_op);
test_scalar_operations<mat_t>(1 ,10, init_a, T{-0.5}, op, s_op);
test_scalar_operations<mat_t>(1, 1, init_a, T{3.5}, op, s_op);
test_scalar_operations<mat_t>(3, 5, init_a, T{-2.5}, op, s_op);
test_scalar_operations<mat_t>(5, 3, init_a, T{4.}, op, s_op);
test_scalar_operations<mat_t>(5, 5, init_a, T{-5.}, op, s_op);
test_scalar_operations<mat_t>(5, 5, init_a, T{1.}, op, s_op);
test_scalar_operations<mat_t>(5, 5, init_a, T{6.}, op, s_op);
test_scalar_operations<mat_t>(10, 1, init_a, T{10.}, op, s_op);
test_scalar_operations<mat_t>(1, 10, init_a, T{-0.5}, op, s_op);
};