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
|
|
@ -6,42 +6,32 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include "unit/common/norms.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
TTS_CASE_TPL("Matrix norm-related operations", rotgen::tests::types)
|
||||
TTS_CASE_TPL("Test dynamic matrix norm operations", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
std::vector<rotgen::tests::matrix_descriptor> test_matrices =
|
||||
auto const cases = rotgen::tests::generate_matrix_references();
|
||||
for (const auto& [rows, cols, fn] : cases)
|
||||
{
|
||||
{ 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); }},
|
||||
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>> )
|
||||
{
|
||||
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);
|
||||
rotgen::tests::check_norms_functions(input);
|
||||
};
|
||||
|
||||
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 (rotgen::Index r = 0; r < rows; ++r)
|
||||
{
|
||||
for (rotgen::Index 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>());
|
||||
}
|
||||
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue