Adding clang-format configuration file and formatting all source files

Co-authored-by: Jules Pénuchot <jules@penuchot.com>
Co-authored-by: Joel FALCOU <jfalcou@codereckons.com>

See merge request oss/rotgen!41
This commit is contained in:
Jules Pénuchot 2025-10-14 16:19:03 +02:00
parent e92e824a18
commit 648dd768ee
94 changed files with 6778 additions and 4722 deletions

View file

@ -9,104 +9,104 @@
#include "unit/common/arithmetic.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic block transposition-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic block transposition-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 const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [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 [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>> )
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 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);
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);
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>> )
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 const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [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 [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>> )
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 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);
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);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};
TTS_CASE_TPL("Test dot product", float, double)<typename T>(tts::type<T>){
{auto v = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1,
16,
2);
auto a = rotgen::head(v, 8);
auto b = rotgen::tail(v, 8);
TTS_EQUAL(rotgen::dot(a, b), 32);
}
TTS_CASE_TPL("Test dot product", float, double)
<typename T>( tts::type<T> )
{
{
auto v = rotgen::setConstant<rotgen::matrix<T,1,rotgen::Dynamic>>(1,16,2);
auto a = rotgen::head(v,8);
auto b = rotgen::tail(v,8);
auto v = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(16, 1, 2);
auto a = rotgen::head(v, 8);
auto b = rotgen::tail(v, 8);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
auto v = rotgen::setConstant<rotgen::matrix<T,rotgen::Dynamic,1>>(16,1,2);
auto a = rotgen::head(v,8);
auto b = rotgen::tail(v,8);
{
auto v = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 16, 2);
auto a = rotgen::head<8>(v);
auto b = rotgen::tail<8>(v);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
auto v = rotgen::setConstant<rotgen::matrix<T,1,rotgen::Dynamic>>(1,16,2);
auto a = rotgen::head<8>(v);
auto b = rotgen::tail<8>(v);
{
auto v = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(16, 1, 2);
auto a = rotgen::head<8>(v);
auto b = rotgen::tail<8>(v);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
{
auto v = rotgen::setConstant<rotgen::matrix<T,rotgen::Dynamic,1>>(16,1,2);
auto a = rotgen::head<8>(v);
auto b = rotgen::tail<8>(v);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
};
TTS_EQUAL(rotgen::dot(a, b), 32);
}
}
;

View file

@ -12,109 +12,116 @@
// NB: This function must not be turned into a lambda, otherwise
// `test-ubuntu-gcc-release` will not pass and the CI will fail.
// This is likely due to a compilation bug from GCC 13.3.0.
void fill(auto &m, int r, int c, auto data[]) {
for (int k = 0; k < r * c; ++k)
m.data()[k] = data[k];
void fill(auto& m, int r, int c, auto data[])
{
for (int k = 0; k < r * c; ++k) m.data()[k] = data[k];
}
TTS_CASE_TPL("Function size", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
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};
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
// 1x12 dynamic block at (0,0)
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> dm(1,12);
fill(dm,1,12,data);
auto b1 = rotgen::block<decltype(dm), rotgen::Dynamic, rotgen::Dynamic>(dm, 0,0,1,12);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> dm(1, 12);
fill(dm, 1, 12, data);
auto b1 = rotgen::block<decltype(dm), rotgen::Dynamic, rotgen::Dynamic>(
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>(dm, 0,2,1,5);
auto b2 = rotgen::block<decltype(dm), rotgen::Dynamic, rotgen::Dynamic>(
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,data);
auto b3 = rotgen::block<decltype(dm2), rotgen::Dynamic, rotgen::Dynamic>(dm2, 1,4,3,2);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> dm2(4, 6);
fill(dm2, 4, 6, data);
auto b3 = rotgen::block<decltype(dm2), rotgen::Dynamic, rotgen::Dynamic>(
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,data);
auto b4 = rotgen::block<decltype(sm), 3, 4>(sm, 0,0);
rotgen::matrix<T, 3, 4, O::value> sm;
fill(sm, 3, 4, data);
auto b4 = rotgen::block<decltype(sm), 3, 4>(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,data);
auto b5 = rotgen::block<decltype(sm2), 6, 2>(sm2, 0,0);
rotgen::matrix<T, 6, 2, O::value> sm2;
fill(sm2, 6, 2, data);
auto b5 = rotgen::block<decltype(sm2), 6, 2>(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>> )
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>;
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];
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>(mat, 0, 0, 4, 3);
for(rotgen::Index i=0;i<4;i++)
auto b =
rotgen::block<base, rotgen::Dynamic, rotgen::Dynamic>(mat, 0, 0, 4, 3);
for (rotgen::Index i = 0; i < 4; i++)
{
for(rotgen::Index j=0;j<3;j++)
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]);
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);
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>> )
TTS_CASE_TPL("Test one index coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto vs = [&]()
{
if constexpr(O::value == rotgen::ColMajor)
auto vs = [&]() {
if constexpr (O::value == rotgen::ColMajor)
{
using base = rotgen::matrix<T,1,rotgen::Dynamic>;
using base = rotgen::matrix<T, 1, rotgen::Dynamic>;
base m(12);
for(int k=0;k<12;++k) m(k) = k+1;
return std::tuple{m,rotgen::block<base,1,rotgen::Dynamic>(m, 0, 0, 1, 12)};
for (int k = 0; k < 12; ++k) m(k) = k + 1;
return std::tuple{
m, rotgen::block<base, 1, rotgen::Dynamic>(m, 0, 0, 1, 12)};
}
else
{
using base = rotgen::matrix<T,rotgen::Dynamic,1>;
using base = rotgen::matrix<T, rotgen::Dynamic, 1>;
base m(12);
for(int k=0;k<12;++k) m(k) = k+1;
return std::tuple{m,rotgen::block<base,rotgen::Dynamic,1>(m, 0, 0, 12, 1)};
for (int k = 0; k < 12; ++k) m(k) = k + 1;
return std::tuple{
m, rotgen::block<base, rotgen::Dynamic, 1>(m, 0, 0, 12, 1)};
}
}();
auto mat = get<0>(vs);
auto b = get<1>(vs);
auto b = get<1>(vs);
TTS_EXPECT(b.IsVectorAtCompileTime);
for(rotgen::Index i=0;i<b.size();i++)
for (rotgen::Index i = 0; i < b.size(); i++)
TTS_EQUAL(b(i), mat(i)) << "Index: " << i << "\n";
for(rotgen::Index i=0;i<b.size();i++)
for (rotgen::Index i = 0; i < b.size(); i++)
TTS_EQUAL(b[i], mat(i)) << "Index: " << i << "\n";
b(1) = 42;

View file

@ -9,34 +9,35 @@
#include "unit/common/cwise.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic block cwise operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic block cwise 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 const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [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 [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_cwise_functions(input);
}
};
TTS_CASE_TPL("Test static block cwise operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static block cwise 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 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);
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_cwise_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -11,41 +11,44 @@
template<typename EigenType, typename F>
void for_each_element(EigenType const& m, F&& f)
{
for(rotgen::Index i = 0; i < m.rows(); ++i)
for(rotgen::Index j = 0; j < m.cols(); ++j)
f(i, j, m(i,j));
for (rotgen::Index i = 0; i < m.rows(); ++i)
for (rotgen::Index j = 0; j < m.cols(); ++j) f(i, j, m(i, j));
}
template<typename EigenType, typename F>
void for_each_element(EigenType& m, F&& f)
{
for(rotgen::Index i = 0; i < m.rows(); ++i)
for(rotgen::Index j = 0; j < m.cols(); ++j)
f(i, j, m(i,j));
for (rotgen::Index i = 0; i < m.rows(); ++i)
for (rotgen::Index j = 0; j < m.cols(); ++j) f(i, j, m(i, j));
}
template<typename MatrixType, typename T>
MatrixType make_initialized_matrix(rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct)
MatrixType make_initialized_matrix(
rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct)
{
auto[d,i0,j0,ni,nj] = matrix_construct;
auto[r,c,fn] = d;
auto [d, i0, j0, ni, nj] = matrix_construct;
auto [r, c, fn] = d;
MatrixType matrix;
if constexpr(MatrixType::RowsAtCompileTime == -1 &&MatrixType::ColsAtCompileTime == -1)
if constexpr (MatrixType::RowsAtCompileTime == -1 &&
MatrixType::ColsAtCompileTime == -1)
rotgen::resize(matrix, r, c);
for(rotgen::Index i = 0; i < r; ++i)
for(rotgen::Index j = 0; j < c; ++j)
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;
}
template<typename MatrixType, typename BlockType>
void validate_block_behavior(MatrixType& matrix, BlockType& block,
rotgen::Index block_i, rotgen::Index block_j,
rotgen::Index block_m, rotgen::Index block_n)
void validate_block_behavior(MatrixType& matrix,
BlockType& block,
rotgen::Index block_i,
rotgen::Index block_j,
rotgen::Index block_m,
rotgen::Index block_n)
{
using T = typename MatrixType::value_type;
TTS_EQUAL(block.rows(), block_m);
@ -58,12 +61,11 @@ void validate_block_behavior(MatrixType& matrix, BlockType& block,
});
// test aliasing if non immutable
if constexpr(!BlockType::is_immutable)
if constexpr (!BlockType::is_immutable)
{
T value = 1;
for_each_element(block, [&](auto i, auto j, auto&) {
block(i, j) = value++;
});
for_each_element(block,
[&](auto i, auto j, auto&) { block(i, j) = value++; });
value = 1;
for_each_element(block, [&](auto i, auto j, auto&) {
@ -81,99 +83,140 @@ void validate_block_behavior(MatrixType& matrix, BlockType& block,
}
template<typename MatrixType, typename T>
void test_dynamic_block_extraction(rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct)
void test_dynamic_block_extraction(
rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct)
{
MatrixType matrix = make_initialized_matrix<MatrixType, T>(matrix_construct);
MatrixType const c_matrix = matrix;
auto c_block_main = rotgen::extract(c_matrix, matrix_construct.i0, matrix_construct.j0,
matrix_construct.ni, matrix_construct.nj);
auto c_block_top_left_corner = rotgen::topLeftCorner(c_matrix, matrix_construct.ni, matrix_construct.nj);
auto c_block_top_right_corner = rotgen::topRightCorner(c_matrix, matrix_construct.ni, matrix_construct.nj);
auto c_block_bottom_left_corner = rotgen::bottomLeftCorner(c_matrix, matrix_construct.ni, matrix_construct.nj);
auto c_block_bottom_right_corner = rotgen::bottomRightCorner(c_matrix, matrix_construct.ni, matrix_construct.nj);
auto c_block_main =
rotgen::extract(c_matrix, matrix_construct.i0, matrix_construct.j0,
matrix_construct.ni, matrix_construct.nj);
auto c_block_top_left_corner =
rotgen::topLeftCorner(c_matrix, matrix_construct.ni, matrix_construct.nj);
auto c_block_top_right_corner =
rotgen::topRightCorner(c_matrix, matrix_construct.ni, matrix_construct.nj);
auto c_block_bottom_left_corner = rotgen::bottomLeftCorner(
c_matrix, matrix_construct.ni, matrix_construct.nj);
auto c_block_bottom_right_corner = rotgen::bottomRightCorner(
c_matrix, matrix_construct.ni, matrix_construct.nj);
auto c_block_top_rows = rotgen::topRows(c_matrix, matrix_construct.ni);
auto c_block_middle_rows = rotgen::middleRows(c_matrix, matrix_construct.i0, matrix_construct.ni);
auto c_block_bottom_rows = rotgen::bottomRows(c_matrix, matrix_construct.ni);
auto c_block_top_rows = rotgen::topRows(c_matrix, matrix_construct.ni);
auto c_block_middle_rows =
rotgen::middleRows(c_matrix, matrix_construct.i0, matrix_construct.ni);
auto c_block_bottom_rows = rotgen::bottomRows(c_matrix, matrix_construct.ni);
auto c_block_left_cols = rotgen::leftCols(c_matrix, matrix_construct.nj);
auto c_block_middle_cols = rotgen::middleCols(c_matrix, matrix_construct.j0, matrix_construct.nj);
auto c_block_right_cols = rotgen::rightCols(c_matrix, matrix_construct.nj);
auto c_block_left_cols = rotgen::leftCols(c_matrix, matrix_construct.nj);
auto c_block_middle_cols =
rotgen::middleCols(c_matrix, matrix_construct.j0, matrix_construct.nj);
auto c_block_right_cols = rotgen::rightCols(c_matrix, matrix_construct.nj);
auto block_main = rotgen::extract(matrix, matrix_construct.i0, matrix_construct.j0,
matrix_construct.ni, matrix_construct.nj);
auto block_top_left_corner = rotgen::topLeftCorner(matrix, matrix_construct.ni, matrix_construct.nj);
auto block_top_right_corner = rotgen::topRightCorner(matrix, matrix_construct.ni, matrix_construct.nj);
auto block_bottom_left_corner = rotgen::bottomLeftCorner(matrix, matrix_construct.ni, matrix_construct.nj);
auto block_bottom_right_corner = rotgen::bottomRightCorner(matrix, matrix_construct.ni, matrix_construct.nj);
auto block_main =
rotgen::extract(matrix, matrix_construct.i0, matrix_construct.j0,
matrix_construct.ni, matrix_construct.nj);
auto block_top_left_corner =
rotgen::topLeftCorner(matrix, matrix_construct.ni, matrix_construct.nj);
auto block_top_right_corner =
rotgen::topRightCorner(matrix, matrix_construct.ni, matrix_construct.nj);
auto block_bottom_left_corner =
rotgen::bottomLeftCorner(matrix, matrix_construct.ni, matrix_construct.nj);
auto block_bottom_right_corner =
rotgen::bottomRightCorner(matrix, matrix_construct.ni, matrix_construct.nj);
auto block_top_rows = rotgen::topRows(matrix, matrix_construct.ni);
auto block_middle_rows = rotgen::middleRows(matrix, matrix_construct.i0, matrix_construct.ni);
auto block_bottom_rows = rotgen::bottomRows(matrix, matrix_construct.ni);
auto block_top_rows = rotgen::topRows(matrix, matrix_construct.ni);
auto block_middle_rows =
rotgen::middleRows(matrix, matrix_construct.i0, matrix_construct.ni);
auto block_bottom_rows = rotgen::bottomRows(matrix, matrix_construct.ni);
auto block_left_cols = rotgen::leftCols(matrix, matrix_construct.nj);
auto block_middle_cols = rotgen::middleCols(matrix, matrix_construct.j0, matrix_construct.nj);
auto block_right_cols = rotgen::rightCols(matrix, matrix_construct.nj);
auto block_left_cols = rotgen::leftCols(matrix, matrix_construct.nj);
auto block_middle_cols =
rotgen::middleCols(matrix, matrix_construct.j0, matrix_construct.nj);
auto block_right_cols = rotgen::rightCols(matrix, matrix_construct.nj);
auto blocks = std::make_tuple(
// --- CONST TESTS
std::make_tuple(c_block_main, matrix_construct.i0, matrix_construct.j0, matrix_construct.ni, matrix_construct.nj),
std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni, matrix_construct.nj),
std::make_tuple(c_block_top_right_corner, 0, matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj),
std::make_tuple(c_block_bottom_left_corner, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj),
std::make_tuple(c_block_bottom_right_corner, matrix.rows() - matrix_construct.ni, matrix.cols() - matrix_construct.nj,
std::make_tuple(c_block_main, matrix_construct.i0, matrix_construct.j0,
matrix_construct.ni, matrix_construct.nj),
std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni,
matrix_construct.nj),
std::make_tuple(c_block_top_right_corner, 0,
matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj),
std::make_tuple(c_block_bottom_left_corner,
matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni,
matrix_construct.nj),
std::make_tuple(c_block_bottom_right_corner,
matrix.rows() - matrix_construct.ni,
matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj),
std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols()),
std::make_tuple(c_block_middle_rows, matrix_construct.i0, 0, matrix_construct.ni, matrix.cols()),
std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix.cols()),
std::make_tuple(c_block_middle_rows, matrix_construct.i0, 0,
matrix_construct.ni, matrix.cols()),
std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni, 0,
matrix_construct.ni, matrix.cols()),
std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj),
std::make_tuple(c_block_middle_cols, 0, matrix_construct.j0, matrix.rows(), matrix_construct.nj),
std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj, matrix.rows(), matrix_construct.nj),
std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(),
matrix_construct.nj),
std::make_tuple(c_block_middle_cols, 0, matrix_construct.j0, matrix.rows(),
matrix_construct.nj),
std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj,
matrix.rows(), matrix_construct.nj),
// --- REGULAR TESTS
std::make_tuple(block_main, matrix_construct.i0, matrix_construct.j0, matrix_construct.ni, matrix_construct.nj),
std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni, matrix_construct.nj),
std::make_tuple(block_top_right_corner, 0, matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj),
std::make_tuple(block_bottom_left_corner, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj),
std::make_tuple(block_bottom_right_corner, matrix.rows() - matrix_construct.ni, matrix.cols() - matrix_construct.nj,
std::make_tuple(block_main, matrix_construct.i0, matrix_construct.j0,
matrix_construct.ni, matrix_construct.nj),
std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni,
matrix_construct.nj),
std::make_tuple(block_top_right_corner, 0,
matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj),
std::make_tuple(block_bottom_left_corner,
matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni,
matrix_construct.nj),
std::make_tuple(block_bottom_right_corner,
matrix.rows() - matrix_construct.ni,
matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj),
std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols()),
std::make_tuple(block_middle_rows, matrix_construct.i0, 0, matrix_construct.ni, matrix.cols()),
std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix.cols()),
std::make_tuple(block_middle_rows, matrix_construct.i0, 0,
matrix_construct.ni, matrix.cols()),
std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni, 0,
matrix_construct.ni, matrix.cols()),
std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj),
std::make_tuple(block_middle_cols, 0, matrix_construct.j0, matrix.rows(), matrix_construct.nj),
std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj, matrix.rows(), matrix_construct.nj)
);
std::make_tuple(block_middle_cols, 0, matrix_construct.j0, matrix.rows(),
matrix_construct.nj),
std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj,
matrix.rows(), matrix_construct.nj));
std::apply([&](auto&&... block_entries)
{
(([&]
{
auto&& [block, i_offset, j_offset, ni, nj] = block_entries;
using block_t = std::remove_reference_t<decltype(block)>;
std::apply(
[&](auto&&... block_entries) {
(([&] {
auto&& [block, i_offset, j_offset, ni, nj] = block_entries;
using block_t = std::remove_reference_t<decltype(block)>;
TTS_EQUAL(block_t::RowsAtCompileTime, rotgen::Dynamic);
TTS_EQUAL(block_t::ColsAtCompileTime, rotgen::Dynamic);
TTS_EQUAL(block_t::storage_order, MatrixType::storage_order);
validate_block_behavior(matrix, block, i_offset, j_offset, ni, nj);
})(), ...);
}, blocks);
TTS_EQUAL(block_t::RowsAtCompileTime, rotgen::Dynamic);
TTS_EQUAL(block_t::ColsAtCompileTime, rotgen::Dynamic);
TTS_EQUAL(block_t::storage_order, MatrixType::storage_order);
validate_block_behavior(matrix, block, i_offset, j_offset, ni, nj);
})(),
...);
},
blocks);
}
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)
void test_static_block_extraction(
rotgen::tests::static_matrix_block_test_case<MatrixType, NI, NJ> const&
matrix_construct)
{
auto[d,i0,j0] = matrix_construct;
auto[r,c,fn] = d;
auto [d, i0, j0] = matrix_construct;
auto [r, c, fn] = d;
MatrixType matrix(r,c);
MatrixType matrix(r, c);
for (rotgen::Index i = 0; i < r; ++i)
for (rotgen::Index j = 0; j < c; ++j)
@ -181,177 +224,219 @@ void test_static_block_extraction(rotgen::tests::static_matrix_block_test_case<M
MatrixType const c_matrix = matrix;
auto c_block_main = rotgen::extract<NI, NJ>(c_matrix, i0, j0);
auto c_block_top_left_corner = rotgen::topLeftCorner<NI, NJ>(c_matrix);
auto c_block_top_right_corner = rotgen::topRightCorner<NI, NJ>(c_matrix);
auto c_block_bottom_left_corner = rotgen::bottomLeftCorner<NI, NJ>(c_matrix);
auto c_block_bottom_right_corner = rotgen::bottomRightCorner<NI, NJ>(c_matrix);
auto c_block_top_rows = rotgen::topRows<NI>(c_matrix);
auto c_block_middle_rows = rotgen::middleRows<NI>(c_matrix, i0);
auto c_block_bottom_rows = rotgen::bottomRows<NI>(c_matrix);
auto c_block_left_cols = rotgen::leftCols<NJ>(c_matrix);
auto c_block_middle_cols = rotgen::middleCols<NJ>(c_matrix, j0);
auto c_block_right_cols = rotgen::rightCols<NJ>(c_matrix);
auto c_block_row = rotgen::row(c_matrix, i0);
auto c_block_col = rotgen::col(c_matrix, j0);
auto c_block_main = rotgen::extract<NI, NJ>(c_matrix, i0, j0);
auto c_block_top_left_corner = rotgen::topLeftCorner<NI, NJ>(c_matrix);
auto c_block_top_right_corner = rotgen::topRightCorner<NI, NJ>(c_matrix);
auto c_block_bottom_left_corner = rotgen::bottomLeftCorner<NI, NJ>(c_matrix);
auto c_block_bottom_right_corner =
rotgen::bottomRightCorner<NI, NJ>(c_matrix);
auto c_block_top_rows = rotgen::topRows<NI>(c_matrix);
auto c_block_middle_rows = rotgen::middleRows<NI>(c_matrix, i0);
auto c_block_bottom_rows = rotgen::bottomRows<NI>(c_matrix);
auto c_block_left_cols = rotgen::leftCols<NJ>(c_matrix);
auto c_block_middle_cols = rotgen::middleCols<NJ>(c_matrix, j0);
auto c_block_right_cols = rotgen::rightCols<NJ>(c_matrix);
auto c_block_row = rotgen::row(c_matrix, i0);
auto c_block_col = rotgen::col(c_matrix, j0);
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_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, 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, j0);
auto block_right_cols = rotgen::rightCols<NJ>(matrix);
auto block_row = rotgen::row(matrix, i0);
auto block_col = rotgen::col(matrix, j0);
auto block_top_rows = rotgen::topRows<NI>(matrix);
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, j0);
auto block_right_cols = rotgen::rightCols<NJ>(matrix);
auto block_row = rotgen::row(matrix, i0);
auto block_col = rotgen::col(matrix, j0);
auto blocks = std::make_tuple(
// ----- TEST ON BLOCK FROM CONST MATRIX
std::make_tuple(c_block_main, i0, j0,
matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_top_left_corner, 0, 0,
matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_top_right_corner, 0, matrix.cols() - matrix_construct.nj,
matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_bottom_left_corner, matrix.rows() - matrix_construct.ni, 0,
matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_bottom_right_corner, matrix.rows() - matrix_construct.ni,
// ----- TEST ON BLOCK FROM CONST MATRIX
std::make_tuple(c_block_main, i0, j0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_top_right_corner, 0,
matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_bottom_left_corner,
matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_bottom_right_corner,
matrix.rows() - matrix_construct.ni,
matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), int(NI), rotgen::Dynamic),
std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(),
int(NI), rotgen::Dynamic),
std::make_tuple(c_block_middle_rows, i0, 0, matrix_construct.ni,
matrix.cols(), int(NI), rotgen::Dynamic),
std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni,
0, matrix_construct.ni, matrix.cols(), int(NI), rotgen::Dynamic),
std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni, 0,
matrix_construct.ni, matrix.cols(), int(NI),
rotgen::Dynamic),
std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)),
std::make_tuple(c_block_middle_cols, 0, j0,
matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)),
std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj,
rotgen::Dynamic, int(NJ)),
std::make_tuple(c_block_middle_cols, 0, j0, matrix.rows(),
matrix_construct.nj, rotgen::Dynamic, int(NJ)),
std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj,
matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)),
matrix.rows(), matrix_construct.nj, rotgen::Dynamic,
int(NJ)),
std::make_tuple(c_block_row, i0, 0,
1, matrix.cols(), 1, rotgen::Dynamic),
std::make_tuple(c_block_col, 0, j0,
matrix.rows(), 1, rotgen::Dynamic, 1),
std::make_tuple(c_block_row, i0, 0, 1, matrix.cols(), 1, rotgen::Dynamic),
std::make_tuple(c_block_col, 0, j0, matrix.rows(), 1, rotgen::Dynamic, 1),
// -- Block to NON CONST
std::make_tuple(block_main, i0, j0,
matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_top_left_corner, 0, 0,
matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_top_right_corner, 0, matrix.cols() - matrix_construct.nj,
matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_bottom_left_corner, matrix.rows() - matrix_construct.ni, 0,
matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_bottom_right_corner, matrix.rows() - matrix_construct.ni,
std::make_tuple(block_main, i0, j0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_top_right_corner, 0,
matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_bottom_left_corner,
matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_bottom_right_corner,
matrix.rows() - matrix_construct.ni,
matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), int(NI), rotgen::Dynamic),
std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(),
int(NI), rotgen::Dynamic),
std::make_tuple(block_middle_rows, i0, 0, matrix_construct.ni,
matrix.cols(), int(NI), rotgen::Dynamic),
std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni,
0, matrix_construct.ni, matrix.cols(), int(NI), rotgen::Dynamic),
std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni, 0,
matrix_construct.ni, matrix.cols(), int(NI),
rotgen::Dynamic),
std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)),
std::make_tuple(block_middle_cols, 0, j0,
matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)),
std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj,
rotgen::Dynamic, int(NJ)),
std::make_tuple(block_middle_cols, 0, j0, matrix.rows(),
matrix_construct.nj, rotgen::Dynamic, int(NJ)),
std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj,
matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)),
matrix.rows(), matrix_construct.nj, rotgen::Dynamic,
int(NJ)),
std::make_tuple(block_row, i0, 0,
1, matrix.cols(), 1, rotgen::Dynamic),
std::make_tuple(block_col, 0, j0,
matrix.rows(), 1, rotgen::Dynamic, 1)
);
std::make_tuple(block_row, i0, 0, 1, matrix.cols(), 1, rotgen::Dynamic),
std::make_tuple(block_col, 0, j0, matrix.rows(), 1, rotgen::Dynamic, 1));
std::apply([&](auto&&... block_entries)
{
(([&]
{
auto&& [block, i_offset, j_offset, ni, nj, rows_ct, cols_ct] = block_entries;
using block_t = std::remove_reference_t<decltype(block)>;
std::apply(
[&](auto&&... block_entries) {
(([&] {
auto&& [block, i_offset, j_offset, ni, nj, rows_ct, cols_ct] =
block_entries;
using block_t = std::remove_reference_t<decltype(block)>;
TTS_EQUAL(block_t::RowsAtCompileTime, rows_ct);
TTS_EQUAL(block_t::ColsAtCompileTime, cols_ct);
TTS_EQUAL(block_t::RowsAtCompileTime, rows_ct);
TTS_EQUAL(block_t::ColsAtCompileTime, cols_ct);
validate_block_behavior(matrix, block, i_offset, j_offset, ni, nj);
})(), ...);
}, blocks);
validate_block_behavior(matrix, block, i_offset, j_offset, ni, nj);
})(),
...);
},
blocks);
}
TTS_CASE_TPL("Check all dynamic block extractions on a dynamic row-major matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL(
"Check all dynamic block extractions on a dynamic row-major matrix",
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, 1>;
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) {
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)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL(
"Check all dynamic block extractions on a static column-major matrix",
rotgen::tests::types)<typename T, typename O>(tts::type<tts::types<T, O>>)
{
using mat_t = rotgen::matrix<T,4,5,O::value, 0>;
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) {
for (auto const& matrix_case : cases)
{
test_dynamic_block_extraction<mat_t, T>(matrix_case);
}
};
TTS_CASE_TPL("Check all static block extractions", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check all static block extractions",
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>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
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); } },
3, 2
}
);
{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)); }},
5, 1
}
);
{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); }},
0, 0
}
);
{5, 5, [](rotgen::Index i, rotgen::Index j) { return T((i + j) % 9); }},
0,
0});
};
TTS_CASE_TPL("Check vector-only extractions",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>) {
auto run_case = [](auto &&matrix, auto &&block, int i_offset, int j_offset,
int ni, int nj, auto const &rows_ct, auto const &cols_ct) {
tts::type<tts::types<T, O>>)
{
auto run_case = [](auto&& matrix, auto&& block, int i_offset, int j_offset,
int ni, int nj, auto const& rows_ct, auto const& cols_ct) {
using block_t = std::remove_reference_t<decltype(block)>;
TTS_EQUAL(block_t::RowsAtCompileTime, rows_ct);
@ -360,12 +445,12 @@ TTS_CASE_TPL("Check vector-only extractions",
validate_block_behavior(matrix, block, i_offset, j_offset, ni, nj);
};
if constexpr (O::value == rotgen::RowMajor) {
if constexpr (O::value == rotgen::RowMajor)
{
using mat_t = rotgen::matrix<T, 1, rotgen::Dynamic, O::value>;
mat_t m(1, 11);
for (rotgen::Index i = 0; i < 11; ++i)
m(i) = 1 + i;
for (rotgen::Index i = 0; i < 11; ++i) m(i) = 1 + i;
run_case(m, head(m, 1), 0, 0, 1, 1, 1, rotgen::Dynamic);
run_case(m, head(m, 5), 0, 0, 1, 5, 1, rotgen::Dynamic);
@ -385,12 +470,13 @@ TTS_CASE_TPL("Check vector-only extractions",
run_case(m, segment<11>(m, 0), 0, 0, 1, 11, 1, 11);
run_case(m, segment<7>(m, 0), 0, 0, 1, 7, 1, 7);
run_case(m, segment<6>(m, 5), 0, 5, 1, 6, 1, 6);
} else {
}
else
{
using mat_t = rotgen::matrix<T, rotgen::Dynamic, 1, O::value>;
mat_t m(11, 1);
for (rotgen::Index i = 0; i < 11; ++i)
m(i) = 1 + i;
for (rotgen::Index i = 0; i < 11; ++i) m(i) = 1 + i;
run_case(m, head(m, 1), 0, 0, 1, 1, rotgen::Dynamic, 1);
run_case(m, head(m, 5), 0, 0, 5, 1, rotgen::Dynamic, 1);

View file

@ -8,261 +8,269 @@
#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
)
void test_value(auto const& 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);
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
)
void test_identity(auto const& 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);
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
)
void test_random(auto const& 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)
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_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>>)
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 const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [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 [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);
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);
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>> )
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 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;
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::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);
test_value(m, T{0}, i0, j0, D::ni, D::nj);
using input_type = decltype(rotgen::extract<D::ni,D::nj>(m, i0, j0));
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);
test_value(values, T{0}, 0, 0, D::ni, D::nj);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
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>>)
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 const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [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 [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);
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);
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>> )
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 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;
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::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);
test_value(m, T{1}, i0, j0, D::ni, D::nj);
using input_type = decltype(rotgen::extract<D::ni,D::nj>(m, i0, j0));
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);
test_value(values, T{1}, 0, 0, D::ni, D::nj);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
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>>)
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 const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [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 [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);
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);
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>> )
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 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;
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::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);
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));
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);
test_value(values, T{13.37f}, 0, 0, D::ni, D::nj);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
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>>)
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 const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [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 [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);
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);
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>> )
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 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;
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::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);
test_identity(m, i0, j0, D::ni, D::nj);
using input_type = decltype(rotgen::extract<D::ni,D::nj>(m, i0, j0));
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);
test_identity(values, 0, 0, D::ni, D::nj);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
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>>)
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 const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [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 [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);
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);
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>> )
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 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;
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::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);
test_random(m, i0, j0, D::ni, D::nj);
using input_type = decltype(rotgen::extract<D::ni,D::nj>(m, i0, j0));
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);
test_random(values, 0, 0, D::ni, D::nj);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
};
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -9,34 +9,35 @@
#include "unit/common/norms.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic block norm operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic block norm 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 const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [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 [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>> )
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 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);
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);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -9,35 +9,38 @@
#include <rotgen/rotgen.hpp>
#include <Eigen/Dense>
template <typename MatrixType, typename T>
void test_block_matrix_operations(rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct,
auto b_init_fn, auto ops, auto self_ops)
template<typename MatrixType, typename T>
void test_block_matrix_operations(
rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct,
auto b_init_fn,
auto ops,
auto self_ops)
{
using EigenMatrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
auto[d,i0,j0,ni,nj] = matrix_construct;
auto[r,c,fn] = d;
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)));
TTS_EXPECT(verify_rotgen_reentrance(ops(a, b)));
for (rotgen::Index rr = 0; rr < r; ++rr)
{
for (rotgen::Index cc = 0; cc < c; ++cc)
{
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));
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, 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 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);
@ -46,7 +49,7 @@ void test_block_matrix_operations(rotgen::tests::matrix_block_test_case<MatrixTy
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(a_block, b_block);
self_ops(ref_a_block, ref_b_block);
for (rotgen::Index rr = 0; rr < ni; ++rr)
@ -63,26 +66,29 @@ void test_block_matrix_operations(rotgen::tests::matrix_block_test_case<MatrixTy
}
}
template <typename MatrixType, typename T>
void test_block_scalar_operations(rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct,
auto scalar, auto ops, auto self_ops)
template<typename MatrixType, typename T>
void test_block_scalar_operations(
rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct,
auto scalar,
auto ops,
auto self_ops)
{
using EigenMatrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
auto[d,i0,j0,ni,nj] = matrix_construct;
auto[rows,cols,fn] = d;
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)));
TTS_EXPECT(verify_rotgen_reentrance(ops(a, scalar)));
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));
ref_a(r, c) = a(r, c) = static_cast<T>(fn(r, c));
auto a_block = rotgen::extract(a, i0, j0,ni, nj);
auto ref_a_block = ref_a.block(i0, j0,ni, 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);
@ -91,7 +97,7 @@ void test_block_scalar_operations(rotgen::tests::matrix_block_test_case<MatrixTy
for (rotgen::Index c = 0; c < nj; ++c)
TTS_EQUAL(result(r, c), ref_result(r, c));
self_ops(a_block,scalar);
self_ops(a_block, scalar);
self_ops(ref_a_block, scalar);
for (rotgen::Index r = 0; r < ni; ++r)
@ -99,18 +105,18 @@ void test_block_scalar_operations(rotgen::tests::matrix_block_test_case<MatrixTy
TTS_EQUAL(a_block(r, c), ref_a_block(r, 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));
for (rotgen::Index c = 0; c < cols; ++c) TTS_EQUAL(a(r, c), ref_a(r, c));
}
template <typename MatrixType, typename T>
void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct,
T scalar)
template<typename MatrixType, typename T>
void test_scalar_block_multiplications(
rotgen::tests::matrix_block_test_case<MatrixType> const& matrix_construct,
T scalar)
{
using EigenMatrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
auto[d,i0,j0,ni,nj] = matrix_construct;
auto[rows,cols,fn] = d;
auto [d, i0, j0, ni, nj] = matrix_construct;
auto [rows, cols, fn] = d;
MatrixType a(rows, cols);
EigenMatrix ref_a(rows, cols);
@ -120,12 +126,10 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
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));
ref_a(r, c) = a(r, c) = static_cast<T>(fn(r, c));
auto a_block = rotgen::extract(a, i0, j0,
ni, nj);
auto ref_a_block = ref_a.block(i0, j0,
ni, 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;
@ -136,8 +140,10 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
{
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));
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));
}
}
@ -149,22 +155,21 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
TTS_EQUAL(a_block(r, c), ref_a_block(r, 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));
for (rotgen::Index c = 0; c < cols; ++c) TTS_EQUAL(a(r, c), ref_a(r, c));
}
template <typename MatrixType, typename T>
void test_block_multiplication(rotgen::tests::matrix_block_test_case<MatrixType> const& a_matrix_construct,
rotgen::tests::matrix_block_test_case<MatrixType> const& b_matrix_construct)
template<typename MatrixType, typename T>
void test_block_multiplication(
rotgen::tests::matrix_block_test_case<MatrixType> const& a_matrix_construct,
rotgen::tests::matrix_block_test_case<MatrixType> const& b_matrix_construct)
{
using EigenMatrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
auto[a_d,a_i0,a_j0,a_ni,a_nj] = a_matrix_construct;
auto[a_rows,a_cols,a_fn] = a_d;
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_d, a_i0, a_j0, a_ni, a_nj] = a_matrix_construct;
auto [a_rows, a_cols, a_fn] = a_d;
auto [b_d, b_i0, b_j0, b_ni, b_nj] = b_matrix_construct;
auto [b_rows, b_cols, b_fn] = b_d;
MatrixType a(a_rows, a_cols);
MatrixType b(b_rows, b_cols);
@ -173,17 +178,16 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case<MatrixType>
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));
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));
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);
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));
@ -192,7 +196,7 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case<MatrixType>
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));
TTS_EQUAL(a_b_product_original(r, c), a_b_product_ref(r, c));
a_block *= b_block;
ref_a_block *= ref_b_block;
@ -202,106 +206,162 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case<MatrixType>
TTS_EQUAL(a_block(r, c), ref_a_block(r, 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 c = 0; c < a_cols; ++c) TTS_EQUAL(a(r, c), ref_a(r, 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));
for (rotgen::Index c = 0; c < b_cols; ++c) TTS_EQUAL(b(r, c), ref_b(r, c));
}
// Basic initializers
inline constexpr auto init_a = [](auto r, auto c) { return 9.9*r*r*r - 6*c -12; };
inline constexpr auto init_b = [](auto r, auto c) { return 3.1*r + 4.2*c - 12.3; };
inline constexpr auto init_0 = [](auto , auto ) { return 0; };
inline constexpr auto init_a = [](auto r, auto c) {
return 9.9 * r * r * r - 6 * c - 12;
};
inline constexpr auto init_b = [](auto r, auto c) {
return 3.1 * r + 4.2 * c - 12.3;
};
inline constexpr auto init_0 = [](auto, auto) { return 0; };
TTS_CASE_TPL("Check block addition", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check block addition",
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 op = [](auto a, auto b) { return a + b; };
auto s_op = [](auto& a, auto b) { return a += b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
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>> )
TTS_CASE_TPL("Check block subtraction",
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 op = [](auto a, auto b) { return a - b; };
auto s_op = [](auto& a, auto b) { return a -= b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
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>> )
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; };
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)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check block multiplication with scalar",
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>;
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)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check block division with scalar",
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 op = [](auto a, auto b) { return a / b; };
auto s_op = [](auto& a, auto b) { return a /= b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
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);
};

View file

@ -12,21 +12,21 @@
namespace rotgen::tests
{
template<typename T>
void check_shape_functions(T original)
template<typename T> void check_shape_functions(T original)
{
using mat_t = matrix<typename T::value_type,Dynamic,Dynamic,T::storage_order>;
using mat_t =
matrix<typename T::value_type, Dynamic, Dynamic, T::storage_order>;
mat_t result(original.cols(), original.rows());
prepare([&](auto r, auto c) { return original(c,r); },result);
prepare([&](auto r, auto c) { return original(c, r); }, result);
TTS_EQUAL(transpose(original) , result );
TTS_EQUAL(conjugate(original) , original);
TTS_EQUAL(adjoint(original) , result );
TTS_EQUAL(transpose(original), result);
TTS_EQUAL(conjugate(original), original);
TTS_EQUAL(adjoint(original), result);
if constexpr(T::is_defined_static)
if constexpr (T::is_defined_static)
{
if constexpr(T::RowsAtCompileTime == T::ColsAtCompileTime)
if constexpr (T::RowsAtCompileTime == T::ColsAtCompileTime)
{
mat_t ref = original;
transposeInPlace(original);
@ -49,37 +49,37 @@ namespace rotgen::tests
}
}
if constexpr(!rotgen::use_expression_templates)
if constexpr (!rotgen::use_expression_templates)
{
TTS_EXPECT(verify_rotgen_reentrance( original.transpose()) );
TTS_EXPECT(verify_rotgen_reentrance( original.conjugate()) );
TTS_EXPECT(verify_rotgen_reentrance( original.adjoint()) );
TTS_EXPECT(verify_rotgen_reentrance(original.transpose()));
TTS_EXPECT(verify_rotgen_reentrance(original.conjugate()));
TTS_EXPECT(verify_rotgen_reentrance(original.adjoint()));
}
}
template<typename T>
void check_reduction_functions(const T& input)
template<typename T> void check_reduction_functions(T const& input)
{
using EigenMatrix = Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
using EigenMatrix =
Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
EigenMatrix ref(input.rows(), input.cols());
prepare([&](auto r, auto c) { return input(r,c); }, ref);
prepare([&](auto r, auto c) { return input(r, c); }, ref);
TTS_ULP_EQUAL(sum(input) , ref.sum() , 2);
TTS_ULP_EQUAL(prod(input) , ref.prod(), 2);
TTS_ULP_EQUAL(mean(input) , ref.mean(), 2);
TTS_EQUAL(trace(input) , ref.trace());
TTS_EQUAL(minCoeff(input) , ref.minCoeff());
TTS_EQUAL(maxCoeff(input) , ref.maxCoeff());
TTS_ULP_EQUAL(sum(input), ref.sum(), 2);
TTS_ULP_EQUAL(prod(input), ref.prod(), 2);
TTS_ULP_EQUAL(mean(input), ref.mean(), 2);
TTS_EQUAL(trace(input), ref.trace());
TTS_EQUAL(minCoeff(input), ref.minCoeff());
TTS_EQUAL(maxCoeff(input), ref.maxCoeff());
{
int row, col, ref_row, ref_col;
TTS_EQUAL(minCoeff(input,&row, &col), ref.minCoeff(&ref_row, &ref_col));
TTS_EQUAL(minCoeff(input, &row, &col), ref.minCoeff(&ref_row, &ref_col));
TTS_EQUAL(row, ref_row);
TTS_EQUAL(col, ref_col);
TTS_EQUAL(maxCoeff(input,&row, &col), ref.maxCoeff(&ref_row, &ref_col));
TTS_EQUAL(maxCoeff(input, &row, &col), ref.maxCoeff(&ref_row, &ref_col));
TTS_EQUAL(row, ref_row);
TTS_EQUAL(col, ref_col);
}

View file

@ -12,81 +12,82 @@
namespace rotgen::tests
{
template<typename T>
void check_cwise_functions(const T& input)
template<typename T> void check_cwise_functions(T const& input)
{
using EigenMatrix = Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
using mat_t = matrix<typename T::value_type,Dynamic,Dynamic,T::storage_order>;
using EigenMatrix =
Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
using mat_t =
matrix<typename T::value_type, Dynamic, Dynamic, T::storage_order>;
TTS_WHEN("Unary Cwise operations")
{
EigenMatrix e_ref(input.rows(), input.cols());
prepare([&](auto r, auto c) { return input(r,c); }, e_ref);
prepare([&](auto r, auto c) { return input(r, c); }, e_ref);
mat_t ref(input.rows(), input.cols());
TTS_AND_THEN(".cwiseAbs")
{
e_ref = e_ref.cwiseAbs();
prepare([&](auto r, auto c) { return e_ref(r,c); }, ref);
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
TTS_EQUAL(input.cwiseAbs(), ref);
}
TTS_AND_THEN(".cwiseAbs2")
{
e_ref = e_ref.cwiseAbs2();
prepare([&](auto r, auto c) { return e_ref(r,c); }, ref);
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
TTS_EQUAL(input.cwiseAbs2(), ref);
}
TTS_AND_THEN(".cwiseInverse")
{
e_ref = e_ref.cwiseInverse();
prepare([&](auto r, auto c) { return e_ref(r,c); }, ref);
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
TTS_EQUAL(input.cwiseInverse(), ref);
}
TTS_AND_THEN(".cwiseSqrt")
{
e_ref = e_ref.cwiseAbs().cwiseSqrt();
auto mat = input.cwiseAbs();
auto mat = input.cwiseAbs();
auto proper_input = mat.cwiseSqrt();
for(rotgen::Index r=0;r<input.rows();++r)
for(rotgen::Index c=0;c<input.cols();++c)
TTS_ULP_EQUAL(proper_input(r,c), e_ref(r,c), 1);
for (rotgen::Index r = 0; r < input.rows(); ++r)
for (rotgen::Index c = 0; c < input.cols(); ++c)
TTS_ULP_EQUAL(proper_input(r, c), e_ref(r, c), 1);
}
TTS_AND_THEN("abs()")
{
e_ref = e_ref.cwiseAbs();
prepare([&](auto r, auto c) { return e_ref(r,c); }, ref);
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
TTS_EQUAL(rotgen::abs(input), ref);
}
TTS_AND_THEN("abs2()")
{
e_ref = e_ref.cwiseAbs2();
prepare([&](auto r, auto c) { return e_ref(r,c); }, ref);
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
TTS_EQUAL(rotgen::abs2(input), ref);
}
TTS_AND_THEN("rec")
{
e_ref = e_ref.cwiseInverse();
prepare([&](auto r, auto c) { return e_ref(r,c); }, ref);
prepare([&](auto r, auto c) { return e_ref(r, c); }, ref);
TTS_EQUAL(rotgen::rec(input), ref);
}
TTS_AND_THEN("sqrt")
{
e_ref = e_ref.cwiseAbs().cwiseSqrt();
auto mat = input.cwiseAbs();
auto mat = input.cwiseAbs();
auto proper_input = rotgen::sqrt(mat);
for(rotgen::Index r=0;r<input.rows();++r)
for(rotgen::Index c=0;c<input.cols();++c)
TTS_ULP_EQUAL(proper_input(r,c), e_ref(r,c), 1);
for (rotgen::Index r = 0; r < input.rows(); ++r)
for (rotgen::Index c = 0; c < input.cols(); ++c)
TTS_ULP_EQUAL(proper_input(r, c), e_ref(r, c), 1);
}
}
}

View file

@ -12,27 +12,29 @@
namespace rotgen::tests
{
template<typename T>
void check_norms_functions(const T& input)
template<typename T> void check_norms_functions(T const& input)
{
using EigenMatrix = Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
using EigenMatrix =
Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
EigenMatrix ref(input.rows(), input.cols());
prepare([&](auto r, auto c) { return input(r,c); }, ref);
prepare([&](auto r, auto c) { return input(r, c); }, ref);
TTS_EQUAL(rotgen::norm(input) , ref.norm());
TTS_EQUAL(rotgen::squaredNorm(input) , ref.squaredNorm());
TTS_EQUAL(rotgen::lpNorm<1>(input) , ref.template lpNorm<1>());
TTS_EQUAL(rotgen::lpNorm<2>(input) , ref.template lpNorm<2>());
TTS_EQUAL(rotgen::lpNorm<rotgen::Infinity>(input) , ref.template lpNorm<Eigen::Infinity>());
TTS_EQUAL(rotgen::norm(input), ref.norm());
TTS_EQUAL(rotgen::squaredNorm(input), ref.squaredNorm());
TTS_EQUAL(rotgen::lpNorm<1>(input), ref.template lpNorm<1>());
TTS_EQUAL(rotgen::lpNorm<2>(input), ref.template lpNorm<2>());
TTS_EQUAL(rotgen::lpNorm<rotgen::Infinity>(input),
ref.template lpNorm<Eigen::Infinity>());
if constexpr(T::IsVectorAtCompileTime)
if constexpr (T::IsVectorAtCompileTime)
{
EigenMatrix e_norm = ref.normalized();
using mat_t = rotgen::matrix<typename T::value_type,rotgen::Dynamic,rotgen::Dynamic,T::storage_order>;
using mat_t = rotgen::matrix<typename T::value_type, rotgen::Dynamic,
rotgen::Dynamic, T::storage_order>;
mat_t norm_ref(input.rows(), input.cols());
prepare([&](auto r, auto c) { return e_norm(r,c); }, norm_ref);
prepare([&](auto r, auto c) { return e_norm(r, c); }, norm_ref);
TTS_EQUAL(rotgen::normalized(input), norm_ref);

View file

@ -15,26 +15,25 @@ namespace rotgen::tests
{
struct matrix_descriptor
{
rotgen::Index rows, cols;
std::function<double(std::size_t,std::size_t)> init_fn;
rotgen::Index rows, cols;
std::function<double(std::size_t, std::size_t)> init_fn;
};
template<rotgen::Index Rows, rotgen::Index Cols>
template<rotgen::Index Rows, rotgen::Index Cols>
struct static_matrix_descriptor
{
static constexpr rotgen::Index rows = Rows;
static constexpr rotgen::Index cols = Cols;
std::function<double(std::size_t,std::size_t)> init_fn;
std::function<double(std::size_t, std::size_t)> init_fn;
};
template<typename MatrixType>
struct matrix_block_test_case
template<typename MatrixType> struct matrix_block_test_case
{
matrix_descriptor matrix_desc;
rotgen::Index i0, j0, ni, nj;
rotgen::Index i0, j0, ni, nj;
};
template<typename MatrixType, rotgen::Index NI, rotgen::Index NJ>
template<typename MatrixType, rotgen::Index NI, rotgen::Index NJ>
struct static_matrix_block_test_case
{
matrix_descriptor matrix_desc;
@ -43,25 +42,25 @@ namespace rotgen::tests
rotgen::Index i0, j0;
};
void prepare(rotgen::Index rows, rotgen::Index cols, auto const &init_fn, auto& output)
void prepare(rotgen::Index rows,
rotgen::Index cols,
auto const& init_fn,
auto& output)
{
for (rotgen::Index r = 0; r < rows; ++r)
for (rotgen::Index c = 0; c < cols; ++c)
output(r,c) = init_fn(r, c);
for (rotgen::Index c = 0; c < cols; ++c) output(r, c) = init_fn(r, c);
}
void prepare(auto fn, auto& output)
{
for (rotgen::Index r = 0; r < output.rows(); ++r)
for (rotgen::Index c = 0; c < output.cols(); ++c)
output(r,c) = fn(r, c);
for (rotgen::Index c = 0; c < output.cols(); ++c) output(r, c) = fn(r, c);
}
auto generate_matrix_references()
{
auto fn = [](auto r, auto c) { return r + 3 * c - 2.5; };
std::vector<rotgen::tests::matrix_descriptor> cases =
{
std::vector<rotgen::tests::matrix_descriptor> cases = {
// Singular matrix
{1, 1, fn},
// Square matrix below MAX_SIZE
@ -81,8 +80,7 @@ namespace rotgen::tests
// Thick matrix at MAX_SIZE
{2, 8, fn},
// Thick matrix above MAX_SIZE
{3, 10, fn}
};
{3, 10, fn}};
return cases;
}
@ -90,102 +88,96 @@ namespace rotgen::tests
auto generate_static_matrix_references()
{
auto fn = [](auto r, auto c) { return r + 3 * c - 2.5; };
std::tuple cases =
{
// Singular matrix
static_matrix_descriptor< 1, 1>{fn},
// Square matrix below MAX_SIZE
static_matrix_descriptor< 3, 3>{fn},
// Square matrix at MAX_SIZE
static_matrix_descriptor< 4, 4>{fn},
// Square matrix above MAX_SIZE
static_matrix_descriptor< 7, 7>{fn},
// Tall matrix below MAX_SIZE
static_matrix_descriptor< 5, 2>{fn},
// Tall matrix at MAX_SIZE
static_matrix_descriptor< 8, 2>{fn},
// Tall matrix above MAX_SIZE
static_matrix_descriptor<10, 3>{fn},
// Thick matrix below MAX_SIZE
static_matrix_descriptor< 2, 5>{fn},
// Thick matrix at MAX_SIZE
static_matrix_descriptor< 2, 8>{fn},
// Thick matrix above MAX_SIZE
static_matrix_descriptor< 3,10>{fn}
};
std::tuple cases = {// Singular matrix
static_matrix_descriptor<1, 1>{fn},
// Square matrix below MAX_SIZE
static_matrix_descriptor<3, 3>{fn},
// Square matrix at MAX_SIZE
static_matrix_descriptor<4, 4>{fn},
// Square matrix above MAX_SIZE
static_matrix_descriptor<7, 7>{fn},
// Tall matrix below MAX_SIZE
static_matrix_descriptor<5, 2>{fn},
// Tall matrix at MAX_SIZE
static_matrix_descriptor<8, 2>{fn},
// Tall matrix above MAX_SIZE
static_matrix_descriptor<10, 3>{fn},
// Thick matrix below MAX_SIZE
static_matrix_descriptor<2, 5>{fn},
// Thick matrix at MAX_SIZE
static_matrix_descriptor<2, 8>{fn},
// Thick matrix above MAX_SIZE
static_matrix_descriptor<3, 10>{fn}};
return cases;
}
template<typename T, typename O>
auto generate_block_references()
template<typename T, typename O> auto generate_block_references()
{
rotgen::tests::matrix_descriptor base{16,16,[](auto r, auto c) { return r + 3 * c - 2.5; }};
rotgen::tests::matrix_descriptor base{
16, 16, [](auto r, auto c) { return r + 3 * c - 2.5; }};
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> cases =
{
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> cases = {
// Singular blocks
{base, 0, 0, 1, 1},
{base, 3, 2, 1, 1},
{base, 4,11, 1, 1},
{base,15,15, 1, 1},
{base, 4, 11, 1, 1},
{base, 15, 15, 1, 1},
// Square block below MAX_SIZE
{base,7,9, 3, 3},
{base, 7, 9, 3, 3},
// Square block at MAX_SIZE
{base,6,3, 4, 4},
{base, 6, 3, 4, 4},
// Square block above MAX_SIZE
{base,6,3, 6, 6},
{base, 6, 3, 6, 6},
// Tall block below MAX_SIZE
{base,6,3, 5, 2},
{base, 6, 3, 5, 2},
// Tall block at MAX_SIZE
{base,6,3, 8, 2},
{base, 6, 3, 8, 2},
// Tall block above MAX_SIZE
{base,6,3, 7, 3},
{base, 6, 3, 7, 3},
// Thick block below MAX_SIZE
{base,6,3, 2, 5},
{base, 6, 3, 2, 5},
// Thick block at MAX_SIZE
{base,6,3, 2, 8},
{base, 6, 3, 2, 8},
// Thick block above MAX_SIZE
{base,6,3, 3, 7}
};
{base, 6, 3, 3, 7}};
return cases;
}
template<typename T, typename O>
auto generate_static_block_references()
template<typename T, typename O> auto generate_static_block_references()
{
rotgen::tests::matrix_descriptor base{16,16,[](auto r, auto c) { return r + 3 * c - 2.5; }};
rotgen::tests::matrix_descriptor base{
16, 16, [](auto r, auto c) { return r + 3 * c - 2.5; }};
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
std::tuple cases =
{
std::tuple cases = {
// Singular blocks
static_matrix_block_test_case<mat_t, 1, 1>{base, 0, 0},
static_matrix_block_test_case<mat_t, 1, 1>{base, 3, 2},
static_matrix_block_test_case<mat_t, 1, 1>{base, 4,11},
static_matrix_block_test_case<mat_t, 1, 1>{base,15,15},
static_matrix_block_test_case<mat_t, 1, 1>{base, 4, 11},
static_matrix_block_test_case<mat_t, 1, 1>{base, 15, 15},
// Square block below MAX_SIZE
static_matrix_block_test_case<mat_t, 3, 3>{base,7,9},
static_matrix_block_test_case<mat_t, 3, 3>{base, 7, 9},
// Square block at MAX_SIZE
static_matrix_block_test_case<mat_t, 4, 4>{base,6,3},
static_matrix_block_test_case<mat_t, 4, 4>{base, 6, 3},
// Square block above MAX_SIZE
static_matrix_block_test_case<mat_t, 6, 6>{base,6,3},
static_matrix_block_test_case<mat_t, 6, 6>{base, 6, 3},
// Tall block below MAX_SIZE
static_matrix_block_test_case<mat_t, 5, 2>{base,6,3},
static_matrix_block_test_case<mat_t, 5, 2>{base, 6, 3},
// Tall block at MAX_SIZE
static_matrix_block_test_case<mat_t, 8, 2>{base,6,3},
static_matrix_block_test_case<mat_t, 8, 2>{base, 6, 3},
// Tall block above MAX_SIZE
static_matrix_block_test_case<mat_t, 7, 3>{base,6,3},
static_matrix_block_test_case<mat_t, 7, 3>{base, 6, 3},
// Thick block below MAX_SIZE
static_matrix_block_test_case<mat_t, 2, 5>{base,6,3},
static_matrix_block_test_case<mat_t, 2, 5>{base, 6, 3},
// Thick block at MAX_SIZE
static_matrix_block_test_case<mat_t, 2, 8>{base,6,3},
static_matrix_block_test_case<mat_t, 2, 8>{base, 6, 3},
// Thick block above MAX_SIZE
static_matrix_block_test_case<mat_t, 3, 7>{base,6,3}
};
static_matrix_block_test_case<mat_t, 3, 7>{base, 6, 3}};
return cases;
}

View file

@ -8,27 +8,28 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("System solver using QR", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("System solver using QR",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic>
a { { 2.3, -1, 0.1}
, {-1.6, 2.6, -1}
, { 0.3, -1, 2}
};
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic> a{{2.3, -1, 0.1},
{-1.6, 2.6, -1},
{0.3, -1, 2}};
rotgen::matrix<T,rotgen::Dynamic,1> b(3,1);
b(0) = b(2) = 1; b(1) = 0;
rotgen::matrix<T, rotgen::Dynamic, 1> b(3, 1);
b(0) = b(2) = 1;
b(1) = 0;
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic> r(3,1), error;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic> r(3, 1), error;
auto x = rotgen::extract(r,0,0,3,1);
auto x = rotgen::extract(r, 0, 0, 3, 1);
rotgen::solver::qr(x, a, b);
error = a * r - b;
auto eps = std::numeric_limits<T>::epsilon();
TTS_LESS(rotgen::maxCoeff(rotgen::abs(error)) / eps, 5)
<< "Result:\n" << r << "\n"
<< "Residuals:\n" << error << "\n";
};
TTS_LESS(rotgen::maxCoeff(rotgen::abs(error)) / eps, 5) << "Result:\n"
<< r << "\n"
<< "Residuals:\n"
<< error << "\n";
};

View file

@ -8,47 +8,58 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("rowwise API", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("rowwise API", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using e_t = Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic,O::value>;
e_t ref = e_t::Random(4,4);
using e_t = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, O::value>;
e_t ref = e_t::Random(4, 4);
auto ref_rw = ref.rowwise();
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> mat(4,4);
rotgen::tests::prepare([&](auto r, auto c) { return ref(r,c); }, mat);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> mat(4, 4);
rotgen::tests::prepare([&](auto r, auto c) { return ref(r, c); }, mat);
auto rw = rotgen::rowwise(mat);
for(rotgen::Index i=0;i<mat.rows();++i) TTS_EQUAL(rw.sum()(i) , ref_rw.sum()(i) );
for(rotgen::Index i=0;i<mat.rows();++i) TTS_EQUAL(rw.mean()(i) , ref_rw.mean()(i) );
for(rotgen::Index i=0;i<mat.rows();++i) TTS_EQUAL(rw.prod()(i) , ref_rw.prod()(i) );
for(rotgen::Index i=0;i<mat.rows();++i) TTS_EQUAL(rw.maxCoeff()(i) , ref_rw.maxCoeff()(i) );
for(rotgen::Index i=0;i<mat.rows();++i) TTS_EQUAL(rw.minCoeff()(i) , ref_rw.minCoeff()(i) );
for(rotgen::Index i=0;i<mat.rows();++i) TTS_EQUAL(rw.squaredNorm()(i) , ref_rw.squaredNorm()(i) );
for(rotgen::Index i=0;i<mat.rows();++i) TTS_EQUAL(rw.norm()(i) , ref_rw.norm()(i) );
for (rotgen::Index i = 0; i < mat.rows(); ++i)
TTS_EQUAL(rw.sum()(i), ref_rw.sum()(i));
for (rotgen::Index i = 0; i < mat.rows(); ++i)
TTS_EQUAL(rw.mean()(i), ref_rw.mean()(i));
for (rotgen::Index i = 0; i < mat.rows(); ++i)
TTS_EQUAL(rw.prod()(i), ref_rw.prod()(i));
for (rotgen::Index i = 0; i < mat.rows(); ++i)
TTS_EQUAL(rw.maxCoeff()(i), ref_rw.maxCoeff()(i));
for (rotgen::Index i = 0; i < mat.rows(); ++i)
TTS_EQUAL(rw.minCoeff()(i), ref_rw.minCoeff()(i));
for (rotgen::Index i = 0; i < mat.rows(); ++i)
TTS_EQUAL(rw.squaredNorm()(i), ref_rw.squaredNorm()(i));
for (rotgen::Index i = 0; i < mat.rows(); ++i)
TTS_EQUAL(rw.norm()(i), ref_rw.norm()(i));
};
TTS_CASE_TPL("colwise API", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("colwise API", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using e_t = Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic,O::value>;
e_t ref = e_t::Random(4,4);
using e_t = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, O::value>;
e_t ref = e_t::Random(4, 4);
auto ref_rw = ref.colwise();
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> mat(4,4);
rotgen::tests::prepare([&](auto r, auto c) { return ref(r,c); }, mat);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> mat(4, 4);
rotgen::tests::prepare([&](auto r, auto c) { return ref(r, c); }, mat);
auto rw = rotgen::colwise(mat);
for(rotgen::Index i=0;i<mat.cols();++i) TTS_EQUAL(rw.sum()(i) , ref_rw.sum()(i) );
for(rotgen::Index i=0;i<mat.cols();++i) TTS_EQUAL(rw.mean()(i) , ref_rw.mean()(i) );
for(rotgen::Index i=0;i<mat.cols();++i) TTS_EQUAL(rw.prod()(i) , ref_rw.prod()(i) );
for(rotgen::Index i=0;i<mat.cols();++i) TTS_EQUAL(rw.maxCoeff()(i) , ref_rw.maxCoeff()(i) );
for(rotgen::Index i=0;i<mat.cols();++i) TTS_EQUAL(rw.minCoeff()(i) , ref_rw.minCoeff()(i) );
for(rotgen::Index i=0;i<mat.cols();++i) TTS_EQUAL(rw.squaredNorm()(i) , ref_rw.squaredNorm()(i) );
for(rotgen::Index i=0;i<mat.cols();++i) TTS_EQUAL(rw.norm()(i) , ref_rw.norm()(i) );
for (rotgen::Index i = 0; i < mat.cols(); ++i)
TTS_EQUAL(rw.sum()(i), ref_rw.sum()(i));
for (rotgen::Index i = 0; i < mat.cols(); ++i)
TTS_EQUAL(rw.mean()(i), ref_rw.mean()(i));
for (rotgen::Index i = 0; i < mat.cols(); ++i)
TTS_EQUAL(rw.prod()(i), ref_rw.prod()(i));
for (rotgen::Index i = 0; i < mat.cols(); ++i)
TTS_EQUAL(rw.maxCoeff()(i), ref_rw.maxCoeff()(i));
for (rotgen::Index i = 0; i < mat.cols(); ++i)
TTS_EQUAL(rw.minCoeff()(i), ref_rw.minCoeff()(i));
for (rotgen::Index i = 0; i < mat.cols(); ++i)
TTS_EQUAL(rw.squaredNorm()(i), ref_rw.squaredNorm()(i));
for (rotgen::Index i = 0; i < mat.cols(); ++i)
TTS_EQUAL(rw.norm()(i), ref_rw.norm()(i));
};

View file

@ -10,27 +10,28 @@
#include <functional>
#include <array>
template <typename MatrixType>
struct MatrixDescriptor
template<typename MatrixType> struct MatrixDescriptor
{
std::size_t rows, cols;
std::function<void(MatrixType &, std::size_t, std::size_t)> init_fn;
std::function<void(MatrixType&, std::size_t, std::size_t)> init_fn;
};
template <typename MatrixType, std::size_t N>
void test_matrix_sizes(std::size_t rows, std::size_t cols,
const std::function<void(MatrixType &, std::size_t, std::size_t)> &init_fn,
const std::array<std::pair<int, int>, N>& resize_dimensions)
template<typename MatrixType, std::size_t N>
void test_matrix_sizes(
std::size_t rows,
std::size_t cols,
std::function<void(MatrixType&, std::size_t, std::size_t)> const& init_fn,
std::array<std::pair<int, int>, N> const& resize_dimensions)
{
MatrixType matrix(rows, cols);
for (std::size_t r = 0; r < rows; ++r)
for (std::size_t c = 0; c < cols; ++c)
init_fn(matrix, r, c);
for (std::size_t c = 0; c < cols; ++c) init_fn(matrix, r, c);
TTS_EQUAL(rotgen::size(matrix), rows*cols);
TTS_EQUAL(rotgen::size(matrix), rows * cols);
for (std::size_t i = 0; i < N; ++i) {
for (std::size_t i = 0; i < N; ++i)
{
int r = resize_dimensions[i].first;
int c = resize_dimensions[i].second;
@ -38,24 +39,22 @@ void test_matrix_sizes(std::size_t rows, std::size_t cols,
TTS_EQUAL(rotgen::rows(matrix), static_cast<size_t>(r));
TTS_EQUAL(rotgen::cols(matrix), static_cast<size_t>(c));
TTS_EQUAL(rotgen::size(matrix), static_cast<size_t>(r*c));
TTS_EQUAL(rotgen::size(matrix), static_cast<size_t>(r * c));
}
rotgen::conservativeResize(matrix, rows, cols);
TTS_EQUAL(rotgen::size(matrix), rows*cols);
TTS_EQUAL(rotgen::size(matrix), rows * cols);
int i = 1;
for(std::size_t r=0;r<rows;++r)
for(std::size_t c=0;c<cols;++c)
matrix(r, c) = i++;
for (std::size_t r = 0; r < rows; ++r)
for (std::size_t c = 0; c < cols; ++c) matrix(r, c) = i++;
rotgen::conservativeResize(matrix, rows + 3, cols + 2);
TTS_EQUAL(rotgen::size(matrix), (rows + 3)*(cols + 2));
TTS_EQUAL(rotgen::size(matrix), (rows + 3) * (cols + 2));
i = 1;
for(std::size_t r=0;r<rows;++r)
for(std::size_t c=0;c<cols;++c)
TTS_EQUAL(matrix(r,c),i++);
for (std::size_t r = 0; r < rows; ++r)
for (std::size_t c = 0; c < cols; ++c) TTS_EQUAL(matrix(r, c), i++);
}
TTS_CASE("Matrix size-related operations")
@ -63,18 +62,37 @@ TTS_CASE("Matrix size-related operations")
std::vector<MatrixDescriptor<rotgen::matrix<double>>> test_matrices = {
{3, 3, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = r + c; }},
{2, 3, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = 0.0; }},
{2, 7, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = -r*r*r - c*c - 1.23; }},
{17, 3, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = r*c + 0.98; }},
{2, 7,
[](auto& m, std::size_t r, std::size_t c) {
m(r, c) = -r * r * r - c * c - 1.23;
}},
{17, 3,
[](auto& m, std::size_t r, std::size_t c) { m(r, c) = r * c + 0.98; }},
{1, 1, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = 42.0; }},
{10, 11, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = std::tan(r + c); }},
{1, 5, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = -1.5*r + 2.56*c + 3.33; }},
{7, 1, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = (r == c ? 1.0 : 0.0); }},
{0, 0, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = (r == c ? 1.0 : 0.0); }},
{10, 11,
[](auto& m, std::size_t r, std::size_t c) { m(r, c) = std::tan(r + c); }},
{1, 5,
[](auto& m, std::size_t r, std::size_t c) {
m(r, c) = -1.5 * r + 2.56 * c + 3.33;
}},
{7, 1,
[](auto& m, std::size_t r, std::size_t c) {
m(r, c) = (r == c ? 1.0 : 0.0);
}},
{0, 0,
[](auto& m, std::size_t r, std::size_t c) {
m(r, c) = (r == c ? 1.0 : 0.0);
}},
};
for (const auto& [rows, cols, init_fn] : test_matrices)
test_matrix_sizes<rotgen::matrix<double>>(rows, cols, init_fn, std::array{
std::pair{1, 2}, std::pair{11, 17}, std::pair{4, 5},
std::pair{9, 1}, std::pair{3, 8}, std::pair{22, 0},
});
for (auto const& [rows, cols, init_fn] : test_matrices)
test_matrix_sizes<rotgen::matrix<double>>(rows, cols, init_fn,
std::array{
std::pair{1, 2},
std::pair{11, 17},
std::pair{4, 5},
std::pair{9, 1},
std::pair{3, 8},
std::pair{22, 0},
});
};

View file

@ -8,23 +8,24 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("SVD decomposition - Dynamic case", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("SVD decomposition - Dynamic case",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
int rank, i = 5;
auto eps = std::numeric_limits<T>::epsilon();
auto m = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>::Random(5,5);
auto m =
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>::Random(5, 5);
auto decomp = rotgen::svd(m);
do
{
rank = decomp.rank();
do {
rank = decomp.rank();
auto u = decomp.U(rank);
auto d = decomp.singular_values(rank);
auto u = decomp.U(rank);
auto d = decomp.singular_values(rank);
auto dd = decomp.D(rank);
auto v = decomp.V(rank);
auto v = decomp.V(rank);
TTS_EQUAL(rank, i);
@ -32,34 +33,36 @@ TTS_CASE_TPL("SVD decomposition - Dynamic case", rotgen::tests::types)
auto error = m - rec;
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 16.)
<< "Result:\n" << rec << "\n"
<< "Residuals:\n" << error << "\n";
<< "Result:\n"
<< rec << "\n"
<< "Residuals:\n"
<< error << "\n";
// Reduce rank by duplicating one column
i--;
col(m,i) = col(m,0);
col(m, i) = col(m, 0);
decomp = rotgen::svd(m);
}while(rank != 1);
} while (rank != 1);
};
TTS_CASE_TPL("SVD decomposition - Static case", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("SVD decomposition - Static case",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
int rank, i = 5;
auto eps = std::numeric_limits<T>::epsilon();
auto m = rotgen::matrix<T,5,5,O::value>::Random();
auto m = rotgen::matrix<T, 5, 5, O::value>::Random();
auto decomp = rotgen::svd(m);
do
{
rank = decomp.rank();
do {
rank = decomp.rank();
auto u = decomp.U(rank);
auto d = decomp.singular_values(rank);
auto u = decomp.U(rank);
auto d = decomp.singular_values(rank);
auto dd = decomp.D(rank);
auto v = decomp.V(rank);
auto v = decomp.V(rank);
TTS_EQUAL(rank, i);
@ -67,13 +70,15 @@ TTS_CASE_TPL("SVD decomposition - Static case", rotgen::tests::types)
auto error = m - rec;
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 16.)
<< "Result:\n" << rec << "\n"
<< "Residuals:\n" << error << "\n";
<< "Result:\n"
<< rec << "\n"
<< "Residuals:\n"
<< error << "\n";
// Reduce rank by duplicating one column
i--;
col(m,i) = col(m,0);
col(m, i) = col(m, 0);
decomp = rotgen::svd(m);
}while(rank != 1);
};
} while (rank != 1);
};

View file

@ -9,101 +9,109 @@
#include "unit/common/arithmetic.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic map transposition-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic map transposition-like operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
mat_t base(rows, cols);
rotgen::tests::prepare(rows,cols,fn,base);
rotgen::tests::prepare(rows, cols, fn, base);
rotgen::map<mat_t> input(base.data(),rows,cols);
rotgen::map<mat_t> input(base.data(), rows, cols);
rotgen::tests::check_shape_functions(input);
}
};
TTS_CASE_TPL("Test static map transposition-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static map transposition-like 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,rotgen::Dynamic,rotgen::Dynamic,O::value> base(D::rows,D::cols);
rotgen::tests::prepare(base.rows(),base.cols(),desc.init_fn,base);
auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows,
D::cols);
rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base);
rotgen::map<rotgen::matrix<T,D::rows,D::cols,O::value>> input(base.data());
rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input(
base.data());
rotgen::tests::check_shape_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};
TTS_CASE_TPL("Test dynamic map reduction-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic map reduction-like operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> base(rows, cols);
rotgen::tests::prepare(rows,cols,fn,base);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(rows,
cols);
rotgen::tests::prepare(rows, cols, fn, base);
rotgen::map<rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>> input(base.data(),rows,cols);
rotgen::map<rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>>
input(base.data(), rows, cols);
rotgen::tests::check_reduction_functions(input);
}
};
TTS_CASE_TPL("Test static map reduction-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static map reduction-like 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,rotgen::Dynamic,rotgen::Dynamic,O::value> base(D::rows,D::cols);
rotgen::tests::prepare(base.rows(),base.cols(),desc.init_fn,base);
auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows,
D::cols);
rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base);
rotgen::map<rotgen::matrix<T,D::rows,D::cols,O::value>> input(base.data());
rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input(
base.data());
rotgen::tests::check_reduction_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};
TTS_CASE_TPL("Test dot product", float, double)
<typename T>( tts::type<T> )
TTS_CASE_TPL("Test dot product", float, double)<typename T>(tts::type<T>){
{auto v = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1,
16,
2);
auto a = rotgen::map<decltype(v)>(v.data(), 1, 8);
auto b = rotgen::map<decltype(v)>(v.data() + 8, 1, 8);
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
{
auto v = rotgen::setConstant<rotgen::matrix<T,1,rotgen::Dynamic>>(1,16,2);
auto a = rotgen::map<decltype(v)>(v.data(),1,8);
auto b = rotgen::map<decltype(v)>(v.data()+8,1,8);
auto v = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(16, 1, 2);
auto a = rotgen::map<decltype(v)>(v.data(), 8, 1);
auto b = rotgen::map<decltype(v)>(v.data() + 8, 8, 1);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
auto v = rotgen::setConstant<rotgen::matrix<T,rotgen::Dynamic,1>>(16,1,2);
auto a = rotgen::map<decltype(v)>(v.data(),8,1);
auto b = rotgen::map<decltype(v)>(v.data()+8,8,1);
{
auto v = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 16, 2);
auto a = rotgen::map<rotgen::matrix<T, 1, 8>>(v.data());
auto b = rotgen::map<rotgen::matrix<T, 1, 8>>(v.data() + 8);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
auto v = rotgen::setConstant<rotgen::matrix<T,1,rotgen::Dynamic>>(1,16,2);
auto a = rotgen::map<rotgen::matrix<T,1,8>>(v.data());
auto b = rotgen::map<rotgen::matrix<T,1,8>>(v.data()+8);
{
auto v = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 16, 2);
auto a = rotgen::map<rotgen::matrix<T, 8, 1>>(v.data());
auto b = rotgen::map<rotgen::matrix<T, 8, 1>>(v.data() + 8);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
{
auto v = rotgen::setConstant<rotgen::matrix<T,1,rotgen::Dynamic>>(1,16,2);
auto a = rotgen::map<rotgen::matrix<T,8,1>>(v.data());
auto b = rotgen::map<rotgen::matrix<T,8,1>>(v.data()+8);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
};
TTS_EQUAL(rotgen::dot(a, b), 32);
}
}
;

View file

@ -8,88 +8,90 @@
#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>> )
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};
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
rotgen::map<rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>> dyn_map(data,1,12);
rotgen::map<rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>>
dyn_map(data, 1, 12);
TTS_EQUAL(dyn_map.rows(), rotgen::Index{1});
TTS_EQUAL(dyn_map.cols(), rotgen::Index{12});
rotgen::map<rotgen::matrix<T,1,12,rotgen::RowMajor>> s112_map(data);
rotgen::map<rotgen::matrix<T, 1, 12, rotgen::RowMajor>> s112_map(data);
TTS_EQUAL(s112_map.rows(), rotgen::Index{1});
TTS_EQUAL(s112_map.cols(), rotgen::Index{12});
TTS_EQUAL(s112_map.size(), rotgen::Index{12});
rotgen::map<rotgen::matrix<T,12,1,rotgen::ColMajor>> s121_map(data);
rotgen::map<rotgen::matrix<T, 12, 1, rotgen::ColMajor>> s121_map(data);
TTS_EQUAL(s121_map.rows(), rotgen::Index{12});
TTS_EQUAL(s121_map.cols(), rotgen::Index{1});
TTS_EQUAL(s121_map.size(), rotgen::Index{12});
rotgen::map<rotgen::matrix<T,3,4,O::value>> s34_map(data);
rotgen::map<rotgen::matrix<T, 3, 4, O::value>> s34_map(data);
TTS_EQUAL(s34_map.rows(), rotgen::Index{3});
TTS_EQUAL(s34_map.cols(), rotgen::Index{4});
TTS_EQUAL(s34_map.size(), rotgen::Index{12});
rotgen::map<rotgen::matrix<T,6,2,O::value>> s62_map(data);
rotgen::map<rotgen::matrix<T, 6, 2, O::value>> s62_map(data);
TTS_EQUAL(s62_map.rows(), rotgen::Index{6});
TTS_EQUAL(s62_map.cols(), rotgen::Index{2});
TTS_EQUAL(s62_map.size(), rotgen::Index{12});
};
TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
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>;
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};
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
rotgen::map<base> a(data,4,3);
for(rotgen::Index i=0;i<4;i++)
rotgen::map<base> a(data, 4, 3);
for (rotgen::Index i = 0; i < 4; i++)
{
for(rotgen::Index j=0;j<3;j++)
for (rotgen::Index j = 0; j < 3; j++)
{
if constexpr(O::value) TTS_EQUAL(a(i,j), data[j+3*i]);
else TTS_EQUAL(a(i,j), data[i+4*j]);
if constexpr (O::value) TTS_EQUAL(a(i, j), data[j + 3 * i]);
else TTS_EQUAL(a(i, j), data[i + 4 * j]);
}
}
a(1, 1) = 42;
TTS_EQUAL(a(1,1), 42);
TTS_EQUAL(a(1, 1), 42);
T& ref = a(2, 2);
ref = 17;
TTS_EQUAL(a(2, 2), 17);
};
TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test one index coefficient accessors",
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};
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
auto m = [&]()
{
if constexpr(O::value == rotgen::ColMajor)
auto m = [&]() {
if constexpr (O::value == rotgen::ColMajor)
{
using base = rotgen::matrix<T,1,rotgen::Dynamic>;
rotgen::map<base> a(data,12);
using base = rotgen::matrix<T, 1, rotgen::Dynamic>;
rotgen::map<base> a(data, 12);
return a;
}
else
{
using base = rotgen::matrix<T,rotgen::Dynamic,1>;
rotgen::map<base> a(data,12);
using base = rotgen::matrix<T, rotgen::Dynamic, 1>;
rotgen::map<base> a(data, 12);
return a;
}
}();
TTS_EXPECT(m.IsVectorAtCompileTime);
for(rotgen::Index i=0;i<m.size();i++)
for (rotgen::Index i = 0; i < m.size(); i++)
TTS_EQUAL(m(i), data[i]) << "Index: " << i << "\n";
for(rotgen::Index i=0;i<m.size();i++)
for (rotgen::Index i = 0; i < m.size(); i++)
TTS_EQUAL(m[i], data[i]) << "Index: " << i << "\n";
m(1) = 42;

View file

@ -8,82 +8,84 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("map constructor from pointer and single static size", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("map constructor from pointer and single static 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};
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
rotgen::map<rotgen::matrix<T,1,12,rotgen::RowMajor>> row_map(data);
for(rotgen::Index i=0;i<12;i++)
TTS_EQUAL(row_map(i), data[i]);
rotgen::map<rotgen::matrix<T, 1, 12, rotgen::RowMajor>> row_map(data);
for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(row_map(i), data[i]);
rotgen::map<rotgen::matrix<T,1,12,rotgen::RowMajor> const> const_row_map(data);
for(rotgen::Index i=0;i<12;i++)
TTS_EQUAL(const_row_map(i), data[i]);
rotgen::map<rotgen::matrix<T, 1, 12, rotgen::RowMajor> const> const_row_map(
data);
for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(const_row_map(i), data[i]);
rotgen::map<rotgen::matrix<T,12,1,rotgen::ColMajor>> col_map(data);
for(rotgen::Index i=0;i<12;i++)
TTS_EQUAL(col_map(i), data[i]);
rotgen::map<rotgen::matrix<T, 12, 1, rotgen::ColMajor>> col_map(data);
for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(col_map(i), data[i]);
rotgen::map<rotgen::matrix<T,12,1,rotgen::ColMajor> const> const_col_map(data);
for(rotgen::Index i=0;i<12;i++)
TTS_EQUAL(const_col_map(i), data[i]);
rotgen::map<rotgen::matrix<T, 12, 1, rotgen::ColMajor> const> const_col_map(
data);
for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(const_col_map(i), data[i]);
};
TTS_CASE_TPL("map constructor from pointer and static size", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("map constructor from pointer and static size",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using base = rotgen::matrix<T,4,3,O::value>;
using base = rotgen::matrix<T, 4, 3, O::value>;
T data[] = {1,2,3,4,5,6,7,8,9,10,11,12};
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
rotgen::map<base> dyn_map(data);
for(rotgen::Index i=0;i<4;i++)
for (rotgen::Index i = 0; i < 4; i++)
{
for(rotgen::Index j=0;j<3;j++)
for (rotgen::Index j = 0; j < 3; j++)
{
if constexpr(O::value) TTS_EQUAL(dyn_map(i,j), data[j+3*i]);
else TTS_EQUAL(dyn_map(i,j), data[i+4*j]);
if constexpr (O::value) TTS_EQUAL(dyn_map(i, j), data[j + 3 * i]);
else TTS_EQUAL(dyn_map(i, j), data[i + 4 * j]);
}
}
};
TTS_CASE_TPL("map constructor from pointer and single dynamic size", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("map constructor from pointer and single dynamic 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};
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
rotgen::map<rotgen::matrix<T,1,rotgen::Dynamic,rotgen::RowMajor>> row_map(data,12);
for(rotgen::Index i=0;i<12;i++)
TTS_EQUAL(row_map(i), data[i]);
rotgen::map<rotgen::matrix<T, 1, rotgen::Dynamic, rotgen::RowMajor>> row_map(
data, 12);
for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(row_map(i), data[i]);
rotgen::map<rotgen::matrix<T,1,rotgen::Dynamic,rotgen::RowMajor> const> const_row_map(data,12);
for(rotgen::Index i=0;i<12;i++)
TTS_EQUAL(const_row_map(i), data[i]);
rotgen::map<rotgen::matrix<T, 1, rotgen::Dynamic, rotgen::RowMajor> const>
const_row_map(data, 12);
for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(const_row_map(i), data[i]);
rotgen::map<rotgen::matrix<T,rotgen::Dynamic,1,rotgen::ColMajor>> col_map(data,12);
for(rotgen::Index i=0;i<12;i++)
TTS_EQUAL(col_map(i), data[i]);
rotgen::map<rotgen::matrix<T, rotgen::Dynamic, 1, rotgen::ColMajor>> col_map(
data, 12);
for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(col_map(i), data[i]);
rotgen::map<rotgen::matrix<T,rotgen::Dynamic,1,rotgen::ColMajor> const> const_col_map(data,12);
for(rotgen::Index i=0;i<12;i++)
TTS_EQUAL(const_col_map(i), data[i]);
rotgen::map<rotgen::matrix<T, rotgen::Dynamic, 1, rotgen::ColMajor> const>
const_col_map(data, 12);
for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(const_col_map(i), data[i]);
};
TTS_CASE_TPL("map constructor from pointer and dynamic size", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("map constructor from pointer and dynamic size",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using base = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
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};
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
rotgen::map<base> dyn_map(data,4,3);
for(rotgen::Index i=0;i<4;i++)
rotgen::map<base> dyn_map(data, 4, 3);
for (rotgen::Index i = 0; i < 4; i++)
{
for(rotgen::Index j=0;j<3;j++)
for (rotgen::Index j = 0; j < 3; j++)
{
if constexpr(O::value) TTS_EQUAL(dyn_map(i,j), data[j+3*i]);
else TTS_EQUAL(dyn_map(i,j), data[i+4*j]);
if constexpr (O::value) TTS_EQUAL(dyn_map(i, j), data[j + 3 * i]);
else TTS_EQUAL(dyn_map(i, j), data[i + 4 * j]);
}
}
};

View file

@ -9,33 +9,38 @@
#include "unit/common/cwise.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic map cwise operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic map cwise operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> base(rows, cols);
rotgen::tests::prepare(rows,cols,fn,base);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(rows,
cols);
rotgen::tests::prepare(rows, cols, fn, base);
rotgen::map<rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>> input(base.data(),rows,cols);
rotgen::map<rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>>
input(base.data(), rows, cols);
rotgen::tests::check_cwise_functions(input);
}
};
TTS_CASE_TPL("Test static map cwise operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static map cwise 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,rotgen::Dynamic,rotgen::Dynamic,O::value> base(D::rows,D::cols);
rotgen::tests::prepare(base.rows(),base.cols(),desc.init_fn,base);
auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows,
D::cols);
rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base);
rotgen::map<rotgen::matrix<T,D::rows,D::cols,O::value>> input(base.data());
rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input(
base.data());
rotgen::tests::check_cwise_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
};
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -9,33 +9,38 @@
#include "unit/common/norms.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic map norm operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic map norm operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> base(rows, cols);
rotgen::tests::prepare(rows,cols,fn,base);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(rows,
cols);
rotgen::tests::prepare(rows, cols, fn, base);
rotgen::map<rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>> input(base.data(),rows,cols);
rotgen::map<rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>>
input(base.data(), rows, cols);
rotgen::tests::check_norms_functions(input);
}
};
TTS_CASE_TPL("Test static map norm operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static map 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,rotgen::Dynamic,rotgen::Dynamic,O::value> base(D::rows,D::cols);
rotgen::tests::prepare(base.rows(),base.cols(),desc.init_fn,base);
auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows,
D::cols);
rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base);
rotgen::map<rotgen::matrix<T,D::rows,D::cols,O::value>> input(base.data());
rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input(
base.data());
rotgen::tests::check_norms_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
};
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -9,8 +9,13 @@
#include <rotgen/rotgen.hpp>
#include <vector>
template <typename MatrixType>
void test_map_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn, auto ops, auto self_ops)
template<typename MatrixType>
void test_map_operations(rotgen::Index rows,
rotgen::Index cols,
auto a_init_fn,
auto b_init_fn,
auto ops,
auto self_ops)
{
MatrixType a_data(rows, cols);
MatrixType b_data(rows, cols);
@ -19,8 +24,8 @@ void test_map_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn,
for (rotgen::Index r = 0; r < rows; ++r)
for (rotgen::Index c = 0; c < cols; ++c)
{
a_data(r,c) = a_init_fn(r, c);
b_data(r,c) = b_init_fn(r, c);
a_data(r, c) = a_init_fn(r, c);
b_data(r, c) = b_init_fn(r, c);
}
ref_data = ops(a_data, b_data);
@ -35,15 +40,19 @@ void test_map_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn,
TTS_EXPECT(verify_rotgen_reentrance(self_ops(a_map, b_map)));
}
template <typename MatrixType>
void test_map_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto fn, auto s, auto ops, auto self_ops)
template<typename MatrixType>
void test_map_scalar_operations(rotgen::Index rows,
rotgen::Index cols,
auto fn,
auto s,
auto ops,
auto self_ops)
{
MatrixType a_data(rows, cols);
MatrixType ref_data;
for (rotgen::Index r = 0; r < rows; ++r)
for (rotgen::Index c = 0; c < cols; ++c)
a_data(r,c) = fn(r, c);
for (rotgen::Index c = 0; c < cols; ++c) a_data(r, c) = fn(r, c);
ref_data = ops(a_data, s);
rotgen::map<MatrixType> a_map(a_data.data(), rows, cols);
@ -56,15 +65,17 @@ void test_map_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto fn,
TTS_EXPECT(verify_rotgen_reentrance(self_ops(a_map, s)));
}
template <typename MatrixType>
void test_map_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn, auto s)
template<typename MatrixType>
void test_map_scalar_multiplications(rotgen::Index rows,
rotgen::Index cols,
auto fn,
auto s)
{
MatrixType a_data(rows, cols);
MatrixType ref_data;
for (rotgen::Index r = 0; r < rows; ++r)
for (rotgen::Index c = 0; c < cols; ++c)
a_data(r,c) = fn(r, c);
for (rotgen::Index c = 0; c < cols; ++c) a_data(r, c) = fn(r, c);
ref_data = a_data * s;
rotgen::map<MatrixType> a_map(a_data.data(), rows, cols);
@ -79,8 +90,11 @@ void test_map_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, aut
TTS_EXPECT(verify_rotgen_reentrance(a_map *= s));
}
template <typename MatrixType>
void test_map_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn)
template<typename MatrixType>
void test_map_multiplication(rotgen::Index rows,
rotgen::Index cols,
auto a_init_fn,
auto b_init_fn)
{
MatrixType a_data(rows, cols);
MatrixType b_data(cols, rows);
@ -89,8 +103,8 @@ void test_map_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_init
for (rotgen::Index r = 0; r < rows; ++r)
for (rotgen::Index c = 0; c < cols; ++c)
{
a_data(r,c) = a_init_fn(r,c);
b_data(c,r) = b_init_fn(c,r);
a_data(r, c) = a_init_fn(r, c);
b_data(c, r) = b_init_fn(c, r);
}
ref_data = a_data * b_data;
@ -100,103 +114,111 @@ void test_map_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_init
TTS_EQUAL(a_map * b_map, ref_data);
TTS_EXPECT(verify_rotgen_reentrance(a_map * b_map));
if(rows == cols)
if (rows == cols)
{
a_map *= b_map;
TTS_EQUAL(a_map, ref_data);
TTS_EXPECT(verify_rotgen_reentrance(a_map *= b_map));
}
}
inline constexpr auto init_a = [](auto r, auto c) { return 9.9*r*r*r - 6*c - 12; };
inline constexpr auto init_b = [](auto r, auto c) { return 3.1*r + 4.2*c - 12.3; };
inline constexpr auto init_0 = [](auto , auto ) { return 0; };
inline constexpr auto init_a = [](auto r, auto c) {
return 9.9 * r * r * r - 6 * c - 12;
};
inline constexpr auto init_b = [](auto r, auto c) {
return 3.1 * r + 4.2 * c - 12.3;
};
inline constexpr auto init_0 = [](auto, auto) { return 0; };
TTS_CASE_TPL("Check map addition", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check map addition",
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 op = [](auto a, auto b) { return a + b; };
auto s_op = [](auto& a, auto b) { return a += b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a + b; };
auto s_op = [](auto& a, auto b) { return a += b; };
test_map_operations<mat_t>(1 , 1, init_a, init_b, op, s_op);
test_map_operations<mat_t>(3 , 5, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5 , 3, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5 , 5, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5 , 5, init_b, init_a, op, s_op);
test_map_operations<mat_t>(1, 1, init_a, init_b, op, s_op);
test_map_operations<mat_t>(3, 5, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5, 3, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5, 5, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5, 5, init_b, init_a, op, s_op);
test_map_operations<mat_t>(10, 1, init_a, init_b, op, s_op);
test_map_operations<mat_t>(1 ,10, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5 , 5, init_0, init_b, op, s_op);
test_map_operations<mat_t>(5 , 5, init_a, init_0, op, s_op);
test_map_operations<mat_t>(1, 10, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5, 5, init_0, init_b, op, s_op);
test_map_operations<mat_t>(5, 5, init_a, init_0, op, s_op);
};
TTS_CASE_TPL("Check map subtraction", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check map subtraction",
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 op = [](auto a, auto b) { return a - b; };
auto s_op = [](auto& a, auto b) { return a -= b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a - b; };
auto s_op = [](auto& a, auto b) { return a -= b; };
test_map_operations<mat_t>(1 , 1, init_a, init_b, op, s_op);
test_map_operations<mat_t>(3 , 5, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5 , 3, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5 , 5, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5 , 5, init_b, init_a, op, s_op);
test_map_operations<mat_t>(1, 1, init_a, init_b, op, s_op);
test_map_operations<mat_t>(3, 5, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5, 3, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5, 5, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5, 5, init_b, init_a, op, s_op);
test_map_operations<mat_t>(10, 1, init_a, init_b, op, s_op);
test_map_operations<mat_t>(1 ,10, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5 , 5, init_0, init_b, op, s_op);
test_map_operations<mat_t>(5 , 5, init_a, init_0, op, s_op);
test_map_operations<mat_t>(1, 10, init_a, init_b, op, s_op);
test_map_operations<mat_t>(5, 5, init_0, init_b, op, s_op);
test_map_operations<mat_t>(5, 5, init_a, init_0, op, s_op);
};
TTS_CASE_TPL("Check map multiplications", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check map 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>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto init_id = [](auto r, auto c) { return r == c ? 1 : 0; };
test_map_multiplication<mat_t>(1 , 1, init_a , init_b );
test_map_multiplication<mat_t>(3 , 5, init_a , init_b );
test_map_multiplication<mat_t>(5 , 3, init_a , init_b );
test_map_multiplication<mat_t>(5 , 5, init_a , init_b );
test_map_multiplication<mat_t>(5 , 5, init_b , init_a );
test_map_multiplication<mat_t>(5 , 5, init_a , init_a );
test_map_multiplication<mat_t>(5 , 5, init_a , init_id);
test_map_multiplication<mat_t>(5 , 5, init_id, init_a );
test_map_multiplication<mat_t>(10, 1, init_a , init_b );
test_map_multiplication<mat_t>(1 ,10, init_a , init_b );
test_map_multiplication<mat_t>(5 , 5, init_0 , init_b );
test_map_multiplication<mat_t>(5 , 5, init_a , init_0 );
test_map_multiplication<mat_t>(1, 1, init_a, init_b);
test_map_multiplication<mat_t>(3, 5, init_a, init_b);
test_map_multiplication<mat_t>(5, 3, init_a, init_b);
test_map_multiplication<mat_t>(5, 5, init_a, init_b);
test_map_multiplication<mat_t>(5, 5, init_b, init_a);
test_map_multiplication<mat_t>(5, 5, init_a, init_a);
test_map_multiplication<mat_t>(5, 5, init_a, init_id);
test_map_multiplication<mat_t>(5, 5, init_id, init_a);
test_map_multiplication<mat_t>(10, 1, init_a, init_b);
test_map_multiplication<mat_t>(1, 10, init_a, init_b);
test_map_multiplication<mat_t>(5, 5, init_0, init_b);
test_map_multiplication<mat_t>(5, 5, init_a, init_0);
};
TTS_CASE_TPL("Check map multiplication with scalar", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check map multiplication with scalar",
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>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
test_map_scalar_multiplications<mat_t>(1 , 1, init_a, T{ 3.5});
test_map_scalar_multiplications<mat_t>(3 , 5, init_a, T{-2.5});
test_map_scalar_multiplications<mat_t>(5 , 3, init_a, T{ 4. });
test_map_scalar_multiplications<mat_t>(5 , 5, init_a, T{-5. });
test_map_scalar_multiplications<mat_t>(5 , 5, init_a, T{ 1. });
test_map_scalar_multiplications<mat_t>(5 , 5, init_a, T{ 6. });
test_map_scalar_multiplications<mat_t>(10, 1, init_a, T{ 10.});
test_map_scalar_multiplications<mat_t>(1 ,10, init_a, T{-0.5});
test_map_scalar_multiplications<mat_t>(1, 1, init_a, T{3.5});
test_map_scalar_multiplications<mat_t>(3, 5, init_a, T{-2.5});
test_map_scalar_multiplications<mat_t>(5, 3, init_a, T{4.});
test_map_scalar_multiplications<mat_t>(5, 5, init_a, T{-5.});
test_map_scalar_multiplications<mat_t>(5, 5, init_a, T{1.});
test_map_scalar_multiplications<mat_t>(5, 5, init_a, T{6.});
test_map_scalar_multiplications<mat_t>(10, 1, init_a, T{10.});
test_map_scalar_multiplications<mat_t>(1, 10, init_a, T{-0.5});
};
TTS_CASE_TPL("Check map division with scalar", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check map division with scalar",
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 op = [](auto a, auto b) { return a / b; };
auto s_op = [](auto& a, auto b) { return a /= b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a / b; };
auto s_op = [](auto& a, auto b) { return a /= b; };
test_map_scalar_operations<mat_t>(1 , 1, init_a, T{ 3.5}, op, s_op);
test_map_scalar_operations<mat_t>(3 , 5, init_a, T{-2.5}, op, s_op);
test_map_scalar_operations<mat_t>(5 , 3, init_a, T{ 4. }, op, s_op);
test_map_scalar_operations<mat_t>(5 , 5, init_a, T{-5. }, op, s_op);
test_map_scalar_operations<mat_t>(5 , 5, init_a, T{ 1. }, op, s_op);
test_map_scalar_operations<mat_t>(5 , 5, init_a, T{ 6. }, op, s_op);
test_map_scalar_operations<mat_t>(10, 1, init_a, T{ 10.}, op, s_op);
test_map_scalar_operations<mat_t>(1 ,10, init_a, T{-0.5}, op, s_op);
test_map_scalar_operations<mat_t>(1, 1, init_a, T{3.5}, op, s_op);
test_map_scalar_operations<mat_t>(3, 5, init_a, T{-2.5}, op, s_op);
test_map_scalar_operations<mat_t>(5, 3, init_a, T{4.}, op, s_op);
test_map_scalar_operations<mat_t>(5, 5, init_a, T{-5.}, op, s_op);
test_map_scalar_operations<mat_t>(5, 5, init_a, T{1.}, op, s_op);
test_map_scalar_operations<mat_t>(5, 5, init_a, T{6.}, op, s_op);
test_map_scalar_operations<mat_t>(10, 1, init_a, T{10.}, op, s_op);
test_map_scalar_operations<mat_t>(1, 10, init_a, T{-0.5}, op, s_op);
};

View file

@ -15,132 +15,138 @@ auto generate_data(int rows, int cols)
std::vector<float> buffer(rows * cols * 3);
for (size_t i = 0; i < buffer.size(); ++i)
buffer[i] = static_cast<float>(1+i);
buffer[i] = static_cast<float>(1 + i);
return buffer;
}
template<int O>
using r_mat_t = rotgen::matrix<float,rotgen::Dynamic,rotgen::Dynamic,O>;
using r_mat_t = rotgen::matrix<float, rotgen::Dynamic, rotgen::Dynamic, O>;
template<int O>
using e_mat_t = Eigen::Matrix<float,Eigen::Dynamic,Eigen::Dynamic,O>;
using e_mat_t = Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, O>;
template<typename M, typename S = rotgen::stride> using r_map_t = rotgen::map<M,0,S>;
template<typename M, typename S = Eigen::Stride<0,0>> using e_map_t = Eigen::Map<M,0,S>;
template<typename M, typename S = rotgen::stride>
using r_map_t = rotgen::map<M, 0, S>;
template<typename M, typename S = Eigen::Stride<0, 0>>
using e_map_t = Eigen::Map<M, 0, S>;
TTS_CASE("Validate Column Major Map with regular stride behavior")
{
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows,cols);
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows, cols);
r_map_t<r_mat_t<rotgen::ColMajor>> r_map(buffer.data(), rows, cols);
TTS_EQUAL(r_map.innerStride(), 1);
TTS_EQUAL(r_map.outerStride(), 3);
e_map_t<e_mat_t<Eigen::ColMajor>> e_map(buffer.data(), rows, cols);
e_map_t<e_mat_t<Eigen::ColMajor>> e_map(buffer.data(), rows, cols);
for(std::ptrdiff_t r=0;r<rows;r++)
for(std::ptrdiff_t c=0;c<cols;c++)
TTS_EQUAL(r_map(r,c), e_map(r,c));
for (std::ptrdiff_t r = 0; r < rows; r++)
for (std::ptrdiff_t c = 0; c < cols; c++)
TTS_EQUAL(r_map(r, c), e_map(r, c));
};
TTS_CASE("Validate Column Major Map with specific outer stride behavior")
{
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows,cols);
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows, cols);
r_map_t<r_mat_t<rotgen::ColMajor>, rotgen::outer_stride<>>
r_map(buffer.data(), rows, cols, rotgen::outer_stride(rows + 1));
r_map_t<r_mat_t<rotgen::ColMajor>, rotgen::outer_stride<>> r_map(
buffer.data(), rows, cols, rotgen::outer_stride(rows + 1));
TTS_EQUAL(r_map.innerStride(), 1);
TTS_EQUAL(r_map.outerStride() , 4);
TTS_EQUAL(r_map.innerStride(), 1);
TTS_EQUAL(r_map.outerStride(), 4);
e_map_t<e_mat_t<Eigen::ColMajor>, Eigen::OuterStride<>>
e_map(buffer.data(), rows, cols, Eigen::OuterStride<>(rows + 1));
e_map_t<e_mat_t<Eigen::ColMajor>, Eigen::OuterStride<>> e_map(
buffer.data(), rows, cols, Eigen::OuterStride<>(rows + 1));
for(std::ptrdiff_t r=0;r<rows;r++)
for(std::ptrdiff_t c=0;c<cols;c++)
TTS_EQUAL(r_map(r,c), e_map(r,c));
for (std::ptrdiff_t r = 0; r < rows; r++)
for (std::ptrdiff_t c = 0; c < cols; c++)
TTS_EQUAL(r_map(r, c), e_map(r, c));
};
TTS_CASE("Validate Column Major Map with specific inner stride behavior")
{
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows,cols);
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows, cols);
r_map_t<r_mat_t<rotgen::ColMajor>>
r_map(buffer.data(), rows, cols, rotgen::stride(rows, 2));
r_map_t<r_mat_t<rotgen::ColMajor>> r_map(buffer.data(), rows, cols,
rotgen::stride(rows, 2));
TTS_EQUAL(r_map.innerStride(), 2);
TTS_EQUAL(r_map.outerStride() , 3);
TTS_EQUAL(r_map.innerStride(), 2);
TTS_EQUAL(r_map.outerStride(), 3);
e_map_t<e_mat_t<Eigen::ColMajor>,Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic>>
e_map(buffer.data(), rows, cols, Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic>(rows,2));
e_map_t<e_mat_t<Eigen::ColMajor>,
Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>>
e_map(buffer.data(), rows, cols,
Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>(rows, 2));
for(std::ptrdiff_t r=0;r<rows;r++)
for(std::ptrdiff_t c=0;c<cols;c++)
TTS_EQUAL(r_map(r,c), e_map(r,c));
for (std::ptrdiff_t r = 0; r < rows; r++)
for (std::ptrdiff_t c = 0; c < cols; c++)
TTS_EQUAL(r_map(r, c), e_map(r, c));
};
TTS_CASE("Validate Row Major Map with regular stride behavior")
{
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows,cols);
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows, cols);
r_map_t<r_mat_t<rotgen::RowMajor>> r_map(buffer.data(), rows, cols);
TTS_EQUAL(r_map.innerStride(), 1);
TTS_EQUAL(r_map.outerStride(), 4);
e_map_t<e_mat_t<Eigen::RowMajor>> e_map(buffer.data(), rows, cols);
e_map_t<e_mat_t<Eigen::RowMajor>> e_map(buffer.data(), rows, cols);
for(std::ptrdiff_t r=0;r<rows;r++)
for(std::ptrdiff_t c=0;c<cols;c++)
TTS_EQUAL(r_map(r,c), e_map(r,c));
for (std::ptrdiff_t r = 0; r < rows; r++)
for (std::ptrdiff_t c = 0; c < cols; c++)
TTS_EQUAL(r_map(r, c), e_map(r, c));
};
TTS_CASE("Validate Row Major Map with specific outer stride behavior")
{
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows,cols);
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows, cols);
r_map_t<r_mat_t<rotgen::RowMajor>, rotgen::outer_stride<>>
r_map(buffer.data(), rows, cols, rotgen::outer_stride(cols + 1));
r_map_t<r_mat_t<rotgen::RowMajor>, rotgen::outer_stride<>> r_map(
buffer.data(), rows, cols, rotgen::outer_stride(cols + 1));
TTS_EQUAL(r_map.innerStride(), 1);
TTS_EQUAL(r_map.outerStride() , 5);
TTS_EQUAL(r_map.innerStride(), 1);
TTS_EQUAL(r_map.outerStride(), 5);
e_map_t<e_mat_t<Eigen::RowMajor>, Eigen::OuterStride<>>
e_map(buffer.data(), rows, cols, Eigen::OuterStride<>(cols + 1));
e_map_t<e_mat_t<Eigen::RowMajor>, Eigen::OuterStride<>> e_map(
buffer.data(), rows, cols, Eigen::OuterStride<>(cols + 1));
for(std::ptrdiff_t r=0;r<rows;r++)
for(std::ptrdiff_t c=0;c<cols;c++)
TTS_EQUAL(r_map(r,c), e_map(r,c));
for (std::ptrdiff_t r = 0; r < rows; r++)
for (std::ptrdiff_t c = 0; c < cols; c++)
TTS_EQUAL(r_map(r, c), e_map(r, c));
};
TTS_CASE("Validate Row Major Map with specific inner stride behavior")
{
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows,cols);
auto rows = 3;
auto cols = 4;
auto buffer = generate_data(rows, cols);
r_map_t<r_mat_t<rotgen::RowMajor>,rotgen::stride>
r_map(buffer.data(), rows, cols, rotgen::stride(2, cols));
r_map_t<r_mat_t<rotgen::RowMajor>, rotgen::stride> r_map(
buffer.data(), rows, cols, rotgen::stride(2, cols));
TTS_EQUAL(r_map.innerStride(), 4);
TTS_EQUAL(r_map.outerStride() , 2);
TTS_EQUAL(r_map.innerStride(), 4);
TTS_EQUAL(r_map.outerStride(), 2);
e_map_t<e_mat_t<Eigen::RowMajor>,Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic>>
e_map(buffer.data(), rows, cols, Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic>(2,cols));
e_map_t<e_mat_t<Eigen::RowMajor>,
Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>>
e_map(buffer.data(), rows, cols,
Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>(2, cols));
for(std::ptrdiff_t r=0;r<rows;r++)
for(std::ptrdiff_t c=0;c<cols;c++)
TTS_EQUAL(r_map(r,c), e_map(r,c));
};
for (std::ptrdiff_t r = 0; r < rows; r++)
for (std::ptrdiff_t c = 0; c < cols; c++)
TTS_EQUAL(r_map(r, c), e_map(r, c));
};

View file

@ -9,88 +9,90 @@
#include "unit/common/arithmetic.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic matrix transposition-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic matrix transposition-like operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> input(rows, cols);
rotgen::tests::prepare(rows,cols,fn,input);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> input(rows,
cols);
rotgen::tests::prepare(rows, cols, fn, input);
rotgen::tests::check_shape_functions(input);
}
};
TTS_CASE_TPL("Test static matrix transposition-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static matrix transposition-like 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);
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_shape_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};
TTS_CASE_TPL("Test dynamic matrix reduction-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic matrix reduction-like operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> input(rows, cols);
rotgen::tests::prepare(rows,cols,fn,input);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> input(rows,
cols);
rotgen::tests::prepare(rows, cols, fn, input);
rotgen::tests::check_reduction_functions(input);
}
};
TTS_CASE_TPL("Test static matrix reduction-like operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static matrix reduction-like 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);
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_reduction_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};
TTS_CASE_TPL("Test dot product", float, double)
<typename T>( tts::type<T> )
TTS_CASE_TPL("Test dot product", float, double)<typename T>(tts::type<T>){
{auto a = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 8, 2);
auto b = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 8, 2);
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
{
auto a = rotgen::setConstant<rotgen::matrix<T,1,rotgen::Dynamic>>(1,8,2);
auto b = rotgen::setConstant<rotgen::matrix<T,1,rotgen::Dynamic>>(1,8,2);
auto a = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(8, 1, 2);
auto b = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(8, 1, 2);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
auto a = rotgen::setConstant<rotgen::matrix<T,rotgen::Dynamic,1>>(8,1,2);
auto b = rotgen::setConstant<rotgen::matrix<T,rotgen::Dynamic,1>>(8,1,2);
{
auto a = rotgen::setConstant<rotgen::matrix<T, 1, 8>>(2);
auto b = rotgen::setConstant<rotgen::matrix<T, 1, 8>>(2);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
TTS_EQUAL(rotgen::dot(a, b), 32);
}
{
auto a = rotgen::setConstant<rotgen::matrix<T,1,8>>(2);
auto b = rotgen::setConstant<rotgen::matrix<T,1,8>>(2);
{
auto a = rotgen::setConstant<rotgen::matrix<T, 8, 1>>(2);
auto b = rotgen::setConstant<rotgen::matrix<T, 8, 1>>(2);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
{
auto a = rotgen::setConstant<rotgen::matrix<T,8,1>>(2);
auto b = rotgen::setConstant<rotgen::matrix<T,8,1>>(2);
TTS_EQUAL(rotgen::dot(a,b), 32);
}
};
TTS_EQUAL(rotgen::dot(a, b), 32);
}
}
;

View file

@ -8,13 +8,15 @@
#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>> )
TTS_CASE_TPL("Function size", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> empty_matrix;
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> matrix(3,4);
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> row_vector(9,1);
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> column_vector(1,5);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> empty_matrix;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix(3, 4);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> row_vector(9,
1);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> column_vector(
1, 5);
TTS_EQUAL(empty_matrix.size(), rotgen::Index{0});
TTS_EQUAL(matrix.size(), rotgen::Index{12});
@ -22,72 +24,69 @@ TTS_CASE_TPL("Function size", rotgen::tests::types)
TTS_EQUAL(column_vector.size(), rotgen::Index{5});
};
TTS_CASE_TPL("Resizing dynamic matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Resizing dynamic matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 3);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(2, 3);
for(rotgen::Index r=0;r<a.rows();++r)
for(rotgen::Index c=0;c<a.cols();++c)
a(r,c) = 42 + 2*c + r;
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = 42 + 2 * c + r;
a.resize(3, 2);
TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(a.cols(), rotgen::Index(2));
for(rotgen::Index r=0;r<a.rows();++r)
for(rotgen::Index c=0;c<a.cols();++c)
TTS_GREATER(a(r,c),0);
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_GREATER(a(r, c), 0);
a.resize(2,2);
a.resize(2, 2);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), rotgen::Index(2));
};
TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Dynamix matrix conservative resizing",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 3);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(2, 3);
int i = 1;
for(rotgen::Index r=0;r<a.rows();++r)
for(rotgen::Index c=0;c<a.cols();++c)
a(r, c) = i++;
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = i++;
a.conservativeResize(2, 3);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), rotgen::Index(3));
i = 1;
for(rotgen::Index r=0;r<a.rows();++r)
for(rotgen::Index c=0;c<a.cols();++c)
TTS_EQUAL(a(r,c),i++);
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_EQUAL(a(r, c), i++);
a.conservativeResize(3, 2);
TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(a.cols(), rotgen::Index(2));
int expected[3][2] = { {1, 2}, {4, 5} };
for(rotgen::Index r = 0; r < 2; ++r)
for(rotgen::Index c = 0; c < 2; ++c)
TTS_EQUAL(a(r, c), expected[r][c]);
int expected[3][2] = {{1, 2}, {4, 5}};
for (rotgen::Index r = 0; r < 2; ++r)
for (rotgen::Index c = 0; c < 2; ++c) TTS_EQUAL(a(r, c), expected[r][c]);
a.conservativeResize(4, 4);
TTS_EQUAL(a.rows(), rotgen::Index(4));
TTS_EQUAL(a.cols(), rotgen::Index(4));
TTS_EQUAL(a(0,0), 1);
TTS_EQUAL(a(3,3), 0);
TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(3, 3), 0);
a.conservativeResize(2, 2);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(a(0,0), 1);
TTS_EQUAL(a(1,1), 5);
TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(1, 1), 5);
a.conservativeResize(1, 2);
TTS_EQUAL(a.rows(), rotgen::Index(1));
TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(a(0,0), 1);
TTS_EQUAL(a(0,1), 2);
TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(0, 1), 2);
a.conservativeResize(0, 0);
TTS_EQUAL(a.rows(), rotgen::Index(0));
@ -98,50 +97,48 @@ TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types)
TTS_EQUAL(a.cols(), rotgen::Index(3));
};
TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(3, 5);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(3, 5);
for(rotgen::Index r=0;r<a.rows();++r)
for(rotgen::Index c=0;c<a.cols();++c)
a(r, c) = r + 2 * c + 3;
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = r + 2 * c + 3;
TTS_EQUAL(a(0,0), 3);
TTS_EQUAL(a(1,1), 6);
TTS_EQUAL(a(1,0), 4);
TTS_EQUAL(a(2,2), 9);
TTS_EQUAL(a(2,4), 13);
TTS_EQUAL(a(0, 0), 3);
TTS_EQUAL(a(1, 1), 6);
TTS_EQUAL(a(1, 0), 4);
TTS_EQUAL(a(2, 2), 9);
TTS_EQUAL(a(2, 4), 13);
a(1, 1) = 42;
TTS_EQUAL(a(1,1), 42);
TTS_EQUAL(a(1, 1), 42);
T& ref = a(2, 2);
ref = 17;
TTS_EQUAL(a(2, 2), 17);
};
TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test one index coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto a = [&]()
{
if constexpr(O::value == rotgen::ColMajor) return rotgen::matrix<T,1,rotgen::Dynamic>(1,8);
else return rotgen::matrix<T,rotgen::Dynamic,1>(8,1);
auto a = [&]() {
if constexpr (O::value == rotgen::ColMajor)
return rotgen::matrix<T, 1, rotgen::Dynamic>(1, 8);
else return rotgen::matrix<T, rotgen::Dynamic, 1>(8, 1);
}();
TTS_EXPECT(a.IsVectorAtCompileTime);
for(rotgen::Index s=0;s<a.size();++s)
a(s) = s+1;
for (rotgen::Index s = 0; s < a.size(); ++s) a(s) = s + 1;
int i = 1;
for(rotgen::Index s=0;s<a.size();++s)
TTS_EQUAL(a(s), i++) << a;
for (rotgen::Index s = 0; s < a.size(); ++s) TTS_EQUAL(a(s), i++) << a;
i = 1;
for(rotgen::Index s=0;s<a.size();++s)
TTS_EQUAL(a[s], i++) << a;
for (rotgen::Index s = 0; s < a.size(); ++s) TTS_EQUAL(a[s], i++) << a;
T& ref = a(2);
ref = 999.5;
@ -150,4 +147,4 @@ TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types)
T& bref = a[3];
bref = 42.5;
TTS_EQUAL(a[3], 42.5);
};
};

View file

@ -8,38 +8,42 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Default matrix dynamic constructor", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Default matrix dynamic constructor",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> matrix;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix;
TTS_EQUAL(matrix.rows(), rotgen::Index{0});
TTS_EQUAL(matrix.cols(), rotgen::Index{0});
};
TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Default matrix static constructor",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,4,9,O::value> matrix;
rotgen::matrix<T, 4, 9, O::value> matrix;
TTS_EQUAL(matrix.rows(), rotgen::Index{4});
TTS_EQUAL(matrix.cols(), rotgen::Index{9});
};
TTS_CASE_TPL("Dynamic matrix constructor with row and columns", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Dynamic matrix constructor with row and columns",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> matrix(10, 5);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix(10, 5);
TTS_EQUAL(matrix.rows(), rotgen::Index{10});
TTS_EQUAL(matrix.cols(), rotgen::Index{5});
};
TTS_CASE_TPL("Static matrix constructor with row and columns", float, double)
<typename T>( tts::type<T> )
TTS_CASE_TPL("Static matrix constructor with row and columns",
float,
double)<typename T>(tts::type<T>)
{
rotgen::matrix<T,1,2> v2(6, 11);
rotgen::matrix<T,2,1> w2(6, 11);
rotgen::matrix<T, 1, 2> v2(6, 11);
rotgen::matrix<T, 2, 1> w2(6, 11);
TTS_EQUAL(v2(0), T{6});
TTS_EQUAL(v2(1), T{11});
@ -47,8 +51,8 @@ TTS_CASE_TPL("Static matrix constructor with row and columns", float, double)
TTS_EQUAL(w2(0), T{6});
TTS_EQUAL(w2(1), T{11});
rotgen::matrix<T,1,3> v3(6, 11, 125);
rotgen::matrix<T,3,1> w3(6, 11, 125);
rotgen::matrix<T, 1, 3> v3(6, 11, 125);
rotgen::matrix<T, 3, 1> w3(6, 11, 125);
TTS_EQUAL(v3(0), T{6});
TTS_EQUAL(v3(1), T{11});
@ -59,52 +63,54 @@ TTS_CASE_TPL("Static matrix constructor with row and columns", float, double)
TTS_EQUAL(w3(2), T{125});
};
TTS_CASE_TPL("Copy constructor produces identical but independent matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor produces identical but independent matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(3, 3);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(3, 3);
for(rotgen::Index r=0;r<a.rows();r++)
for(rotgen::Index c=0;c<a.cols();c++)
a(r,c) = r + c;
for (rotgen::Index r = 0; r < a.rows(); r++)
for (rotgen::Index c = 0; c < a.cols(); c++) a(r, c) = r + c;
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a;
TTS_EQUAL(b.rows(), a.rows());
TTS_EQUAL(b.cols(), a.cols());
for(rotgen::Index r=0;r<a.rows();r++)
for(rotgen::Index c=0;c<a.cols();c++)
TTS_EQUAL(b(r,c), a(r,c));
for (rotgen::Index r = 0; r < a.rows(); r++)
for (rotgen::Index c = 0; c < a.cols(); c++) TTS_EQUAL(b(r, c), a(r, c));
TTS_EQUAL(b(0, 0), 0.0);
TTS_EQUAL(b(1, 0), 1.0);
TTS_EQUAL(b(2, 1), 3.0);
a(0,0) = 42.0;
TTS_NOT_EQUAL(b(0,0), a(0,0));
a(0, 0) = 42.0;
TTS_NOT_EQUAL(b(0, 0), a(0, 0));
};
TTS_CASE_TPL("Copy constructor on default matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor on default matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a;
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a;
TTS_EQUAL(b.rows(), rotgen::Index{0});
TTS_EQUAL(b.cols(), rotgen::Index{0});
};
TTS_CASE_TPL("Copy constructor from const matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor from const matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
const rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 2);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> const a(2, 2);
auto b = a;
TTS_EQUAL(b.rows(), rotgen::Index{2});
TTS_EQUAL(b.cols(), rotgen::Index{2});
};
TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor on static matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T, 2, 5> a;
rotgen::matrix<T, 2, 5> b = a;
@ -112,93 +118,100 @@ TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types)
TTS_EQUAL(b.cols(), rotgen::Index{5});
};
TTS_CASE_TPL("Copy constructor on static/dynamic matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor on static/dynamic matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T, 11, 4,O::value> a;
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = a;
rotgen::matrix<T, 11, 4, O::value> a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a;
TTS_EQUAL(b.rows(), 11);
TTS_EQUAL(b.cols(), 4);
};
TTS_CASE_TPL("Copy constructor on dynamic/static matrix", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Copy constructor on dynamic/static matrix",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(5, 7);
rotgen::matrix<T, 5, 7,O::value> b = a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(5, 7);
rotgen::matrix<T, 5, 7, O::value> b = a;
TTS_EQUAL(b.rows(), 5);
TTS_EQUAL(b.cols(), 7);
};
TTS_CASE_TPL("Move constructor transfers contents", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Move constructor transfers contents",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(3, 3);
a(1,1) = 7;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(3, 3);
a(1, 1) = 7;
auto ptr = a.data();
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = std::move(a);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b =
std::move(a);
TTS_EQUAL(b(1,1), 7);
TTS_EQUAL(b(1, 1), 7);
TTS_EQUAL(b.rows(), rotgen::Index{3});
TTS_EQUAL(b.cols(), rotgen::Index{3});
TTS_EXPECT(b.data() == ptr);
};
TTS_CASE_TPL("Move constructor from Rvalue", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Move constructor from Rvalue",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>(2, 2);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b =
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>(2, 2);
TTS_EQUAL(b.rows(), rotgen::Index{2});
TTS_EQUAL(b.cols(), rotgen::Index{2});
};
TTS_CASE_TPL("Constructor from Initializer list", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Constructor from Initializer list",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,1,1,O::value> b1{3.5};
rotgen::matrix<T, 1, 1, O::value> b1{3.5};
TTS_EQUAL(b1.rows(), rotgen::Index{1});
TTS_EQUAL(b1.cols(), rotgen::Index{1});
TTS_EQUAL(b1(0) , 3.5);
TTS_EQUAL(b1(0), 3.5);
rotgen::matrix<T,5,1,rotgen::ColMajor> b9{0.25, 0.5, 1, 2, 4};
rotgen::matrix<T, 5, 1, rotgen::ColMajor> b9{0.25, 0.5, 1, 2, 4};
TTS_EQUAL(b9.rows(), rotgen::Index{5});
TTS_EQUAL(b9.cols(), rotgen::Index{1});
T i = 0.25;
for(rotgen::Index r=0;r<b9.rows();++r)
for (rotgen::Index r = 0; r < b9.rows(); ++r)
{
TTS_EQUAL(b9(r,0), i);
TTS_EQUAL(b9(r, 0), i);
i *= 2;
}
rotgen::matrix<T,1,3,rotgen::RowMajor> b13{1.2,2.3,3.4};
rotgen::matrix<T, 1, 3, rotgen::RowMajor> b13{1.2, 2.3, 3.4};
TTS_EQUAL(b13.rows(), rotgen::Index{1});
TTS_EQUAL(b13.cols(), rotgen::Index{3});
TTS_EQUAL(b13(0) , T(1.2));
TTS_EQUAL(b13(1) , T(2.3));
TTS_EQUAL(b13(2) , T(3.4));
TTS_EQUAL(b13(0), T(1.2));
TTS_EQUAL(b13(1), T(2.3));
TTS_EQUAL(b13(2), T(3.4));
};
TTS_CASE_TPL("Constructor from Initializer list of rows", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Constructor from Initializer list of rows",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b1{{3.5}};
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b1{{3.5}};
TTS_EQUAL(b1.rows(), rotgen::Index{1});
TTS_EQUAL(b1.cols(), rotgen::Index{1});
TTS_EQUAL(b1(0,0) , T(3.5));
TTS_EQUAL(b1(0, 0), T(3.5));
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>
b23 { {1.2,2.3,3.4}
, {10,200,3000}
};
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b23{
{1.2, 2.3, 3.4},
{10, 200, 3000}};
TTS_EQUAL(b23.rows(), rotgen::Index{2});
TTS_EQUAL(b23.cols(), rotgen::Index{3});
TTS_EQUAL(b23(0,0) , T(1.2));
TTS_EQUAL(b23(0,1) , T(2.3));
TTS_EQUAL(b23(0,2) , T(3.4));
TTS_EQUAL(b23(1,0) , T(10));
TTS_EQUAL(b23(1,1) , T(200));
TTS_EQUAL(b23(1,2) , T(3000));
};
TTS_EQUAL(b23(0, 0), T(1.2));
TTS_EQUAL(b23(0, 1), T(2.3));
TTS_EQUAL(b23(0, 2), T(3.4));
TTS_EQUAL(b23(1, 0), T(10));
TTS_EQUAL(b23(1, 1), T(200));
TTS_EQUAL(b23(1, 2), T(3000));
};

View file

@ -9,29 +9,31 @@
#include "unit/common/cwise.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic matrix cwise operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic matrix cwise operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> input(rows, cols);
rotgen::tests::prepare(rows,cols,fn,input);
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> input(rows,
cols);
rotgen::tests::prepare(rows, cols, fn, input);
rotgen::tests::check_cwise_functions(input);
}
};
TTS_CASE_TPL("Test static matrix cwise operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static matrix cwise 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);
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_cwise_functions(input);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
};
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -8,134 +8,141 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
void test_value(const auto& matrix, std::size_t rows, std::size_t cols, auto constant)
void test_value(auto const& 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);
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)
void test_random(auto const& 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)
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)
void test_identity(auto const& 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);
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>> )
TTS_CASE_TPL("Test zero", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using namespace rotgen;
test_value(setZero<matrix<T, 3, 4, O::value> >(), 3, 4, 0);
test_value(setZero<matrix<T, 1, 1, O::value> >(), 1, 1, 0);
test_value(setZero<matrix<T, 10, 10, O::value> >(), 10, 10, 0);
test_value(setZero<matrix<T,Dynamic,Dynamic, O::value>>(3, 4), 3, 4, 0);
test_value(setZero<matrix<T, 7, 5, O::value> >(7, 5), 7, 5, 0);
test_value(setZero<matrix<T, 9,Dynamic> >(9, 3), 9, 3, 0);
test_value(setZero<matrix<T,Dynamic, 3> >(2, 3), 2, 3, 0);
test_value(setZero<matrix<T, 3, 4, O::value>>(), 3, 4, 0);
test_value(setZero<matrix<T, 1, 1, O::value>>(), 1, 1, 0);
test_value(setZero<matrix<T, 10, 10, O::value>>(), 10, 10, 0);
test_value(setZero<matrix<T, Dynamic, Dynamic, O::value>>(3, 4), 3, 4, 0);
test_value(setZero<matrix<T, 7, 5, O::value>>(7, 5), 7, 5, 0);
test_value(setZero<matrix<T, 9, Dynamic>>(9, 3), 9, 3, 0);
test_value(setZero<matrix<T, Dynamic, 3>>(2, 3), 2, 3, 0);
test_value(setZero(matrix<T, 3, 4, O::value>{} ), 3, 4, 0);
test_value(setZero(matrix<T, 1, 1, O::value>{} ), 1, 1, 0);
test_value(setZero(matrix<T, 10, 10, O::value>{} ), 10, 10, 0);
test_value(setZero(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4, 0);
test_value(setZero(matrix<T, 7, 5, O::value>{} ), 7, 5, 0);
test_value(setZero(matrix<T, 9,Dynamic>{9, 3} ), 9, 3, 0);
test_value(setZero(matrix<T,Dynamic, 3>{2, 3} ), 2, 3, 0);
test_value(setZero(matrix<T, 3, 4, O::value>{}), 3, 4, 0);
test_value(setZero(matrix<T, 1, 1, O::value>{}), 1, 1, 0);
test_value(setZero(matrix<T, 10, 10, O::value>{}), 10, 10, 0);
test_value(setZero(matrix<T, Dynamic, Dynamic, O::value>{3, 4}), 3, 4, 0);
test_value(setZero(matrix<T, 7, 5, O::value>{}), 7, 5, 0);
test_value(setZero(matrix<T, 9, Dynamic>{9, 3}), 9, 3, 0);
test_value(setZero(matrix<T, Dynamic, 3>{2, 3}), 2, 3, 0);
};
TTS_CASE_TPL("Test ones", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test ones", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using namespace rotgen;
test_value(setOnes<matrix<T, 3, 4, O::value> >(), 3, 4, 1);
test_value(setOnes<matrix<T, 1, 1, O::value> >(), 1, 1, 1);
test_value(setOnes<matrix<T, 10, 10, O::value> >(), 10, 10, 1);
test_value(setOnes<matrix<T,Dynamic,Dynamic, O::value>>(3, 4), 3, 4, 1);
test_value(setOnes<matrix<T, 7, 5, O::value> >(7, 5), 7, 5, 1);
test_value(setOnes<matrix<T, 9,Dynamic> >(9, 3), 9, 3, 1);
test_value(setOnes<matrix<T,Dynamic, 3> >(2, 3), 2, 3, 1);
test_value(setOnes<matrix<T, 3, 4, O::value>>(), 3, 4, 1);
test_value(setOnes<matrix<T, 1, 1, O::value>>(), 1, 1, 1);
test_value(setOnes<matrix<T, 10, 10, O::value>>(), 10, 10, 1);
test_value(setOnes<matrix<T, Dynamic, Dynamic, O::value>>(3, 4), 3, 4, 1);
test_value(setOnes<matrix<T, 7, 5, O::value>>(7, 5), 7, 5, 1);
test_value(setOnes<matrix<T, 9, Dynamic>>(9, 3), 9, 3, 1);
test_value(setOnes<matrix<T, Dynamic, 3>>(2, 3), 2, 3, 1);
test_value(setOnes(matrix<T, 3, 4, O::value>{} ), 3, 4, 1);
test_value(setOnes(matrix<T, 1, 1, O::value>{} ), 1, 1, 1);
test_value(setOnes(matrix<T, 10, 10, O::value>{} ), 10, 10, 1);
test_value(setOnes(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4, 1);
test_value(setOnes(matrix<T, 7, 5, O::value>{} ), 7, 5, 1);
test_value(setOnes(matrix<T, 9,Dynamic>{9, 3} ), 9, 3, 1);
test_value(setOnes(matrix<T,Dynamic, 3>{2, 3} ), 2, 3, 1);
test_value(setOnes(matrix<T, 3, 4, O::value>{}), 3, 4, 1);
test_value(setOnes(matrix<T, 1, 1, O::value>{}), 1, 1, 1);
test_value(setOnes(matrix<T, 10, 10, O::value>{}), 10, 10, 1);
test_value(setOnes(matrix<T, Dynamic, Dynamic, O::value>{3, 4}), 3, 4, 1);
test_value(setOnes(matrix<T, 7, 5, O::value>{}), 7, 5, 1);
test_value(setOnes(matrix<T, 9, Dynamic>{9, 3}), 9, 3, 1);
test_value(setOnes(matrix<T, Dynamic, 3>{2, 3}), 2, 3, 1);
};
TTS_CASE_TPL("Test constant", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test constant", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using namespace rotgen;
test_value(setConstant<matrix<T, 3, 4, O::value> >(T(5.12)), 3, 4, T(5.12));
test_value(setConstant<matrix<T, 1, 1, O::value> >(T(5.12)), 1, 1, T(5.12));
test_value(setConstant<matrix<T, 10, 10, O::value> >(T(5.12)), 10, 10, T(5.12));
test_value(setConstant<matrix<T,Dynamic,Dynamic, O::value>>(3, 4, T(5.12)), 3, 4, T(5.12));
test_value(setConstant<matrix<T, 7, 5, O::value> >(7, 5, T(5.12)), 7, 5, T(5.12));
test_value(setConstant<matrix<T, 9,Dynamic> >(9, 3, T(5.12)), 9, 3, T(5.12));
test_value(setConstant<matrix<T,Dynamic, 3> >(2, 3, T(5.12)), 2, 3, T(5.12));
test_value(setConstant<matrix<T, 3, 4, O::value>>(T(5.12)), 3, 4, T(5.12));
test_value(setConstant<matrix<T, 1, 1, O::value>>(T(5.12)), 1, 1, T(5.12));
test_value(setConstant<matrix<T, 10, 10, O::value>>(T(5.12)), 10, 10,
T(5.12));
test_value(setConstant<matrix<T, Dynamic, Dynamic, O::value>>(3, 4, T(5.12)),
3, 4, T(5.12));
test_value(setConstant<matrix<T, 7, 5, O::value>>(7, 5, T(5.12)), 7, 5,
T(5.12));
test_value(setConstant<matrix<T, 9, Dynamic>>(9, 3, T(5.12)), 9, 3, T(5.12));
test_value(setConstant<matrix<T, Dynamic, 3>>(2, 3, T(5.12)), 2, 3, T(5.12));
test_value(setConstant(matrix<T, 3, 4, O::value>{} , T(5.12)), 3, 4, T(5.12));
test_value(setConstant(matrix<T, 1, 1, O::value>{} , T(5.12)), 1, 1, T(5.12));
test_value(setConstant(matrix<T, 10, 10, O::value>{} , T(5.12)), 10, 10, T(5.12));
test_value(setConstant(matrix<T,Dynamic,Dynamic, O::value>{3, 4}, T(5.12)), 3, 4, T(5.12));
test_value(setConstant(matrix<T, 7, 5, O::value>{} , T(5.12)), 7, 5, T(5.12));
test_value(setConstant(matrix<T, 9,Dynamic>{9, 3} , T(5.12)), 9, 3, T(5.12));
test_value(setConstant(matrix<T,Dynamic, 3>{2, 3} , T(5.12)), 2, 3, T(5.12));
test_value(setConstant(matrix<T, 3, 4, O::value>{}, T(5.12)), 3, 4, T(5.12));
test_value(setConstant(matrix<T, 1, 1, O::value>{}, T(5.12)), 1, 1, T(5.12));
test_value(setConstant(matrix<T, 10, 10, O::value>{}, T(5.12)), 10, 10,
T(5.12));
test_value(setConstant(matrix<T, Dynamic, Dynamic, O::value>{3, 4}, T(5.12)),
3, 4, T(5.12));
test_value(setConstant(matrix<T, 7, 5, O::value>{}, T(5.12)), 7, 5, T(5.12));
test_value(setConstant(matrix<T, 9, Dynamic>{9, 3}, T(5.12)), 9, 3, T(5.12));
test_value(setConstant(matrix<T, Dynamic, 3>{2, 3}, T(5.12)), 2, 3, T(5.12));
};
TTS_CASE_TPL("Test random", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test random", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using namespace rotgen;
test_random(setRandom<matrix<T, 3, 4, O::value> >(), 3, 4);
test_random(setRandom<matrix<T, 1, 1, O::value> >(), 1, 1);
test_random(setRandom<matrix<T, 10, 10, O::value> >(), 10, 10);
test_random(setRandom<matrix<T,Dynamic,Dynamic, O::value>>(3, 4), 3, 4);
test_random(setRandom<matrix<T, 7, 5, O::value> >(7, 5), 7, 5);
test_random(setRandom<matrix<T, 9,Dynamic> >(9, 3), 9, 3);
test_random(setRandom<matrix<T,Dynamic, 3> >(2, 3), 2, 3);
test_random(setRandom<matrix<T, 3, 4, O::value>>(), 3, 4);
test_random(setRandom<matrix<T, 1, 1, O::value>>(), 1, 1);
test_random(setRandom<matrix<T, 10, 10, O::value>>(), 10, 10);
test_random(setRandom<matrix<T, Dynamic, Dynamic, O::value>>(3, 4), 3, 4);
test_random(setRandom<matrix<T, 7, 5, O::value>>(7, 5), 7, 5);
test_random(setRandom<matrix<T, 9, Dynamic>>(9, 3), 9, 3);
test_random(setRandom<matrix<T, Dynamic, 3>>(2, 3), 2, 3);
test_random(setRandom(matrix<T, 3, 4, O::value>{} ), 3, 4);
test_random(setRandom(matrix<T, 1, 1, O::value>{} ), 1, 1);
test_random(setRandom(matrix<T, 10, 10, O::value>{} ), 10, 10);
test_random(setRandom(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4);
test_random(setRandom(matrix<T, 7, 5, O::value>{} ), 7, 5);
test_random(setRandom(matrix<T, 9,Dynamic>{9, 3} ), 9, 3);
test_random(setRandom(matrix<T,Dynamic, 3>{2, 3} ), 2, 3);
test_random(setRandom(matrix<T, 3, 4, O::value>{}), 3, 4);
test_random(setRandom(matrix<T, 1, 1, O::value>{}), 1, 1);
test_random(setRandom(matrix<T, 10, 10, O::value>{}), 10, 10);
test_random(setRandom(matrix<T, Dynamic, Dynamic, O::value>{3, 4}), 3, 4);
test_random(setRandom(matrix<T, 7, 5, O::value>{}), 7, 5);
test_random(setRandom(matrix<T, 9, Dynamic>{9, 3}), 9, 3);
test_random(setRandom(matrix<T, Dynamic, 3>{2, 3}), 2, 3);
};
TTS_CASE_TPL("Test identity", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test identity", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using namespace rotgen;
test_identity(setIdentity<matrix<T, 3, 4, O::value> >(), 3, 4);
test_identity(setIdentity<matrix<T, 1, 1, O::value> >(), 1, 1);
test_identity(setIdentity<matrix<T, 10, 10, O::value> >(), 10, 10);
test_identity(setIdentity<matrix<T,Dynamic,Dynamic, O::value>>(3, 4), 3, 4);
test_identity(setIdentity<matrix<T, 7, 5, O::value> >(7, 5), 7, 5);
test_identity(setIdentity<matrix<T, 9,Dynamic> >(9, 3), 9, 3);
test_identity(setIdentity<matrix<T,Dynamic, 3> >(2, 3), 2, 3);
test_identity(setIdentity<matrix<T, 3, 4, O::value>>(), 3, 4);
test_identity(setIdentity<matrix<T, 1, 1, O::value>>(), 1, 1);
test_identity(setIdentity<matrix<T, 10, 10, O::value>>(), 10, 10);
test_identity(setIdentity<matrix<T, Dynamic, Dynamic, O::value>>(3, 4), 3, 4);
test_identity(setIdentity<matrix<T, 7, 5, O::value>>(7, 5), 7, 5);
test_identity(setIdentity<matrix<T, 9, Dynamic>>(9, 3), 9, 3);
test_identity(setIdentity<matrix<T, Dynamic, 3>>(2, 3), 2, 3);
test_identity(setIdentity(matrix<T, 3, 4, O::value>{} ), 3, 4);
test_identity(setIdentity(matrix<T, 1, 1, O::value>{} ), 1, 1);
test_identity(setIdentity(matrix<T, 10, 10, O::value>{} ), 10, 10);
test_identity(setIdentity(matrix<T,Dynamic,Dynamic, O::value>{3, 4}), 3, 4);
test_identity(setIdentity(matrix<T, 7, 5, O::value>{} ), 7, 5);
test_identity(setIdentity(matrix<T, 9,Dynamic>{9, 3} ), 9, 3);
test_identity(setIdentity(matrix<T,Dynamic, 3>{2, 3} ), 2, 3);
};
test_identity(setIdentity(matrix<T, 3, 4, O::value>{}), 3, 4);
test_identity(setIdentity(matrix<T, 1, 1, O::value>{}), 1, 1);
test_identity(setIdentity(matrix<T, 10, 10, O::value>{}), 10, 10);
test_identity(setIdentity(matrix<T, Dynamic, Dynamic, O::value>{3, 4}), 3, 4);
test_identity(setIdentity(matrix<T, 7, 5, O::value>{}), 7, 5);
test_identity(setIdentity(matrix<T, 9, Dynamic>{9, 3}), 9, 3);
test_identity(setIdentity(matrix<T, Dynamic, 3>{2, 3}), 2, 3);
};

View file

@ -9,54 +9,59 @@
#include "unit/common/arithmetic.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic matrix inverse", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic matrix inverse",
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>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto eps = std::numeric_limits<T>::epsilon();
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [r, c, fn] : cases)
for (auto const& [r, c, fn] : cases)
{
if(r == c)
if (r == c)
{
auto input = mat_t::Random(r, c);
auto inv = rotgen::inverse(input);
auto rec = input * inv;
auto id = mat_t::Identity(rotgen::rows(rec),rotgen::cols(rec));
auto error = rec - id;
auto rec = input * inv;
auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec));
auto error = rec - id;
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 64.)
<< "Result:\n" << rec << "\n"
<< "Residuals:\n" << error << "\n";
<< "Result:\n"
<< rec << "\n"
<< "Residuals:\n"
<< error << "\n";
}
}
};
TTS_CASE_TPL("Test static matrix inverse", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test static matrix inverse",
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>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto eps = std::numeric_limits<T>::epsilon();
auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = [&]<typename D>(D const&)
{
if constexpr(D::rows == D::cols)
auto process = [&]<typename D>(D const&) {
if constexpr (D::rows == D::cols)
{
auto input = rotgen::matrix<T,D::rows,D::cols,O::value>::Random();
auto input = rotgen::matrix<T, D::rows, D::cols, O::value>::Random();
auto inv = rotgen::inverse(input);
auto rec = input * inv;
auto id = mat_t::Identity(rotgen::rows(rec),rotgen::cols(rec));
auto error = rec - id;
auto rec = input * inv;
auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec));
auto error = rec - id;
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 64.)
<< "Result:\n" << rec << "\n"
<< "Residuals:\n" << error << "\n";
<< "Result:\n"
<< rec << "\n"
<< "Residuals:\n"
<< error << "\n";
}
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -9,29 +9,31 @@
#include "unit/common/norms.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Test dynamic matrix norm operations", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Test dynamic matrix norm operations",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
auto const cases = rotgen::tests::generate_matrix_references();
for (const auto& [rows, cols, fn] : cases)
for (auto const& [rows, cols, fn] : cases)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> input(rows, cols);
rotgen::tests::prepare(rows,cols,fn,input);
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>> )
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);
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);
};
std::apply([&](auto const&... d) { (process(d),...);}, cases);
};
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
};

View file

@ -8,8 +8,13 @@
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
template <typename MatrixType>
void test_matrix_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn, auto ops, auto self_ops)
template<typename MatrixType>
void test_matrix_operations(rotgen::Index rows,
rotgen::Index cols,
auto a_init_fn,
auto b_init_fn,
auto ops,
auto self_ops)
{
MatrixType a(rows, cols);
MatrixType b(rows, cols);
@ -19,22 +24,27 @@ void test_matrix_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_
{
for (rotgen::Index c = 0; c < cols; ++c)
{
a(r,c) = a_init_fn(r, c);
b(r,c) = b_init_fn(r, c);
ref(r, c) = ops(a(r,c),b(r,c));
a(r, c) = a_init_fn(r, c);
b(r, c) = b_init_fn(r, c);
ref(r, c) = ops(a(r, c), b(r, c));
}
}
TTS_EQUAL(ops(a, b), ref);
self_ops(a,b);
self_ops(a, b);
TTS_EQUAL(a, ref);
TTS_EXPECT(verify_rotgen_reentrance(ops(a, b)));
TTS_EXPECT(verify_rotgen_reentrance(self_ops(a, b)));
}
template <typename MatrixType>
void test_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto s, auto ops, auto self_ops)
template<typename MatrixType>
void test_scalar_operations(rotgen::Index rows,
rotgen::Index cols,
auto a_init_fn,
auto s,
auto ops,
auto self_ops)
{
MatrixType a(rows, cols);
MatrixType ref(rows, cols);
@ -43,21 +53,24 @@ void test_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_
{
for (rotgen::Index c = 0; c < cols; ++c)
{
a(r,c) = a_init_fn(r, c);
ref(r, c) = ops(a(r,c),s);
a(r, c) = a_init_fn(r, c);
ref(r, c) = ops(a(r, c), s);
}
}
TTS_EQUAL(ops(a, s), ref);
self_ops(a,s);
self_ops(a, s);
TTS_EQUAL(a, ref);
TTS_EXPECT(verify_rotgen_reentrance(ops(a, s)));
TTS_EXPECT(verify_rotgen_reentrance(self_ops(a, s)));
}
template <typename MatrixType>
void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn, auto s)
template<typename MatrixType>
void test_scalar_multiplications(rotgen::Index rows,
rotgen::Index cols,
auto fn,
auto s)
{
MatrixType a(rows, cols);
MatrixType ref(rows, cols);
@ -66,8 +79,8 @@ void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn
{
for (rotgen::Index c = 0; c < cols; ++c)
{
a(r,c) = fn(r, c);
ref(r, c) = a(r,c) * s;
a(r, c) = fn(r, c);
ref(r, c) = a(r, c) * s;
}
}
@ -76,25 +89,26 @@ void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn
a *= s;
TTS_EQUAL(a, ref);
TTS_EXPECT(verify_rotgen_reentrance(a*s));
TTS_EXPECT(verify_rotgen_reentrance(s*a));
TTS_EXPECT(verify_rotgen_reentrance(a*=s));
TTS_EXPECT(verify_rotgen_reentrance(a * s));
TTS_EXPECT(verify_rotgen_reentrance(s * a));
TTS_EXPECT(verify_rotgen_reentrance(a *= s));
}
template <typename MatrixType>
void test_matrix_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn)
template<typename MatrixType>
void test_matrix_multiplication(rotgen::Index rows,
rotgen::Index cols,
auto a_init_fn,
auto b_init_fn)
{
MatrixType a(rows, cols);
MatrixType b(cols, rows);
MatrixType ref(rows, rows);
for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < a.cols(); ++c)
a(r,c) = a_init_fn(r, c);
for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = a_init_fn(r, c);
for (rotgen::Index r = 0; r < b.rows(); ++r)
for (rotgen::Index c = 0; c < b.cols(); ++c)
b(r,c) = b_init_fn(r, c);
for (rotgen::Index c = 0; c < b.cols(); ++c) b(r, c) = b_init_fn(r, c);
for (rotgen::Index i = 0; i < a.rows(); ++i)
{
@ -107,98 +121,107 @@ void test_matrix_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_i
}
TTS_EQUAL(a * b, ref);
TTS_EXPECT(verify_rotgen_reentrance(a*b));
TTS_EXPECT(verify_rotgen_reentrance(a * b));
}
// Basic initializers
inline constexpr auto init_a = [](auto r, auto c) { return 9.9*r*r*r - 6*c -12; };
inline constexpr auto init_b = [](auto r, auto c) { return 3.1*r + 4.2*c - 12.3; };
inline constexpr auto init_0 = [](auto , auto ) { return 0; };
inline constexpr auto init_a = [](auto r, auto c) {
return 9.9 * r * r * r - 6 * c - 12;
};
inline constexpr auto init_b = [](auto r, auto c) {
return 3.1 * r + 4.2 * c - 12.3;
};
inline constexpr auto init_0 = [](auto, auto) { return 0; };
TTS_CASE_TPL("Check matrix addition", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check matrix addition",
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 op = [](auto a, auto b) { return a + b; };
auto s_op = [](auto& a, auto b) { return a += b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a + b; };
auto s_op = [](auto& a, auto b) { return a += b; };
test_matrix_operations<mat_t>(1 , 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(3 , 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 3, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_b, init_a, op, s_op);
test_matrix_operations<mat_t>(1, 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(3, 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 3, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_b, init_a, op, s_op);
test_matrix_operations<mat_t>(10, 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(1 ,10, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_0, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_a, init_0, op, s_op);
test_matrix_operations<mat_t>(1, 10, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_0, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_a, init_0, op, s_op);
};
TTS_CASE_TPL("Check matrix substraction", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check matrix substraction",
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 op = [](auto a, auto b) { return a - b; };
auto s_op = [](auto& a, auto b) { return a -= b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a - b; };
auto s_op = [](auto& a, auto b) { return a -= b; };
test_matrix_operations<mat_t>(1 , 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(3 , 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 3, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_b, init_a, op, s_op);
test_matrix_operations<mat_t>(1, 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(3, 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 3, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_b, init_a, op, s_op);
test_matrix_operations<mat_t>(10, 1, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(1 ,10, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_0, init_b, op, s_op);
test_matrix_operations<mat_t>(5 , 5, init_a, init_0, op, s_op);
test_matrix_operations<mat_t>(1, 10, init_a, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_0, init_b, op, s_op);
test_matrix_operations<mat_t>(5, 5, init_a, init_0, op, s_op);
};
TTS_CASE_TPL("Check matrix multiplications", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check matrix 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 = [](auto r, auto c) { return r == c ? 1 : 0; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto init_id = [](auto r, auto c) { return r == c ? 1 : 0; };
test_matrix_multiplication<mat_t>(1 , 1, init_a , init_b );
test_matrix_multiplication<mat_t>(3 , 5, init_a , init_b );
test_matrix_multiplication<mat_t>(5 , 3, init_a , init_b );
test_matrix_multiplication<mat_t>(5 , 5, init_a , init_b );
test_matrix_multiplication<mat_t>(5 , 5, init_b , init_a );
test_matrix_multiplication<mat_t>(5 , 5, init_a , init_a );
test_matrix_multiplication<mat_t>(5 , 5, init_a , init_id);
test_matrix_multiplication<mat_t>(5 , 5, init_id, init_a );
test_matrix_multiplication<mat_t>(10, 1, init_a , init_b );
test_matrix_multiplication<mat_t>(1 ,10, init_a , init_b );
test_matrix_multiplication<mat_t>(5 , 5, init_0 , init_b );
test_matrix_multiplication<mat_t>(5 , 5, init_a , init_0 );
test_matrix_multiplication<mat_t>(1, 1, init_a, init_b);
test_matrix_multiplication<mat_t>(3, 5, init_a, init_b);
test_matrix_multiplication<mat_t>(5, 3, init_a, init_b);
test_matrix_multiplication<mat_t>(5, 5, init_a, init_b);
test_matrix_multiplication<mat_t>(5, 5, init_b, init_a);
test_matrix_multiplication<mat_t>(5, 5, init_a, init_a);
test_matrix_multiplication<mat_t>(5, 5, init_a, init_id);
test_matrix_multiplication<mat_t>(5, 5, init_id, init_a);
test_matrix_multiplication<mat_t>(10, 1, init_a, init_b);
test_matrix_multiplication<mat_t>(1, 10, init_a, init_b);
test_matrix_multiplication<mat_t>(5, 5, init_0, init_b);
test_matrix_multiplication<mat_t>(5, 5, init_a, init_0);
};
TTS_CASE_TPL("Check matrix multiplication with scalar", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check matrix multiplication with scalar",
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>;
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
test_scalar_multiplications<mat_t>(1 , 1, init_a, T{ 3.5});
test_scalar_multiplications<mat_t>(3 , 5, init_a, T{-2.5});
test_scalar_multiplications<mat_t>(5 , 3, init_a, T{ 4. });
test_scalar_multiplications<mat_t>(5 , 5, init_a, T{-5. });
test_scalar_multiplications<mat_t>(5 , 5, init_a, T{ 1. });
test_scalar_multiplications<mat_t>(5 , 5, init_a, T{ 6. });
test_scalar_multiplications<mat_t>(10, 1, init_a, T{ 10.});
test_scalar_multiplications<mat_t>(1 ,10, init_a, T{-0.5});
test_scalar_multiplications<mat_t>(1, 1, init_a, T{3.5});
test_scalar_multiplications<mat_t>(3, 5, init_a, T{-2.5});
test_scalar_multiplications<mat_t>(5, 3, init_a, T{4.});
test_scalar_multiplications<mat_t>(5, 5, init_a, T{-5.});
test_scalar_multiplications<mat_t>(5, 5, init_a, T{1.});
test_scalar_multiplications<mat_t>(5, 5, init_a, T{6.});
test_scalar_multiplications<mat_t>(10, 1, init_a, T{10.});
test_scalar_multiplications<mat_t>(1, 10, init_a, T{-0.5});
};
TTS_CASE_TPL("Check matrix division with scalar", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
TTS_CASE_TPL("Check matrix division with scalar",
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 op = [](auto a, auto b) { return a / b; };
auto s_op = [](auto& a, auto b) { return a /= b; };
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a / b; };
auto s_op = [](auto& a, auto b) { return a /= b; };
test_scalar_operations<mat_t>(1 , 1, init_a, T{ 3.5}, op, s_op);
test_scalar_operations<mat_t>(3 , 5, init_a, T{-2.5}, op, s_op);
test_scalar_operations<mat_t>(5 , 3, init_a, T{ 4. }, op, s_op);
test_scalar_operations<mat_t>(5 , 5, init_a, T{-5. }, op, s_op);
test_scalar_operations<mat_t>(5 , 5, init_a, T{ 1. }, op, s_op);
test_scalar_operations<mat_t>(5 , 5, init_a, T{ 6. }, op, s_op);
test_scalar_operations<mat_t>(10, 1, init_a, T{ 10.}, op, s_op);
test_scalar_operations<mat_t>(1 ,10, init_a, T{-0.5}, op, s_op);
test_scalar_operations<mat_t>(1, 1, init_a, T{3.5}, op, s_op);
test_scalar_operations<mat_t>(3, 5, init_a, T{-2.5}, op, s_op);
test_scalar_operations<mat_t>(5, 3, init_a, T{4.}, op, s_op);
test_scalar_operations<mat_t>(5, 5, init_a, T{-5.}, op, s_op);
test_scalar_operations<mat_t>(5, 5, init_a, T{1.}, op, s_op);
test_scalar_operations<mat_t>(5, 5, init_a, T{6.}, op, s_op);
test_scalar_operations<mat_t>(10, 1, init_a, T{10.}, op, s_op);
test_scalar_operations<mat_t>(1, 10, init_a, T{-0.5}, op, s_op);
};

View file

@ -15,40 +15,41 @@
namespace rotgen::tests
{
template<auto N> struct constant { static constexpr auto value = N; };
template<auto N> struct constant
{
static constexpr auto value = N;
};
using scalar = tts::types<float,double>;
using order = tts::types<constant<ColMajor>,constant<RowMajor>>;
using scalar = tts::types<float, double>;
using order = tts::types<constant<ColMajor>, constant<RowMajor>>;
using types = tts::types< tts::types<float ,constant<ColMajor>>
, tts::types<double,constant<ColMajor>>
, tts::types<float ,constant<RowMajor>>
, tts::types<double,constant<RowMajor>>
>;
using types = tts::types<tts::types<float, constant<ColMajor>>,
tts::types<double, constant<ColMajor>>,
tts::types<float, constant<RowMajor>>,
tts::types<double, constant<RowMajor>>>;
}
#include <iostream>
template<typename T>
constexpr bool verify_rotgen_reentrance(T const&)
template<typename T> constexpr bool verify_rotgen_reentrance(T const&)
{
if constexpr(rotgen::use_expression_templates) return true;
else return rotgen::concepts::entity<T>;
if constexpr (rotgen::use_expression_templates) return true;
else return rotgen::concepts::entity<T>;
}
int main(int argc, char const **argv)
int main(int argc, char const** argv)
{
::tts::initialize(argc,argv);
::tts::initialize(argc, argv);
#ifdef NDEBUG
constexpr auto assert_status = "Disabled";
#else
constexpr auto assert_status = "Enabled";
#endif
std::cout << "[ROTGEN] - Assertions: " << assert_status << std::endl;
std::cout << "[ROTGEN] - Assertions: " << assert_status << std::endl;
rotgen::setup_summary(std::cout);
rotgen_main(argc, argv);
return tts::report(0,0);
}
return tts::report(0, 0);
}