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
81
test/unit/basic/static_functions.cpp
Normal file
81
test/unit/basic/static_functions.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/matrix.hpp>
|
||||
|
||||
void test_value(const auto& matrix, std::size_t rows, std::size_t cols, auto 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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>> )
|
||||
{
|
||||
test_value(rotgen::matrix<T, 3, 4, O::value>::Zero(), 3, 4, 0);
|
||||
test_value(rotgen::matrix<T, 1, 1, O::value>::Zero(), 1, 1, 0);
|
||||
test_value(rotgen::matrix<T, 10, 10, O::value>::Zero(), 10, 10, 0);
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Zero(3, 4), 3, 4, 0);
|
||||
test_value(rotgen::matrix<T, 7, 5, O::value>::Zero(7, 5), 7, 5, 0);
|
||||
test_value(rotgen::matrix<T, 9,rotgen::Dynamic, O::value>::Zero(9, 3), 9, 3, 0);
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic, 3, O::value>::Zero(2, 3), 2, 3, 0);
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test constant", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
test_value(rotgen::matrix<T, 3, 8, O::value>::Constant(5.12), 3, 8, T(5.12));
|
||||
test_value(rotgen::matrix<T, 1, 1, O::value>::Constant(2.2), 1, 1, T(2.2));
|
||||
test_value(rotgen::matrix<T, 11, 12, O::value>::Constant(13), 11, 12, T(13));
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Constant(2, 7, 5.6), 2, 7, T(5.6));
|
||||
test_value(rotgen::matrix<T, 2, 2, O::value>::Constant(2, 2, 2.0), 2, 2, T(2.0));
|
||||
test_value(rotgen::matrix<T, 9,rotgen::Dynamic, O::value>::Constant(9, 3, 1.1), 9, 3, T(1.1));
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic, 9, O::value>::Constant(5, 9, 42), 5, 9,T(42));
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test random", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
test_random(rotgen::matrix<T, 2, 3, O::value>::Random(), 2, 3);
|
||||
test_random(rotgen::matrix<T, 1, 1, O::value>::Random(), 1, 1);
|
||||
test_random(rotgen::matrix<T, 11, 17, O::value>::Random(), 11, 17);
|
||||
test_random(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Random(7, 3), 7, 3);
|
||||
test_random(rotgen::matrix<T, 2, 2, O::value>::Random(2, 2), 2, 2);
|
||||
test_random(rotgen::matrix<T, 4,rotgen::Dynamic, O::value>::Random(4, 3), 4, 3);
|
||||
test_random(rotgen::matrix<T,rotgen::Dynamic, 5, O::value>::Random(5, 5), 5, 5);
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test identity", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
test_identity(rotgen::matrix<T, 4, 5, O::value>::Identity(), 4, 5);
|
||||
test_identity(rotgen::matrix<T, 1, 1, O::value>::Identity(), 1, 1);
|
||||
test_identity(rotgen::matrix<T, 21, 3, O::value>::Identity(), 21, 3);
|
||||
test_identity(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Identity(2, 7), 2, 7);
|
||||
test_identity(rotgen::matrix<T, 2, 2, O::value>::Identity(2, 2), 2, 2);
|
||||
test_identity(rotgen::matrix<T, 3,rotgen::Dynamic, O::value>::Identity(3, 3), 3, 3);
|
||||
test_identity(rotgen::matrix<T,rotgen::Dynamic, 11, O::value>::Identity(5, 11), 5, 11);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue