Merge branch 'feat/x-files' into 'main'
Use X-macros to generate all combinations of supported Eigen Matrix types Co-authored-by: Joel Falcou <joel.falcou@lri.fr> See merge request oss/rotgen!8
This commit is contained in:
parent
a76020e274
commit
8647639c0d
24 changed files with 1176 additions and 1111 deletions
47
test/unit/basic/norms.cpp
Normal file
47
test/unit/basic/norms.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
TTS_CASE_TPL("Matrix norm-related operations", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
std::vector<rotgen::tests::matrix_descriptor> test_matrices =
|
||||
{
|
||||
{ 3, 3, [](int r, int c) { return r + c; }},
|
||||
{ 2, 3, [](int , int ) { return T{0}; }},
|
||||
{ 2, 7, [](int r, int c) { return -r*r*r - c*c - T(1.23); }},
|
||||
{17, 3, [](int r, int c) { return r*c + T(0.98); }},
|
||||
{ 1, 1, [](int , int ) { return 42; }},
|
||||
{10, 11, [](int r, int c) { return std::tan(T(r + c)); }},
|
||||
{ 1, 5, [](int r, int c) { return T(-1.5)*r + T(2.56)*c + T(3.33); }},
|
||||
{ 7, 1, [](int r, int c) { return r == c ? T(1) : T(0); }},
|
||||
{ 0, 0, [](int r, int c) { return r == c ? T(1) : T(0); }},
|
||||
};
|
||||
|
||||
for (const auto& [rows, cols, fn] : test_matrices)
|
||||
{
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> matrix(rows, cols);
|
||||
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic,O::value> ref(rows, cols);
|
||||
|
||||
for (std::size_t r = 0; r < rows; ++r)
|
||||
{
|
||||
for (std::size_t c = 0; c < cols; ++c)
|
||||
{
|
||||
ref(r, c) = matrix(r, c) = fn(r,c);
|
||||
}
|
||||
}
|
||||
|
||||
TTS_EQUAL(matrix.norm(), ref.norm());
|
||||
TTS_EQUAL(matrix.squaredNorm(), ref.squaredNorm());
|
||||
TTS_EQUAL(matrix.template lpNorm<1>() , ref.template lpNorm<1>());
|
||||
TTS_EQUAL(matrix.template lpNorm<2>() , ref.template lpNorm<2>());
|
||||
TTS_EQUAL(matrix.template lpNorm<rotgen::Infinity>(), ref.template lpNorm<Eigen::Infinity>());
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue