Implements map and ref for both static & dynamic mode
See merge request oss/rotgen!12
This commit is contained in:
parent
aacae1cbb1
commit
6c2b260229
58 changed files with 4121 additions and 1205 deletions
136
test/unit/matrix/generators.cpp
Normal file
136
test/unit/matrix/generators.cpp
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
void test_value(const auto& 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);
|
||||
}
|
||||
|
||||
void test_random(const auto& 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_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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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>{}.setZero(), 3, 4, 0);
|
||||
test_value(rotgen::matrix<T, 1, 1, O::value>{}.setZero(), 1, 1, 0);
|
||||
test_value(rotgen::matrix<T, 10, 10, O::value>{}.setZero(), 10, 10, 0);
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>(1,1).setZero(3,4), 3, 4, 0);
|
||||
test_value(rotgen::matrix<T, 7, 5, O::value>().setZero(7, 5), 7, 5, 0);
|
||||
test_value(rotgen::matrix<T, 9,rotgen::Dynamic, O::value>(9,1).setZero(9, 3), 9, 3, 0);
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic, 3, O::value>(1,3).setZero(2, 3), 2, 3, 0);
|
||||
|
||||
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 ones", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
test_value(rotgen::matrix<T, 3, 4, O::value>{}.setOnes(), 3, 4, 1);
|
||||
test_value(rotgen::matrix<T, 1, 1, O::value>{}.setOnes(), 1, 1, 1);
|
||||
test_value(rotgen::matrix<T, 10, 10, O::value>{}.setOnes(), 10, 10, 1);
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>(1,1).setOnes(3, 4), 3, 4, 1);
|
||||
test_value(rotgen::matrix<T, 7, 5, O::value>{}.setOnes(7, 5), 7, 5, 1);
|
||||
test_value(rotgen::matrix<T, 9,rotgen::Dynamic, O::value>(9,1).setOnes(9, 3), 9, 3, 1);
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic, 3, O::value>(1,3).setOnes(2, 3), 2, 3, 1);
|
||||
|
||||
test_value(rotgen::matrix<T, 3, 4, O::value>::Ones(), 3, 4, 1);
|
||||
test_value(rotgen::matrix<T, 1, 1, O::value>::Ones(), 1, 1, 1);
|
||||
test_value(rotgen::matrix<T, 10, 10, O::value>::Ones(), 10, 10, 1);
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>::Ones(3, 4), 3, 4, 1);
|
||||
test_value(rotgen::matrix<T, 7, 5, O::value>::Ones(7, 5), 7, 5, 1);
|
||||
test_value(rotgen::matrix<T, 9,rotgen::Dynamic, O::value>::Ones(9, 3), 9, 3, 1);
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic, 3, O::value>::Ones(2, 3), 2, 3, 1);
|
||||
};
|
||||
|
||||
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>{}.setConstant(5.12), 3, 8, T(5.12));
|
||||
test_value(rotgen::matrix<T, 1, 1, O::value>{}.setConstant(2.2), 1, 1, T(2.2));
|
||||
test_value(rotgen::matrix<T, 11, 12, O::value>{}.setConstant(13), 11, 12, T(13));
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>(1,1).setConstant(2, 7, 5.6), 2, 7, T(5.6));
|
||||
test_value(rotgen::matrix<T, 2, 2, O::value>{}.setConstant(2, 2, 2.0), 2, 2, T(2.0));
|
||||
test_value(rotgen::matrix<T, 9,rotgen::Dynamic, O::value>(9,1).setConstant(9, 3, 1.1), 9, 3, T(1.1));
|
||||
test_value(rotgen::matrix<T,rotgen::Dynamic, 9, O::value>(1,9).setConstant(5, 9, 42), 5, 9,T(42));
|
||||
|
||||
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>{}.setRandom(), 2, 3);
|
||||
test_random(rotgen::matrix<T, 1, 1, O::value>{}.setRandom(), 1, 1);
|
||||
test_random(rotgen::matrix<T, 11, 17, O::value>{}.setRandom(), 11, 17);
|
||||
test_random(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>{1,1}.setRandom(7, 3), 7, 3);
|
||||
test_random(rotgen::matrix<T, 2, 2, O::value>{}.setRandom(2, 2), 2, 2);
|
||||
test_random(rotgen::matrix<T, 4,rotgen::Dynamic, O::value>{4,1}.setRandom(4, 3), 4, 3);
|
||||
test_random(rotgen::matrix<T,rotgen::Dynamic, 5, O::value>{1,5}.setRandom(5, 5), 5, 5);
|
||||
|
||||
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>{}.setIdentity(), 4, 5);
|
||||
test_identity(rotgen::matrix<T, 1, 1, O::value>{}.setIdentity(), 1, 1);
|
||||
test_identity(rotgen::matrix<T, 21, 3, O::value>{}.setIdentity(), 21, 3);
|
||||
test_identity(rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic, O::value>{1,1}.setIdentity(2, 7), 2, 7);
|
||||
test_identity(rotgen::matrix<T, 2, 2, O::value>{}.setIdentity(2, 2), 2, 2);
|
||||
test_identity(rotgen::matrix<T, 3,rotgen::Dynamic, O::value>{3,1}.setIdentity(3, 3), 3, 3);
|
||||
test_identity(rotgen::matrix<T,rotgen::Dynamic, 11, O::value>{1,11}.setIdentity(5, 11), 5, 11);
|
||||
|
||||
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