Implements block typs and related functions - First part
Co-authored-by: Karen <kkaspar@codereckons.com> Co-authored-by: Joel FALCOU <jfalcou@codereckons.com> See merge request oss/rotgen!9
This commit is contained in:
parent
09be3b4b15
commit
c6b864f247
28 changed files with 1814 additions and 114 deletions
115
test/unit/block/static_functions.cpp
Normal file
115
test/unit/block/static_functions.cpp
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/block.hpp>
|
||||
#include <rotgen/matrix.hpp>
|
||||
|
||||
void test_size(const auto& matrix, std::size_t rows, std::size_t cols)
|
||||
{
|
||||
TTS_EQUAL(matrix.rows(), rows);
|
||||
TTS_EQUAL(matrix.cols(), cols);
|
||||
TTS_EQUAL(matrix.size(), rows*cols);
|
||||
}
|
||||
|
||||
void test_value(const auto& matrix, std::size_t rows, std::size_t cols, auto constant)
|
||||
{
|
||||
test_size(matrix, rows, cols);
|
||||
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)
|
||||
{
|
||||
test_size(matrix, rows, 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)
|
||||
{
|
||||
test_size(matrix, rows, 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::block<rotgen::matrix<T, 7, 8>, 3, 4>::Zero(), 3, 4, 0);
|
||||
test_value(rotgen::block<rotgen::matrix<T, 72, 2>, 1, 1>::Zero(), 1, 1, 0);
|
||||
test_value(rotgen::block<rotgen::matrix<T, 21, 33>, 10, 10>::Zero(), 10, 10, 0);
|
||||
test_value(rotgen::block<rotgen::matrix<T, 3, 4>, 3, 4>::Zero(3, 4), 3, 4, 0);
|
||||
test_value(rotgen::block<rotgen::matrix<T, 17, 4>, 3, 3>::Zero(3, 3), 3, 3, 0);
|
||||
test_value(rotgen::block<rotgen::matrix<T, 2, 2>, 2, 2>::Zero(2, 2), 2, 2, 0);
|
||||
test_value(rotgen::block<rotgen::matrix<T, 8, 7>, rotgen::Dynamic, rotgen::Dynamic>::Zero(2, 3), 2, 3, 0);
|
||||
test_value(rotgen::block<rotgen::matrix<T, 3, 4>, 0, 0>::Zero(0, 0), 0, 0, 0);
|
||||
test_value(rotgen::block<decltype(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Identity(2, 7)),
|
||||
rotgen::Dynamic, 7>::Zero(3, 7), 3, 7, 0);
|
||||
test_value(rotgen::block<decltype(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Random(14, 3)),
|
||||
4, rotgen::Dynamic>::Zero(4, 3), 4, 3, 0);
|
||||
};
|
||||
|
||||
|
||||
TTS_CASE_TPL("Test constant", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
test_value(rotgen::block<rotgen::matrix<T, 3, 4>, 3, 4>::Constant(5.12), 3, 4, T(5.12));
|
||||
test_value(rotgen::block<rotgen::matrix<T, 88, 81>, 1, 1>::Constant(2.2), 1, 1, T(2.2));
|
||||
test_value(rotgen::block<rotgen::matrix<T, 21, 33>, 10, 10>::Constant(13), 10, 10, T(13));
|
||||
test_value(rotgen::block<rotgen::matrix<T, 3, 4>, rotgen::Dynamic, rotgen::Dynamic>::Constant(2, 7, 5.6), 2, 7, T(5.6));
|
||||
test_value(rotgen::block<rotgen::matrix<T, 17, 5>, 2, 2>::Constant(2, 2, 2.0), 2, 2, T(2.0));
|
||||
test_value(rotgen::block<rotgen::matrix<T, 144, 109>, rotgen::Dynamic, 9>::Constant(9, 9, 1.1), 9, 9, T(1.1));
|
||||
test_value(rotgen::block<rotgen::matrix<T, 8, 11>, 5, rotgen::Dynamic>::Constant(5, 9, 42), 5, 9, T(42));
|
||||
test_value(rotgen::block<rotgen::matrix<T, 4, 3>, 4, 3>::Constant(4, 3, 0), 4, 3, 0);
|
||||
test_value(rotgen::block<decltype(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Identity(3, 7)),
|
||||
rotgen::Dynamic, 7>::Constant(3, 7, 88), 3, 7, T(88));
|
||||
test_value(rotgen::block<decltype(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Random(14, 3)),
|
||||
4, rotgen::Dynamic>::Constant(4, 3, 3.99), 4, 3, T(3.99));
|
||||
};
|
||||
|
||||
|
||||
TTS_CASE_TPL("Test random", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
test_random(rotgen::block<rotgen::matrix<T, 3, 4>, 3, 3>::Random(), 3, 3);
|
||||
test_random(rotgen::block<rotgen::matrix<T, 1, 1>, 1, 1>::Random(), 1, 1);
|
||||
test_random(rotgen::block<rotgen::matrix<T, 13, 12>, 3, 4>::Random(), 3, 4);
|
||||
test_random(rotgen::block<rotgen::matrix<T, 3, 4>, rotgen::Dynamic, rotgen::Dynamic>::Random(1, 5), 1, 5);
|
||||
test_random(rotgen::block<rotgen::matrix<T, 17, 11>, 2, 1>::Random(2, 1), 2, 1);
|
||||
test_random(rotgen::block<rotgen::matrix<T, 109, 117>, rotgen::Dynamic, 9>::Random(3, 9), 3, 9);
|
||||
test_random(rotgen::block<rotgen::matrix<T, 9, 11>, 5, rotgen::Dynamic>::Random(5, 2), 5, 2);
|
||||
test_random(rotgen::block<rotgen::matrix<T, 4, 3>, 4, 3>::Random(4, 3), 4, 3);
|
||||
test_random(rotgen::block<decltype(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Identity(3, 7)),
|
||||
rotgen::Dynamic, 7>::Random(3, 7), 3, 7);
|
||||
test_random(rotgen::block<decltype(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Random(14, 15)),
|
||||
4, rotgen::Dynamic>::Random(4, 11), 4, 11);
|
||||
};
|
||||
|
||||
|
||||
TTS_CASE_TPL("Test identity", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
test_identity(rotgen::block<rotgen::matrix<T, 3, 4>, 3, 3>::Identity(), 3, 3);
|
||||
test_identity(rotgen::block<rotgen::matrix<T, 1, 1>, 1, 1>::Identity(), 1, 1);
|
||||
test_identity(rotgen::block<rotgen::matrix<T, 13, 12>, 3, 4>::Identity(), 3, 4);
|
||||
test_identity(rotgen::block<rotgen::matrix<T, 3, 4>, rotgen::Dynamic, rotgen::Dynamic>::Identity(1, 5), 1, 5);
|
||||
test_identity(rotgen::block<rotgen::matrix<T, 17, 11>, 2, 1>::Identity(2, 1), 2, 1);
|
||||
test_identity(rotgen::block<rotgen::matrix<T, 109, 117>, rotgen::Dynamic, 9>::Identity(3, 9), 3, 9);
|
||||
test_identity(rotgen::block<rotgen::matrix<T, 9, 11>, 5, rotgen::Dynamic>::Identity(5, 2), 5, 2);
|
||||
test_identity(rotgen::block<rotgen::matrix<T, 4, 3>, 4, 3>::Identity(4, 3), 4, 3);
|
||||
test_identity(rotgen::block<decltype(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Identity(3, 7)),
|
||||
rotgen::Dynamic, 7>::Identity(3, 7), 3, 7);
|
||||
test_identity(rotgen::block<decltype(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Random(14, 15)),
|
||||
4, rotgen::Dynamic>::Identity(4, 11), 4, 11);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue