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
49
test/unit/block/norms.cpp
Normal file
49
test/unit/block/norms.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <rotgen/extract.hpp>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
TTS_CASE_TPL("Matrix norm-related operations", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
||||
|
||||
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> test_cases =
|
||||
{
|
||||
{6, 5, [](auto r, auto c) {return r + c; }, 1, 2, 3, 2},
|
||||
{9, 11, [](auto r, auto c) {return r + c; }, 0, 1, 4, 9},
|
||||
{3, 3, [](auto , auto ) {return 0.0; }, 1, 1, 1, 1},
|
||||
{1, 4, [](auto r, auto c) {return -r -c*c - 1234; }, 0, 0, 1, 1},
|
||||
{4, 1, [](auto , auto ) {return 7.0; }, 2, 0, 2, 1},
|
||||
{1, 1, [](auto , auto ) {return 42.0; }, 0, 0, 1, 1},
|
||||
{12, 13, [](auto r, auto c) {return std::sin(r + c); }, 2, 3, 4, 5 },
|
||||
{4, 9, [](auto r, auto c) {return -1.5 * r + 2.56 * c; }, 0, 1, 2, 3 },
|
||||
{2, 5, [](auto r, auto c) {return (r == c ? 1.0 : 0.0); }, 1, 1, 1, 1},
|
||||
};
|
||||
|
||||
for (const auto& [rows, cols, fn, i0, j0, ni, nj] : test_cases)
|
||||
{
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> original_matrix(rows, cols);
|
||||
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic,O::value> ref_matrix(rows, cols);
|
||||
|
||||
for (std::size_t r = 0; r < rows; ++r)
|
||||
for (std::size_t c = 0; c < cols; ++c)
|
||||
ref_matrix(r, c) = original_matrix(r, c) = fn(r,c);
|
||||
|
||||
auto original_block = rotgen::extract(original_matrix, i0, j0, ni, nj);
|
||||
auto ref_block = ref_matrix.block(i0, j0, ni, nj);
|
||||
|
||||
TTS_EQUAL(original_block.norm(), ref_block.norm());
|
||||
TTS_EQUAL(original_block.squaredNorm(), ref_block.squaredNorm());
|
||||
TTS_EQUAL(original_block.template lpNorm<1>() , ref_block.template lpNorm<1>());
|
||||
TTS_EQUAL(original_block.template lpNorm<2>() , ref_block.template lpNorm<2>());
|
||||
TTS_EQUAL(original_block.template lpNorm<rotgen::Infinity>(), ref_block.template lpNorm<Eigen::Infinity>());
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue