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,128 +6,69 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include "unit/common/arithmetic.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
template<typename Type1, typename Type2>
|
||||
void test_comparison(const Type1& t1, const Type2& t2)
|
||||
{
|
||||
TTS_EQUAL(static_cast<std::ptrdiff_t>(t1.rows()), static_cast<std::ptrdiff_t>(t2.rows()));
|
||||
TTS_EQUAL(static_cast<std::ptrdiff_t>(t1.cols()), static_cast<std::ptrdiff_t>(t2.cols()));
|
||||
for (rotgen::Index r = 0; r < static_cast<rotgen::Index>(t1.rows()); ++r)
|
||||
for (rotgen::Index c = 0; c < static_cast<rotgen::Index>(t1.cols()); ++c)
|
||||
TTS_EQUAL(t1(r, c), t2(r, c));
|
||||
}
|
||||
|
||||
template<typename Matrix1, typename Matrix2, typename Block1, typename Block2>
|
||||
void test_block_unary_ops(const Matrix1& original_matrix, const Matrix2& ref_matrix,
|
||||
Block1 original_block, Block2 ref_block)
|
||||
{
|
||||
TTS_EXPECT(verify_rotgen_reentrance(original_block.transpose()));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(original_block.conjugate()));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(original_block.adjoint()));
|
||||
|
||||
test_comparison(original_block.transpose(), ref_block.transpose());
|
||||
test_comparison(original_block.conjugate(), ref_block.conjugate());
|
||||
test_comparison(original_block.adjoint(), ref_block.adjoint());
|
||||
|
||||
if (original_block.rows() == original_block.cols()) {
|
||||
original_block.transposeInPlace();
|
||||
ref_block.transposeInPlace();
|
||||
test_comparison(original_block, ref_block);
|
||||
test_comparison(original_matrix, ref_matrix);
|
||||
|
||||
original_block.adjointInPlace();
|
||||
ref_block.adjointInPlace();
|
||||
test_comparison(original_block, ref_block);
|
||||
test_comparison(original_matrix, ref_matrix);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Block1, typename Block2>
|
||||
void compare_reductions(const Block1& block, const Block2& ref)
|
||||
{
|
||||
constexpr double epsilon = 0.0001;
|
||||
TTS_RELATIVE_EQUAL(block.sum(), ref.sum(), epsilon);
|
||||
TTS_RELATIVE_EQUAL(block.prod(), ref.prod(), epsilon);
|
||||
TTS_RELATIVE_EQUAL(block.mean(), ref.mean(), epsilon);
|
||||
TTS_EQUAL(block.trace(), ref.trace());
|
||||
TTS_EQUAL(block.minCoeff(), ref.minCoeff());
|
||||
TTS_EQUAL(block.maxCoeff(), ref.maxCoeff());
|
||||
|
||||
std::ptrdiff_t row, col, ref_row, ref_col;
|
||||
|
||||
TTS_EQUAL(block.minCoeff(&row, &col), ref.minCoeff(&ref_row, &ref_col));
|
||||
TTS_EQUAL(row, ref_row);
|
||||
TTS_EQUAL(col, ref_col);
|
||||
|
||||
TTS_EQUAL(block.maxCoeff(&row, &col), ref.maxCoeff(&ref_row, &ref_col));
|
||||
TTS_EQUAL(row, ref_row);
|
||||
TTS_EQUAL(col, ref_col);
|
||||
}
|
||||
|
||||
template <typename MatrixType, typename T>
|
||||
void test_dynamic_block_reductions(rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct)
|
||||
{
|
||||
using EigenMatrix = Eigen::Matrix<typename MatrixType::scalar_type, Eigen::Dynamic, Eigen::Dynamic>;
|
||||
|
||||
MatrixType original(matrix_construct.rows, matrix_construct.cols);
|
||||
EigenMatrix ref(matrix_construct.rows, matrix_construct.cols);
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
ref(r, c) = original(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
|
||||
|
||||
std::vector<std::pair<rotgen::block<MatrixType>, Eigen::Block<EigenMatrix>>> test_cases {
|
||||
{ rotgen::extract(original, matrix_construct.i0, matrix_construct.j0,
|
||||
matrix_construct.ni, matrix_construct.nj),
|
||||
ref.block(matrix_construct.i0, matrix_construct.j0,
|
||||
matrix_construct.ni, matrix_construct.nj) },
|
||||
|
||||
{ rotgen::topLeftCorner(original, matrix_construct.ni, matrix_construct.nj),
|
||||
ref.topLeftCorner(matrix_construct.ni, matrix_construct.nj) },
|
||||
{ rotgen::topRightCorner(original, matrix_construct.ni, matrix_construct.nj),
|
||||
ref.topRightCorner(matrix_construct.ni, matrix_construct.nj) },
|
||||
{ rotgen::bottomLeftCorner(original, matrix_construct.ni, matrix_construct.nj),
|
||||
ref.bottomLeftCorner(matrix_construct.ni, matrix_construct.nj) },
|
||||
{ rotgen::bottomRightCorner(original, matrix_construct.ni, matrix_construct.nj),
|
||||
ref.bottomRightCorner(matrix_construct.ni, matrix_construct.nj) },
|
||||
|
||||
{ rotgen::topRows(original, matrix_construct.ni),
|
||||
ref.topRows(matrix_construct.ni) },
|
||||
{ rotgen::middleRows(original, matrix_construct.i0, matrix_construct.ni),
|
||||
ref.middleRows(matrix_construct.i0, matrix_construct.ni) },
|
||||
{ rotgen::bottomRows(original, matrix_construct.ni),
|
||||
ref.bottomRows(matrix_construct.ni) },
|
||||
};
|
||||
|
||||
for (const auto& [original_block, ref_block] : test_cases) {
|
||||
compare_reductions(original_block, ref_block);
|
||||
test_block_unary_ops(original, ref, original_block, ref_block);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TTS_CASE_TPL("Test dynamic block reductions", rotgen::tests::types)
|
||||
TTS_CASE_TPL("Test dynamic block transposition-like 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, [](rotgen::Index r, rotgen::Index c) { return T(r + c); }, 1, 2, 3, 2},
|
||||
{9, 11, [](rotgen::Index r, rotgen::Index c) {return T(r + c); }, 0, 1, 4, 9},
|
||||
{3, 3, [](rotgen::Index , rotgen::Index ) {return T(0.0); }, 1, 1, 1, 1},
|
||||
{1, 4, [](rotgen::Index r, rotgen::Index c) {return T(-r -c*c - 1234); }, 0, 0, 1, 1},
|
||||
{9, 9, [](rotgen::Index r, rotgen::Index c) {return T(-r + 2*c); }, 0, 1, 3, 3},
|
||||
{11, 13, [](rotgen::Index r, rotgen::Index c) {return T(std::tan(r+c)); }, 1, 1, 2, 2},
|
||||
{4, 1, [](rotgen::Index , rotgen::Index ) {return T(7.0); }, 2, 0, 2, 1},
|
||||
{1, 1, [](rotgen::Index , rotgen::Index ) {return T(42.0); }, 0, 0, 1, 1},
|
||||
{12, 13, [](rotgen::Index r, rotgen::Index c) {return T(std::sin(r + c)); }, 2, 3, 4, 5 },
|
||||
{4, 9, [](rotgen::Index r, rotgen::Index c) {return T(-1.5 * r + 2.56 * c); }, 0, 1, 2, 3 },
|
||||
{2, 5, [](rotgen::Index r, rotgen::Index c) {return T(r == c ? 1.0 : 0.0); }, 1, 1, 1, 1},
|
||||
};
|
||||
|
||||
for (const auto& test_case : test_cases)
|
||||
test_dynamic_block_reductions<mat_t, T>(test_case);
|
||||
auto const cases = rotgen::tests::generate_block_references<T,O>();
|
||||
for (const auto& [matrix_desc, i0, j0, ni, nj] : cases)
|
||||
{
|
||||
auto[rows,cols,fn] = matrix_desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract(m, i0, j0, ni, nj);
|
||||
rotgen::tests::check_shape_functions(input);
|
||||
}
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test static block transposition-like operations", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_static_block_references<T,O>();
|
||||
|
||||
auto process = []<typename D>(D const& d)
|
||||
{
|
||||
auto[desc,i0,j0] = d;
|
||||
auto[rows,cols,fn] = desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract<D::ni,D::nj>(m, i0, j0);
|
||||
rotgen::tests::check_shape_functions(input);
|
||||
};
|
||||
|
||||
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test dynamic block reduction-like operations", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_block_references<T,O>();
|
||||
for (const auto& [matrix_desc, i0, j0, ni, nj] : cases)
|
||||
{
|
||||
auto[rows,cols,fn] = matrix_desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract(m, i0, j0, ni, nj);
|
||||
rotgen::tests::check_reduction_functions(input);
|
||||
}
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test static block reduction-like operations", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_static_block_references<T,O>();
|
||||
|
||||
auto process = []<typename D>(D const& d)
|
||||
{
|
||||
auto[desc,i0,j0] = d;
|
||||
auto[rows,cols,fn] = desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract<D::ni,D::nj>(m, i0, j0);
|
||||
rotgen::tests::check_reduction_functions(input);
|
||||
};
|
||||
|
||||
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||
};
|
||||
|
|
|
|||
104
test/unit/block/basic_api.cpp
Normal file
104
test/unit/block/basic_api.cpp
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
TTS_CASE_TPL("Function size", rotgen::tests::types)
|
||||
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
||||
{
|
||||
T data[] = {1,2,3,4,5,6,7,8,9,10,11,12};
|
||||
|
||||
// Helper: fill matrix from raw data
|
||||
auto fill = [&](auto& m, int r, int c) {
|
||||
for(int k = 0; k < r * c; ++k) m.data()[k] = data[k];
|
||||
};
|
||||
|
||||
// 1x12 dynamic block at (0,0)
|
||||
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> dm(1,12);
|
||||
fill(dm,1,12);
|
||||
auto b1 = rotgen::block<decltype(dm), rotgen::Dynamic, rotgen::Dynamic, false, O::value>(dm, 0,0,1,12);
|
||||
TTS_EQUAL(b1.rows(), rotgen::Index{1});
|
||||
TTS_EQUAL(b1.cols(), rotgen::Index{12});
|
||||
|
||||
// 1x5 dynamic block at (0,2)
|
||||
auto b2 = rotgen::block<decltype(dm), rotgen::Dynamic, rotgen::Dynamic, false, O::value>(dm, 0,2,1,5);
|
||||
TTS_EQUAL(b2.rows(), rotgen::Index{1});
|
||||
TTS_EQUAL(b2.cols(), rotgen::Index{5});
|
||||
|
||||
// 3x2 dynamic block at (1,4) in 4x6
|
||||
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> dm2(4,6);
|
||||
fill(dm2,4,6);
|
||||
auto b3 = rotgen::block<decltype(dm2), rotgen::Dynamic, rotgen::Dynamic, false, O::value>(dm2, 1,4,3,2);
|
||||
TTS_EQUAL(b3.rows(), rotgen::Index{3});
|
||||
TTS_EQUAL(b3.cols(), rotgen::Index{2});
|
||||
TTS_EQUAL(b3.size(), rotgen::Index{6});
|
||||
|
||||
// 3x4 static block
|
||||
rotgen::matrix<T,3,4,O::value> sm;
|
||||
fill(sm,3,4);
|
||||
auto b4 = rotgen::block<decltype(sm), 3, 4, false, O::value>(sm, 0,0);
|
||||
TTS_EQUAL(b4.rows(), rotgen::Index{3});
|
||||
TTS_EQUAL(b4.cols(), rotgen::Index{4});
|
||||
TTS_EQUAL(b4.size(), rotgen::Index{12});
|
||||
|
||||
// 6x2 static block
|
||||
rotgen::matrix<T,6,2,O::value> sm2;
|
||||
fill(sm2,6,2);
|
||||
auto b5 = rotgen::block<decltype(sm2), 6, 2, false, O::value>(sm2, 0,0);
|
||||
TTS_EQUAL(b5.rows(), rotgen::Index{6});
|
||||
TTS_EQUAL(b5.cols(), rotgen::Index{2});
|
||||
TTS_EQUAL(b5.size(), rotgen::Index{12});
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
using base = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
||||
|
||||
T data[] = {1,2,3,4,5,6,7,8,9,10,11,12};
|
||||
base mat(4,3);
|
||||
for(int k=0;k<12;++k) mat.data()[k] = data[k];
|
||||
|
||||
auto b = rotgen::block<base,rotgen::Dynamic,rotgen::Dynamic,false,O::value>(mat, 0, 0, 4, 3);
|
||||
for(rotgen::Index i=0;i<4;i++)
|
||||
{
|
||||
for(rotgen::Index j=0;j<3;j++)
|
||||
{
|
||||
if constexpr(O::value) TTS_EQUAL(b(i,j), data[j+3*i]);
|
||||
else TTS_EQUAL(b(i,j), data[i+4*j]);
|
||||
}
|
||||
}
|
||||
|
||||
b(1, 1) = 42;
|
||||
TTS_EQUAL(b(1,1), 42);
|
||||
|
||||
T& ref = b(2, 2);
|
||||
ref = 17;
|
||||
TTS_EQUAL(b(2, 2), 17);
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
using base = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
||||
|
||||
T data[] = {1,2,3,4,5,6,7,8,9,10,11,12};
|
||||
base mat(4,3);
|
||||
for(int k=0;k<12;++k) mat.data()[k] = data[k];
|
||||
|
||||
auto b = rotgen::block<base,rotgen::Dynamic,rotgen::Dynamic,false,O::value>(mat, 0, 0, 4, 3);
|
||||
for(rotgen::Index i=0;i<b.size();i++)
|
||||
TTS_EQUAL(b(i), data[i]) << "Index: " << i << "\n";
|
||||
|
||||
b(1) = 42;
|
||||
TTS_EQUAL(mat.data()[1], 42);
|
||||
|
||||
T& ref = b(2);
|
||||
ref = 17;
|
||||
TTS_EQUAL(mat.data()[2], 17);
|
||||
};
|
||||
|
|
@ -27,11 +27,14 @@ void for_each_element(EigenType& m, F&& f)
|
|||
template<typename MatrixType, typename T>
|
||||
MatrixType make_initialized_matrix(rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct)
|
||||
{
|
||||
MatrixType matrix(matrix_construct.rows, matrix_construct.cols);
|
||||
auto[d,i0,j0,ni,nj] = matrix_construct;
|
||||
auto[r,c,fn] = d;
|
||||
|
||||
for(rotgen::Index i = 0; i < matrix_construct.rows; ++i)
|
||||
for(rotgen::Index j = 0; j < matrix_construct.cols; ++j)
|
||||
matrix(i, j) = static_cast<T>(matrix_construct.init_fn(i, j));
|
||||
MatrixType matrix(r, c);
|
||||
|
||||
for(rotgen::Index i = 0; i < r; ++i)
|
||||
for(rotgen::Index j = 0; j < c; ++j)
|
||||
matrix(i, j) = static_cast<T>(fn(i, j));
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
|
@ -127,31 +130,34 @@ void test_dynamic_block_extraction(rotgen::tests::matrix_block_test_case<MatrixT
|
|||
template<typename MatrixType, typename T, rotgen::Index NI, rotgen::Index NJ>
|
||||
void test_static_block_extraction(rotgen::tests::static_matrix_block_test_case<MatrixType, NI, NJ> const& matrix_construct)
|
||||
{
|
||||
MatrixType matrix(matrix_construct.rows, matrix_construct.cols);
|
||||
auto[d,i0,j0] = matrix_construct;
|
||||
auto[r,c,fn] = d;
|
||||
|
||||
for (rotgen::Index i = 0; i < matrix_construct.rows; ++i)
|
||||
for (rotgen::Index j = 0; j < matrix_construct.cols; ++j)
|
||||
matrix(i, j) = static_cast<T>(matrix_construct.init_fn(i, j));
|
||||
MatrixType matrix(r,c);
|
||||
|
||||
auto block_main = rotgen::extract<NI, NJ>(matrix, matrix_construct.i0, matrix_construct.j0);
|
||||
for (rotgen::Index i = 0; i < r; ++i)
|
||||
for (rotgen::Index j = 0; j < c; ++j)
|
||||
matrix(i, j) = static_cast<T>(fn(i, j));
|
||||
|
||||
auto block_main = rotgen::extract<NI, NJ>(matrix, i0, j0);
|
||||
auto block_top_left_corner = rotgen::topLeftCorner<NI, NJ>(matrix);
|
||||
auto block_top_right_corner = rotgen::topRightCorner<NI, NJ>(matrix);
|
||||
auto block_bottom_left_corner = rotgen::bottomLeftCorner<NI, NJ>(matrix);
|
||||
auto block_bottom_right_corner = rotgen::bottomRightCorner<NI, NJ>(matrix);
|
||||
|
||||
auto block_top_rows = rotgen::topRows<NI>(matrix);
|
||||
auto block_middle_rows = rotgen::middleRows<NI>(matrix, matrix_construct.i0);
|
||||
auto block_middle_rows = rotgen::middleRows<NI>(matrix, i0);
|
||||
auto block_bottom_rows = rotgen::bottomRows<NI>(matrix);
|
||||
|
||||
auto block_left_cols = rotgen::leftCols<NJ>(matrix);
|
||||
auto block_middle_cols = rotgen::middleCols<NJ>(matrix, matrix_construct.j0);
|
||||
auto block_middle_cols = rotgen::middleCols<NJ>(matrix, j0);
|
||||
auto block_right_cols = rotgen::rightCols<NJ>(matrix);
|
||||
|
||||
auto block_row = rotgen::row(matrix, matrix_construct.i0);
|
||||
auto block_col = rotgen::col(matrix, matrix_construct.j0);
|
||||
auto block_row = rotgen::row(matrix, i0);
|
||||
auto block_col = rotgen::col(matrix, j0);
|
||||
|
||||
auto blocks = std::make_tuple(
|
||||
std::make_tuple(block_main, matrix_construct.i0, matrix_construct.j0,
|
||||
std::make_tuple(block_main, i0, j0,
|
||||
matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ), -1),
|
||||
std::make_tuple(block_top_left_corner, 0, 0,
|
||||
matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ), -1),
|
||||
|
|
@ -164,20 +170,20 @@ void test_static_block_extraction(rotgen::tests::static_matrix_block_test_case<M
|
|||
matrix_construct.nj, int(NI), int(NJ), -1),
|
||||
|
||||
std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), int(NI), rotgen::Dynamic, -1),
|
||||
std::make_tuple(block_middle_rows, matrix_construct.i0, 0, matrix_construct.ni,
|
||||
std::make_tuple(block_middle_rows, i0, 0, matrix_construct.ni,
|
||||
matrix.cols(), int(NI), rotgen::Dynamic, -1),
|
||||
std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni,
|
||||
0, matrix_construct.ni, matrix.cols(), int(NI), rotgen::Dynamic, -1),
|
||||
|
||||
std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ), -1),
|
||||
std::make_tuple(block_middle_cols, 0, matrix_construct.j0,
|
||||
std::make_tuple(block_middle_cols, 0, j0,
|
||||
matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ), -1),
|
||||
std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj,
|
||||
matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ), -1),
|
||||
|
||||
std::make_tuple(block_row, matrix_construct.i0, 0,
|
||||
std::make_tuple(block_row, i0, 0,
|
||||
1, matrix.cols(), 1, rotgen::Dynamic, 1),
|
||||
std::make_tuple(block_col, 0, matrix_construct.j0,
|
||||
std::make_tuple(block_col, 0, j0,
|
||||
matrix.rows(), 1, rotgen::Dynamic, 1, 0)
|
||||
);
|
||||
|
||||
|
|
@ -205,16 +211,15 @@ TTS_CASE_TPL("Check all dynamic block extractions on a dynamic row-major matrix"
|
|||
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value, 1>;
|
||||
|
||||
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> cases = {
|
||||
{ 6, 11, [](rotgen::Index i, rotgen::Index j) { return T(i * 10 + j); }, 1, 2, 3, 2 },
|
||||
{ 7, 10, [](rotgen::Index i, rotgen::Index j) { return T(std::sin(i + j)); }, 4, 4, 3, 3 },
|
||||
{ 5, 5, [](rotgen::Index i, rotgen::Index j) { return T((i + j) % 7); }, 0, 0, 5, 5 },
|
||||
{ 9, 14, [](rotgen::Index i, rotgen::Index j) { return T(i+j + 3*j); }, 3, 7, 1, 1 }
|
||||
{ {6, 11, [](rotgen::Index i, rotgen::Index j) { return T(i * 10 + j); }}, 1, 2, 3, 2 },
|
||||
{ {7, 10, [](rotgen::Index i, rotgen::Index j) { return T(std::sin(i + j)); }}, 4, 4, 3, 3 },
|
||||
{ {5, 5, [](rotgen::Index i, rotgen::Index j) { return T((i + j) % 7); }}, 0, 0, 5, 5 },
|
||||
{ {9, 14, [](rotgen::Index i, rotgen::Index j) { return T(i+j + 3*j); }}, 3, 7, 1, 1 }
|
||||
};
|
||||
|
||||
for (auto const& matrix_case : cases) {
|
||||
test_dynamic_block_extraction<mat_t, T>(matrix_case);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Check all dynamic block extractions on a static column-major matrix", rotgen::tests::types)
|
||||
|
|
@ -223,9 +228,9 @@ TTS_CASE_TPL("Check all dynamic block extractions on a static column-major matri
|
|||
using mat_t = rotgen::matrix<T,4,5,O::value, 0>;
|
||||
|
||||
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> cases = {
|
||||
{ 4, 5, [](auto i, auto j) { return T(2*i + j*j*j - 42); }, 1, 2, 3, 2 },
|
||||
{ 4, 5, [](auto i, auto j) { return T(std::tan(i*i*j)); }, 0, 1, 2, 1 },
|
||||
{ 4, 5, [](auto i, auto j) { return T((i*i + j*j) / 6); }, 2, 0, 0, 0 }
|
||||
{ {4, 5, [](auto i, auto j) { return T(2*i + j*j*j - 42); } }, 1, 2, 3, 2 },
|
||||
{ {4, 5, [](auto i, auto j) { return T(std::tan(i*i*j)); } }, 0, 1, 2, 1 },
|
||||
{ {4, 5, [](auto i, auto j) { return T((i*i + j*j) / 6); } }, 2, 0, 0, 0 }
|
||||
};
|
||||
|
||||
for (auto const& matrix_case : cases) {
|
||||
|
|
@ -241,24 +246,21 @@ TTS_CASE_TPL("Check all static block extractions", rotgen::tests::types)
|
|||
|
||||
test_static_block_extraction<mat_t, T, 1, 2>(
|
||||
rotgen::tests::static_matrix_block_test_case<mat_t, 1, 2>{
|
||||
11, 11,
|
||||
[](rotgen::Index i, rotgen::Index j) { return T(i*i*i + 3*j - 127); },
|
||||
{11, 11, [](rotgen::Index i, rotgen::Index j) { return T(i*i*i + 3*j - 127); } },
|
||||
3, 2
|
||||
}
|
||||
);
|
||||
|
||||
test_static_block_extraction<mat_t, double, 4, 3>(
|
||||
rotgen::tests::static_matrix_block_test_case<mat_t, 4, 3>{
|
||||
14, 15,
|
||||
[](rotgen::Index i, rotgen::Index j) { return T(std::cos(i * j * 2)); },
|
||||
{14, 15,[](rotgen::Index i, rotgen::Index j) { return T(std::cos(i * j * 2)); }},
|
||||
5, 1
|
||||
}
|
||||
);
|
||||
|
||||
test_static_block_extraction<mat_t, double, 0, 0>(
|
||||
rotgen::tests::static_matrix_block_test_case<mat_t, 0, 0>{
|
||||
5, 5,
|
||||
[](rotgen::Index i, rotgen::Index j) { return T((i + j) % 9); },
|
||||
{5, 5,[](rotgen::Index i, rotgen::Index j) { return T((i + j) % 9); }},
|
||||
0, 0
|
||||
}
|
||||
);
|
||||
|
|
|
|||
268
test/unit/block/generators.cpp
Normal file
268
test/unit/block/generators.cpp
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
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, auto value
|
||||
, rotgen::Index i0, rotgen::Index j0
|
||||
, rotgen::Index rows, rotgen::Index cols
|
||||
)
|
||||
{
|
||||
for(rotgen::Index r=0;r<rows;++r)
|
||||
for(rotgen::Index c=0;c<cols;++c)
|
||||
TTS_EQUAL(matrix(i0+r, j0+c), value);
|
||||
}
|
||||
|
||||
void test_identity( const auto& matrix
|
||||
, rotgen::Index i0, rotgen::Index j0
|
||||
, rotgen::Index rows, rotgen::Index cols
|
||||
)
|
||||
{
|
||||
for(rotgen::Index r=0;r<rows;++r)
|
||||
for(rotgen::Index c=0;c<cols;++c)
|
||||
TTS_EQUAL(matrix(i0+r, j0+c), r==c ? 1 : 0);
|
||||
}
|
||||
|
||||
void test_random( const auto& matrix
|
||||
, rotgen::Index i0, rotgen::Index j0
|
||||
, rotgen::Index rows, rotgen::Index cols
|
||||
)
|
||||
{
|
||||
for(rotgen::Index r=0;r<rows;++r)
|
||||
for(rotgen::Index c=0;c<cols;++c)
|
||||
{
|
||||
TTS_GREATER_EQUAL(matrix(i0+r, j0+c), -1.0);
|
||||
TTS_LESS_EQUAL(matrix(i0+r, j0+c), 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
TTS_CASE_TPL("Test dynamic block::setZero", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>>)
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_block_references<T,O>();
|
||||
for (const auto& [matrix_desc, i0, j0, ni, nj] : cases)
|
||||
{
|
||||
auto[rows,cols,fn] = matrix_desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract(m, i0, j0, ni, nj);
|
||||
|
||||
input.setZero();
|
||||
test_value(m,T{0},i0,j0,ni,nj);
|
||||
|
||||
using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj));
|
||||
auto values = input_type::Zero(ni,nj);
|
||||
test_value(values,T{0},0,0,ni,nj);
|
||||
}
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test static block:setZero", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_static_block_references<T,O>();
|
||||
|
||||
auto process = []<typename D>(D const& d)
|
||||
{
|
||||
auto[desc,i0,j0] = d;
|
||||
auto[rows,cols,fn] = desc;
|
||||
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract<D::ni,D::nj>(m, i0, j0);
|
||||
|
||||
input.setZero();
|
||||
test_value(m,T{0},i0,j0,D::ni,D::nj);
|
||||
|
||||
using input_type = decltype(rotgen::extract<D::ni,D::nj>(m, i0, j0));
|
||||
auto values = input_type::Zero();
|
||||
test_value(values,T{0},0,0,D::ni,D::nj);
|
||||
};
|
||||
|
||||
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test dynamic block::setOnes", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>>)
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_block_references<T,O>();
|
||||
for (const auto& [matrix_desc, i0, j0, ni, nj] : cases)
|
||||
{
|
||||
auto[rows,cols,fn] = matrix_desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract(m, i0, j0, ni, nj);
|
||||
|
||||
input.setOnes();
|
||||
test_value(m,T{1},i0,j0,ni,nj);
|
||||
|
||||
using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj));
|
||||
auto values = input_type::Ones(ni,nj);
|
||||
test_value(values,T{1},0,0,ni,nj);
|
||||
}
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test static block:setOnes", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_static_block_references<T,O>();
|
||||
|
||||
auto process = []<typename D>(D const& d)
|
||||
{
|
||||
auto[desc,i0,j0] = d;
|
||||
auto[rows,cols,fn] = desc;
|
||||
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract<D::ni,D::nj>(m, i0, j0);
|
||||
|
||||
input.setOnes();
|
||||
test_value(m,T{1},i0,j0,D::ni,D::nj);
|
||||
|
||||
using input_type = decltype(rotgen::extract<D::ni,D::nj>(m, i0, j0));
|
||||
auto values = input_type::Ones();
|
||||
test_value(values,T{1},0,0,D::ni,D::nj);
|
||||
};
|
||||
|
||||
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test dynamic block::setConstant", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>>)
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_block_references<T,O>();
|
||||
for (const auto& [matrix_desc, i0, j0, ni, nj] : cases)
|
||||
{
|
||||
auto[rows,cols,fn] = matrix_desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract(m, i0, j0, ni, nj);
|
||||
|
||||
input.setConstant(T{13.37f});
|
||||
test_value(m,T{13.37f},i0,j0,ni,nj);
|
||||
|
||||
using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj));
|
||||
auto values = input_type::Constant(ni,nj,T{13.37f});
|
||||
test_value(values,T{13.37f},0,0,ni,nj);
|
||||
}
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test static block:setConstant", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_static_block_references<T,O>();
|
||||
|
||||
auto process = []<typename D>(D const& d)
|
||||
{
|
||||
auto[desc,i0,j0] = d;
|
||||
auto[rows,cols,fn] = desc;
|
||||
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract<D::ni,D::nj>(m, i0, j0);
|
||||
|
||||
input.setConstant(T{13.37f});
|
||||
test_value(m,T{13.37f},i0,j0,D::ni,D::nj);
|
||||
|
||||
using input_type = decltype(rotgen::extract<D::ni,D::nj>(m, i0, j0));
|
||||
auto values = input_type::Constant(T{13.37f});
|
||||
test_value(values,T{13.37f},0,0,D::ni,D::nj);
|
||||
};
|
||||
|
||||
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test dynamic block::setIdentity", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>>)
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_block_references<T,O>();
|
||||
for (const auto& [matrix_desc, i0, j0, ni, nj] : cases)
|
||||
{
|
||||
auto[rows,cols,fn] = matrix_desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract(m, i0, j0, ni, nj);
|
||||
|
||||
input.setIdentity();
|
||||
test_identity(m,i0,j0,ni,nj);
|
||||
|
||||
using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj));
|
||||
auto values = input_type::Identity(ni,nj);
|
||||
test_identity(values,0,0,ni,nj);
|
||||
}
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test static block:setIdentity", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_static_block_references<T,O>();
|
||||
|
||||
auto process = []<typename D>(D const& d)
|
||||
{
|
||||
auto[desc,i0,j0] = d;
|
||||
auto[rows,cols,fn] = desc;
|
||||
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract<D::ni,D::nj>(m, i0, j0);
|
||||
|
||||
input.setIdentity();
|
||||
test_identity(m,i0,j0,D::ni,D::nj);
|
||||
|
||||
using input_type = decltype(rotgen::extract<D::ni,D::nj>(m, i0, j0));
|
||||
auto values = input_type::Identity();
|
||||
test_identity(values,0,0,D::ni,D::nj);
|
||||
};
|
||||
|
||||
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test dynamic block::setRandom", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>>)
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_block_references<T,O>();
|
||||
for (const auto& [matrix_desc, i0, j0, ni, nj] : cases)
|
||||
{
|
||||
auto[rows,cols,fn] = matrix_desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract(m, i0, j0, ni, nj);
|
||||
|
||||
input.setRandom();
|
||||
test_random(m,i0,j0,ni,nj);
|
||||
|
||||
using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj));
|
||||
auto values = input_type::Random(ni,nj);
|
||||
test_random(values,0,0,ni,nj);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TTS_CASE_TPL("Test static block:setRandom", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_static_block_references<T,O>();
|
||||
|
||||
auto process = []<typename D>(D const& d)
|
||||
{
|
||||
auto[desc,i0,j0] = d;
|
||||
auto[rows,cols,fn] = desc;
|
||||
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract<D::ni,D::nj>(m, i0, j0);
|
||||
|
||||
input.setRandom();
|
||||
test_random(m,i0,j0,D::ni,D::nj);
|
||||
|
||||
using input_type = decltype(rotgen::extract<D::ni,D::nj>(m, i0, j0));
|
||||
auto values = input_type::Random();
|
||||
test_random(values,0,0,D::ni,D::nj);
|
||||
};
|
||||
|
||||
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||
};
|
||||
|
|
@ -6,43 +6,37 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#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 block norm 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, [](rotgen::Index r, rotgen::Index c) {return r + c; }, 1, 2, 3, 2},
|
||||
{9, 11, [](rotgen::Index r, rotgen::Index c) {return r + c; }, 0, 1, 4, 9},
|
||||
{3, 3, [](rotgen::Index , rotgen::Index ) {return 0.0; }, 1, 1, 1, 1},
|
||||
{1, 4, [](rotgen::Index r, rotgen::Index c) {return -r -c*c - 1234; }, 0, 0, 1, 1},
|
||||
{4, 1, [](rotgen::Index , rotgen::Index ) {return 7.0; }, 2, 0, 2, 1},
|
||||
{1, 1, [](rotgen::Index , rotgen::Index ) {return 42.0; }, 0, 0, 1, 1},
|
||||
{12, 13, [](rotgen::Index r, rotgen::Index c) {return std::sin(r + c); }, 2, 3, 4, 5 },
|
||||
{4, 9, [](rotgen::Index r, rotgen::Index c) {return -1.5 * r + 2.56 * c; }, 0, 1, 2, 3 },
|
||||
{2, 5, [](rotgen::Index r, rotgen::Index c) {return (r == c ? 1.0 : 0.0); }, 1, 1, 1, 1},
|
||||
};
|
||||
|
||||
for (const auto& [rows, cols, fn, i0, j0, ni, nj] : test_cases)
|
||||
auto const cases = rotgen::tests::generate_block_references<T,O>();
|
||||
for (const auto& [matrix_desc, i0, j0, ni, nj] : 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 (rotgen::Index r = 0; r < rows; ++r)
|
||||
for (rotgen::Index 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>());
|
||||
auto[rows,cols,fn] = matrix_desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract(m, i0, j0, ni, nj);
|
||||
rotgen::tests::check_norms_functions(input);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Test static block norm operations", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
auto const cases = rotgen::tests::generate_static_block_references<T,O>();
|
||||
|
||||
auto process = []<typename D>(D const& d)
|
||||
{
|
||||
auto[desc,i0,j0] = d;
|
||||
auto[rows,cols,fn] = desc;
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||
rotgen::tests::prepare(rows,cols,fn,m);
|
||||
auto input = rotgen::extract<D::ni,D::nj>(m, i0, j0);
|
||||
rotgen::tests::check_norms_functions(input);
|
||||
};
|
||||
|
||||
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,51 +15,50 @@ void test_block_matrix_operations(rotgen::tests::matrix_block_test_case<MatrixTy
|
|||
{
|
||||
using EigenMatrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
|
||||
|
||||
MatrixType a(matrix_construct.rows, matrix_construct.cols);
|
||||
MatrixType b(matrix_construct.rows, matrix_construct.cols);
|
||||
EigenMatrix ref_a(matrix_construct.rows, matrix_construct.cols);
|
||||
EigenMatrix ref_b(matrix_construct.rows, matrix_construct.cols);
|
||||
auto[d,i0,j0,ni,nj] = matrix_construct;
|
||||
auto[r,c,fn] = d;
|
||||
|
||||
MatrixType a(r, c);
|
||||
MatrixType b(r, c);
|
||||
EigenMatrix ref_a(r, c);
|
||||
EigenMatrix ref_b(r, c);
|
||||
|
||||
TTS_EXPECT(verify_rotgen_reentrance(ops(a,b)));
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index rr = 0; rr < r; ++rr)
|
||||
{
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
for (rotgen::Index cc = 0; cc < c; ++cc)
|
||||
{
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
|
||||
ref_b(r,c) = b(r,c) = static_cast<T>(b_init_fn(r, c));
|
||||
ref_a(rr,cc) = a(rr,cc) = static_cast<T>(fn(rr,cc));
|
||||
ref_b(rr,cc) = b(rr,cc) = static_cast<T>(b_init_fn(rr,cc));
|
||||
}
|
||||
}
|
||||
|
||||
auto a_block = rotgen::extract(a, matrix_construct.i0, matrix_construct.j0,
|
||||
matrix_construct.ni, matrix_construct.nj);
|
||||
auto b_block = rotgen::extract(b, matrix_construct.i0, matrix_construct.j0,
|
||||
matrix_construct.ni, matrix_construct.nj);
|
||||
auto ref_a_block = ref_a.block(matrix_construct.i0, matrix_construct.j0,
|
||||
matrix_construct.ni, matrix_construct.nj);
|
||||
auto ref_b_block = ref_b.block(matrix_construct.i0, matrix_construct.j0,
|
||||
matrix_construct.ni, matrix_construct.nj);
|
||||
auto a_block = rotgen::extract(a, i0, j0,ni, nj);
|
||||
auto b_block = rotgen::extract(b, i0, j0,ni, nj);
|
||||
auto ref_a_block = ref_a.block(i0, j0,ni, nj);
|
||||
auto ref_b_block = ref_b.block(i0, j0,ni, nj);
|
||||
|
||||
auto result_block = ops(a_block, b_block);
|
||||
auto ref_result_block = ops(ref_a_block, ref_b_block);
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
TTS_EQUAL(result_block(r, c), ref_result_block(r, c));
|
||||
for (rotgen::Index rr = 0; rr < ni; ++rr)
|
||||
for (rotgen::Index cc = 0; cc < nj; ++cc)
|
||||
TTS_EQUAL(result_block(rr, cc), ref_result_block(rr, cc));
|
||||
|
||||
self_ops(a_block,b_block);
|
||||
self_ops(ref_a_block, ref_b_block);
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
|
||||
for (rotgen::Index rr = 0; rr < ni; ++rr)
|
||||
for (rotgen::Index cc = 0; cc < nj; ++cc)
|
||||
TTS_EQUAL(a_block(rr, cc), ref_a_block(rr, cc));
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index rr = 0; rr < ni; ++rr)
|
||||
{
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
for (rotgen::Index cc = 0; cc < nj; ++cc)
|
||||
{
|
||||
TTS_EQUAL(a(r, c), ref_a(r, c));
|
||||
TTS_EQUAL(b(r, c), ref_b(r, c));
|
||||
TTS_EQUAL(a(rr, cc), ref_a(rr, cc));
|
||||
TTS_EQUAL(b(rr, cc), ref_b(rr, cc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -70,36 +69,37 @@ void test_block_scalar_operations(rotgen::tests::matrix_block_test_case<MatrixTy
|
|||
{
|
||||
using EigenMatrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
|
||||
|
||||
MatrixType a(matrix_construct.rows, matrix_construct.cols);
|
||||
EigenMatrix ref_a(matrix_construct.rows, matrix_construct.cols);
|
||||
auto[d,i0,j0,ni,nj] = matrix_construct;
|
||||
auto[rows,cols,fn] = d;
|
||||
|
||||
MatrixType a(rows, cols);
|
||||
EigenMatrix ref_a(rows, cols);
|
||||
|
||||
TTS_EXPECT(verify_rotgen_reentrance(ops(a,scalar)));
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
|
||||
for (rotgen::Index r = 0; r < rows; ++r)
|
||||
for (rotgen::Index c = 0; c < cols; ++c)
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(fn(r, c));
|
||||
|
||||
auto a_block = rotgen::extract(a, matrix_construct.i0, matrix_construct.j0,
|
||||
matrix_construct.ni, matrix_construct.nj);
|
||||
auto ref_a_block = ref_a.block(matrix_construct.i0, matrix_construct.j0,
|
||||
matrix_construct.ni, matrix_construct.nj);
|
||||
auto a_block = rotgen::extract(a, i0, j0,ni, nj);
|
||||
auto ref_a_block = ref_a.block(i0, j0,ni, nj);
|
||||
|
||||
auto result = ops(a_block, scalar);
|
||||
auto ref_result = ops(ref_a_block, scalar);
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < ni; ++r)
|
||||
for (rotgen::Index c = 0; c < nj; ++c)
|
||||
TTS_EQUAL(result(r, c), ref_result(r, c));
|
||||
|
||||
self_ops(a_block,scalar);
|
||||
self_ops(ref_a_block, scalar);
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < ni; ++r)
|
||||
for (rotgen::Index c = 0; c < nj; ++c)
|
||||
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < rows; ++r)
|
||||
for (rotgen::Index c = 0; c < cols; ++c)
|
||||
TTS_EQUAL(a(r, c), ref_a(r, c));
|
||||
}
|
||||
|
||||
|
|
@ -109,29 +109,32 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
|
|||
{
|
||||
using EigenMatrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
|
||||
|
||||
MatrixType a(matrix_construct.rows, matrix_construct.cols);
|
||||
EigenMatrix ref_a(matrix_construct.rows, matrix_construct.cols);
|
||||
auto[d,i0,j0,ni,nj] = matrix_construct;
|
||||
auto[rows,cols,fn] = d;
|
||||
|
||||
MatrixType a(rows, cols);
|
||||
EigenMatrix ref_a(rows, cols);
|
||||
|
||||
TTS_EXPECT(verify_rotgen_reentrance(a * scalar));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(scalar * a));
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
|
||||
for (rotgen::Index r = 0; r < rows; ++r)
|
||||
for (rotgen::Index c = 0; c < cols; ++c)
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(fn(r, c));
|
||||
|
||||
auto a_block = rotgen::extract(a, matrix_construct.i0, matrix_construct.j0,
|
||||
matrix_construct.ni, matrix_construct.nj);
|
||||
auto ref_a_block = ref_a.block(matrix_construct.i0, matrix_construct.j0,
|
||||
matrix_construct.ni, matrix_construct.nj);
|
||||
auto a_block = rotgen::extract(a, i0, j0,
|
||||
ni, nj);
|
||||
auto ref_a_block = ref_a.block(i0, j0,
|
||||
ni, nj);
|
||||
|
||||
auto a_scalar_multiplication = a_block * scalar;
|
||||
auto scalar_a_multiplication = scalar * a_block;
|
||||
auto a_scalar_multiplication_ref = ref_a_block * scalar;
|
||||
auto scalar_a_multiplication_ref = scalar * ref_a_block;
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index r = 0; r < ni; ++r)
|
||||
{
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
for (rotgen::Index c = 0; c < nj; ++c)
|
||||
{
|
||||
TTS_EQUAL(a_scalar_multiplication (r, c), a_scalar_multiplication_ref(r, c));
|
||||
TTS_EQUAL(scalar_a_multiplication(r, c), scalar_a_multiplication_ref(r, c));
|
||||
|
|
@ -141,12 +144,12 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
|
|||
a_block *= scalar;
|
||||
ref_a_block *= scalar;
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < ni; ++r)
|
||||
for (rotgen::Index c = 0; c < nj; ++c)
|
||||
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < rows; ++r)
|
||||
for (rotgen::Index c = 0; c < cols; ++c)
|
||||
TTS_EQUAL(a(r, c), ref_a(r, c));
|
||||
}
|
||||
|
||||
|
|
@ -156,51 +159,54 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case<MatrixType>
|
|||
{
|
||||
using EigenMatrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
|
||||
|
||||
MatrixType a(a_matrix_construct.rows, a_matrix_construct.cols);
|
||||
MatrixType b(b_matrix_construct.rows, b_matrix_construct.cols);
|
||||
EigenMatrix ref_a(a_matrix_construct.rows, a_matrix_construct.cols);
|
||||
EigenMatrix ref_b(b_matrix_construct.rows, b_matrix_construct.cols);
|
||||
auto[a_d,a_i0,a_j0,a_ni,a_nj] = a_matrix_construct;
|
||||
auto[a_rows,a_cols,a_fn] = a_d;
|
||||
|
||||
for (rotgen::Index r = 0; r < a_matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < a_matrix_construct.cols; ++c)
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(a_matrix_construct.init_fn(r, c));
|
||||
|
||||
for (rotgen::Index r = 0; r < b_matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < b_matrix_construct.cols; ++c)
|
||||
ref_b(r,c) = b(r,c) = static_cast<T>(b_matrix_construct.init_fn(r, c));
|
||||
auto[b_d,b_i0,b_j0,b_ni,b_nj] = b_matrix_construct;
|
||||
auto[b_rows,b_cols,b_fn] = b_d;
|
||||
|
||||
|
||||
auto a_block = rotgen::extract(a, a_matrix_construct.i0, a_matrix_construct.j0,
|
||||
a_matrix_construct.ni, a_matrix_construct.nj);
|
||||
auto b_block = rotgen::extract(b, b_matrix_construct.i0, b_matrix_construct.j0,
|
||||
b_matrix_construct.ni, b_matrix_construct.nj);
|
||||
auto ref_a_block = ref_a.block(a_matrix_construct.i0, a_matrix_construct.j0,
|
||||
a_matrix_construct.ni, a_matrix_construct.nj);
|
||||
auto ref_b_block = ref_b.block(b_matrix_construct.i0, b_matrix_construct.j0,
|
||||
b_matrix_construct.ni, b_matrix_construct.nj);
|
||||
MatrixType a(a_rows, a_cols);
|
||||
MatrixType b(b_rows, b_cols);
|
||||
EigenMatrix ref_a(a_rows, a_cols);
|
||||
EigenMatrix ref_b(b_rows, b_cols);
|
||||
|
||||
for (rotgen::Index r = 0; r < a_rows; ++r)
|
||||
for (rotgen::Index c = 0; c < a_cols; ++c)
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(a_fn(r, c));
|
||||
|
||||
for (rotgen::Index r = 0; r < b_rows; ++r)
|
||||
for (rotgen::Index c = 0; c < b_cols; ++c)
|
||||
ref_b(r,c) = b(r,c) = static_cast<T>(b_fn(r, c));
|
||||
|
||||
|
||||
auto a_block = rotgen::extract(a, a_i0, a_j0,a_ni, a_nj);
|
||||
auto b_block = rotgen::extract(b, b_i0, b_j0,b_ni, b_nj);
|
||||
auto ref_a_block = ref_a.block(a_i0, a_j0,a_ni, a_nj);
|
||||
auto ref_b_block = ref_b.block(b_i0, b_j0,b_ni, b_nj);
|
||||
|
||||
TTS_EXPECT(verify_rotgen_reentrance(a_block * b_block));
|
||||
|
||||
auto a_b_product_original = a_block * b_block;
|
||||
auto a_b_product_ref = ref_a_block * ref_b_block;
|
||||
|
||||
for (rotgen::Index r = 0; r < a_matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < a_matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < a_ni; ++r)
|
||||
for (rotgen::Index c = 0; c < a_nj; ++c)
|
||||
TTS_EQUAL(a_b_product_original (r, c), a_b_product_ref(r, c));
|
||||
|
||||
a_block *= b_block;
|
||||
ref_a_block *= ref_b_block;
|
||||
|
||||
for (rotgen::Index r = 0; r < a_matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < a_matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < a_ni; ++r)
|
||||
for (rotgen::Index c = 0; c < a_nj; ++c)
|
||||
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
|
||||
|
||||
for (rotgen::Index r = 0; r < a_matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < a_matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < a_rows; ++r)
|
||||
for (rotgen::Index c = 0; c < a_cols; ++c)
|
||||
TTS_EQUAL(a(r, c), ref_a(r, c));
|
||||
|
||||
for (rotgen::Index r = 0; r < b_matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < b_matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < b_rows; ++r)
|
||||
for (rotgen::Index c = 0; c < b_cols; ++c)
|
||||
TTS_EQUAL(b(r, c), ref_b(r, c));
|
||||
}
|
||||
|
||||
|
|
@ -216,18 +222,17 @@ TTS_CASE_TPL("Check block addition", rotgen::tests::types)
|
|||
auto op = [](auto a, auto b) { return a + b; };
|
||||
auto s_op = [](auto& a, auto b) { return a += b; };
|
||||
|
||||
test_block_matrix_operations<mat_t, T>({1 , 1, init_a, 0, 0, 1, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({13 , 15, init_a, 1, 2, 3, 4}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({5 , 9, init_a, 2, 2, 2, 2}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({15 , 15, init_a, 3, 4, 5, 5}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({5 , 5, init_b, 1, 0, 3, 2}, init_a, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({10, 1, init_a, 0, 0, 5, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({1 , 10, init_a, 0, 0, 1, 5}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({21 , 5, init_0, 4, 4, 10, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({11 , 7, init_a, 2, 0, 7, 5}, init_0, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{ 1, 1, init_a}, 0, 0, 1, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{13, 15, init_a}, 1, 2, 3, 4}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{ 5, 9, init_a}, 2, 2, 2, 2}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{15, 15, init_a}, 3, 4, 5, 5}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{ 5, 5, init_b}, 1, 0, 3, 2}, init_a, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{10, 1, init_a}, 0, 0, 5, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{ 1, 10, init_a}, 0, 0, 1, 5}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{21, 5, init_0}, 4, 4, 10, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{11, 7, init_a}, 2, 0, 7, 5}, init_0, op, s_op);
|
||||
};
|
||||
|
||||
|
||||
TTS_CASE_TPL("Check block subtraction", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
{
|
||||
|
|
@ -235,36 +240,35 @@ TTS_CASE_TPL("Check block subtraction", rotgen::tests::types)
|
|||
auto op = [](auto a, auto b) { return a - b; };
|
||||
auto s_op = [](auto& a, auto b) { return a -= b; };
|
||||
|
||||
test_block_matrix_operations<mat_t, T>({1 , 1, init_a, 0, 0, 1, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({1 , 1, init_a, 0, 0, 1, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({13 , 15, init_a, 1, 2, 3, 4}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({5 , 9, init_a, 2, 2, 2, 2}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({15 , 15, init_a, 3, 4, 5, 5}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({5 , 5, init_b, 1, 0, 3, 2}, init_a, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({10, 1, init_a, 0, 0, 5, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({1 , 10, init_a, 0, 0, 1, 5}, init_b,op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({21 , 5, init_0, 4, 4, 10, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({11 , 7, init_a, 2, 0, 7, 5}, init_0, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{ 1, 1, init_a}, 0, 0, 1, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{ 1, 1, init_a}, 0, 0, 1, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{13, 15, init_a}, 1, 2, 3, 4}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{ 5, 9, init_a}, 2, 2, 2, 2}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{15, 15, init_a}, 3, 4, 5, 5}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{ 5, 5, init_b}, 1, 0, 3, 2}, init_a, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{10, 1, init_a}, 0, 0, 5, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{ 1, 10, init_a}, 0, 0, 1, 5}, init_b,op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{21 , 5, init_0}, 4, 4, 10, 1}, init_b, op, s_op);
|
||||
test_block_matrix_operations<mat_t, T>({{11 , 7, init_a}, 2, 0, 7, 5}, init_0, op, s_op);
|
||||
};
|
||||
|
||||
|
||||
TTS_CASE_TPL("Check block multiplications", 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>;
|
||||
auto init_id = [](rotgen::Index r, rotgen::Index c) { return r == c ? 1 : 0; };
|
||||
|
||||
test_block_multiplication<mat_t, T>({1 , 1, init_a, 0, 0, 1, 1}, {1 , 1, init_b, 0, 0, 1, 1});
|
||||
test_block_multiplication<mat_t, T>({13 , 15, init_b, 1, 2, 4, 4}, {13 , 15, init_b, 0, 1, 4, 4});
|
||||
test_block_multiplication<mat_t, T>({6 , 9, init_a, 2, 2, 2, 2}, {5 , 9, init_b, 2, 2, 2, 2});
|
||||
test_block_multiplication<mat_t, T>({15 , 15, init_a, 3, 4, 5, 5}, {15 , 15, init_b, 0, 0, 5, 5});
|
||||
test_block_multiplication<mat_t, T>({5 , 5, init_b, 1, 0, 3, 3}, {5 , 5, init_a, 0, 0, 3, 3});
|
||||
test_block_multiplication<mat_t, T>({11 , 3, init_id, 2, 0, 2, 2}, {18 , 7, init_a, 2, 0, 2, 2});
|
||||
test_block_multiplication<mat_t, T>({10, 1, init_a, 0, 0, 1, 1}, {10, 1, init_a, 0, 0, 1, 1});
|
||||
test_block_multiplication<mat_t, T>({1 , 10, init_a, 0, 0, 1, 1}, {1 , 10, init_id, 0, 0, 1, 1});
|
||||
test_block_multiplication<mat_t, T>({21 , 5, init_0, 1, 1, 3, 3}, {12 , 7, init_0, 4, 4, 3, 3});
|
||||
test_block_multiplication<mat_t, T>({11 , 7, init_a, 2, 0, 7, 7}, {11 , 11, init_a, 2, 1, 7, 7});
|
||||
test_block_multiplication<mat_t, T>({11 , 7, init_a, 2, 0, 5, 5}, {11 , 12, init_id, 0, 0, 5, 5});
|
||||
test_block_multiplication<mat_t, T>({{ 1, 1, init_a }, 0, 0, 1, 1}, {{ 1, 1, init_b }, 0, 0, 1, 1});
|
||||
test_block_multiplication<mat_t, T>({{13, 15, init_b }, 1, 2, 4, 4}, {{13, 15, init_b }, 0, 1, 4, 4});
|
||||
test_block_multiplication<mat_t, T>({{ 6, 9, init_a }, 2, 2, 2, 2}, {{ 5, 9, init_b }, 2, 2, 2, 2});
|
||||
test_block_multiplication<mat_t, T>({{15, 15, init_a }, 3, 4, 5, 5}, {{15, 15, init_b }, 0, 0, 5, 5});
|
||||
test_block_multiplication<mat_t, T>({{ 5, 5, init_b }, 1, 0, 3, 3}, {{ 5, 5, init_a }, 0, 0, 3, 3});
|
||||
test_block_multiplication<mat_t, T>({{11, 3, init_id}, 2, 0, 2, 2}, {{18, 7, init_a }, 2, 0, 2, 2});
|
||||
test_block_multiplication<mat_t, T>({{10, 1, init_a }, 0, 0, 1, 1}, {{10, 1, init_a }, 0, 0, 1, 1});
|
||||
test_block_multiplication<mat_t, T>({{ 1, 10, init_a }, 0, 0, 1, 1}, {{ 1, 10, init_id}, 0, 0, 1, 1});
|
||||
test_block_multiplication<mat_t, T>({{21, 5, init_0 }, 1, 1, 3, 3}, {{12, 7, init_0 }, 4, 4, 3, 3});
|
||||
test_block_multiplication<mat_t, T>({{11, 7, init_a }, 2, 0, 7, 7}, {{11, 11, init_a }, 2, 1, 7, 7});
|
||||
test_block_multiplication<mat_t, T>({{11, 7, init_a }, 2, 0, 5, 5}, {{11, 12, init_id}, 0, 0, 5, 5});
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Check block multiplication with scalar", rotgen::tests::types)
|
||||
|
|
@ -272,15 +276,15 @@ TTS_CASE_TPL("Check block multiplication with scalar", rotgen::tests::types)
|
|||
{
|
||||
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
||||
|
||||
test_scalar_block_multiplications<mat_t, T>({1 , 1, init_a, 0, 0, 1, 1}, T{ 3.5});
|
||||
test_scalar_block_multiplications<mat_t, T>({13 , 15, init_a, 1, 2, 3, 4}, T{ 0.});
|
||||
test_scalar_block_multiplications<mat_t, T>({5 , 9, init_a, 2, 2, 2, 2}, T{-2.5});
|
||||
test_scalar_block_multiplications<mat_t, T>({15 , 15, init_a, 3, 4, 5, 5}, T{ 42. });
|
||||
test_scalar_block_multiplications<mat_t, T>({5 , 5, init_b, 1, 0, 3, 2}, T{-5. });
|
||||
test_scalar_block_multiplications<mat_t, T>({10, 1, init_a, 0, 0, 5, 1}, T{ 1. });
|
||||
test_scalar_block_multiplications<mat_t, T>({1 , 10, init_a, 0, 0, 1, 5}, T{ 6. });
|
||||
test_scalar_block_multiplications<mat_t, T>({21 , 5, init_0, 4, 4, 10, 1}, T{ 10.1});
|
||||
test_scalar_block_multiplications<mat_t, T>({11 , 7, init_a, 2, 0, 7, 5}, T{-0.5});
|
||||
test_scalar_block_multiplications<mat_t, T>({{ 1, 1, init_a}, 0, 0, 1, 1}, T{ 3.5});
|
||||
test_scalar_block_multiplications<mat_t, T>({{13, 15, init_a}, 1, 2, 3, 4}, T{ 0.});
|
||||
test_scalar_block_multiplications<mat_t, T>({{ 5 , 9, init_a}, 2, 2, 2, 2}, T{-2.5});
|
||||
test_scalar_block_multiplications<mat_t, T>({{15, 15, init_a}, 3, 4, 5, 5}, T{ 42. });
|
||||
test_scalar_block_multiplications<mat_t, T>({{ 5, 5, init_b}, 1, 0, 3, 2}, T{-5. });
|
||||
test_scalar_block_multiplications<mat_t, T>({{10, 1, init_a}, 0, 0, 5, 1}, T{ 1. });
|
||||
test_scalar_block_multiplications<mat_t, T>({{ 1, 10, init_a}, 0, 0, 1, 5}, T{ 6. });
|
||||
test_scalar_block_multiplications<mat_t, T>({{21, 5, init_0}, 4, 4, 10, 1}, T{ 10.1});
|
||||
test_scalar_block_multiplications<mat_t, T>({{11, 7, init_a}, 2, 0, 7, 5}, T{-0.5});
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Check block division with scalar", rotgen::tests::types)
|
||||
|
|
@ -290,13 +294,14 @@ TTS_CASE_TPL("Check block division with scalar", rotgen::tests::types)
|
|||
auto op = [](auto a, auto b) { return a / b; };
|
||||
auto s_op = [](auto& a, auto b) { return a /= b; };
|
||||
|
||||
test_block_scalar_operations<mat_t, T>({1 , 1, init_a, 0, 0, 1, 1}, T{ 3.5}, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({13 , 15, init_a, 1, 2, 3, 4}, T{-2.5}, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({5 , 9, init_a, 2, 2, 2, 2}, T{ 42. }, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({15 , 15, init_a, 3, 4, 5, 5}, T{-5. }, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({5 , 5, init_b, 1, 0, 3, 2}, T{ 1. }, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({10, 1, init_a, 0, 0, 5, 1}, T{ 0. }, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({1 , 10, init_a, 0, 0, 1, 5}, T{ 6. }, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({21 , 5, init_0, 4, 4, 10, 1}, T{ 10.}, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({11 , 7, init_a, 2, 0, 7, 5}, T{-0.5}, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({{ 1, 1, init_a}, 0, 0, 1, 1}, T{ 3.5}, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({{13, 15, init_a}, 1, 2, 3, 4}, T{-2.5}, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({{ 5, 9, init_a}, 2, 2, 2, 2}, T{ 42. }, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({{15, 15, init_a}, 3, 4, 5, 5}, T{-5. }, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({{ 5, 5, init_b}, 1, 0, 3, 2}, T{ 1. }, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({{10, 1, init_a}, 0, 0, 5, 1}, T{ 0. }, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({{ 1, 10, init_a}, 0, 0, 1, 5}, T{ 6. }, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({{21, 5, init_0}, 4, 4, 10, 1}, T{ 10.}, op, s_op);
|
||||
test_block_scalar_operations<mat_t, T>({{11, 7, init_a}, 2, 0, 7, 5}, T{-0.5}, op, s_op);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,117 +0,0 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
void test_size(const auto& matrix, rotgen::Index rows, rotgen::Index cols)
|
||||
{
|
||||
TTS_EQUAL(matrix.rows(), rows);
|
||||
TTS_EQUAL(matrix.cols(), cols);
|
||||
TTS_EQUAL(matrix.size(), rows*cols);
|
||||
}
|
||||
|
||||
void test_value(const auto& matrix, rotgen::Index rows, rotgen::Index cols, auto constant)
|
||||
{
|
||||
TTS_EXPECT(verify_rotgen_reentrance(matrix));
|
||||
test_size(matrix, rows, cols);
|
||||
for(rotgen::Index r=0;r<rows;++r)
|
||||
for(rotgen::Index c=0;c<cols;++c)
|
||||
TTS_EQUAL(matrix(r, c), constant);
|
||||
}
|
||||
|
||||
void test_random(const auto& matrix, rotgen::Index rows, rotgen::Index cols)
|
||||
{
|
||||
TTS_EXPECT(verify_rotgen_reentrance(matrix));
|
||||
test_size(matrix, rows, cols);
|
||||
for(rotgen::Index r=0;r<rows;++r)
|
||||
for(rotgen::Index 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, rotgen::Index rows, rotgen::Index cols)
|
||||
{
|
||||
TTS_EXPECT(verify_rotgen_reentrance(matrix));
|
||||
test_size(matrix, rows, cols);
|
||||
for(rotgen::Index r=0;r<rows;++r)
|
||||
for(rotgen::Index 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