Implement fixed size options for rotgen containers
See merge request oss/rotgen!11
This commit is contained in:
parent
8e545dd51a
commit
2084874b1b
39 changed files with 1247 additions and 323 deletions
|
|
@ -6,9 +6,7 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/block.hpp>
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <rotgen/extract.hpp>
|
||||
#include <rotgen/rotgen.hpp>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
template<typename Type1, typename Type2>
|
||||
|
|
@ -16,8 +14,8 @@ void test_comparison(const Type1& t1, const Type2& t2)
|
|||
{
|
||||
TTS_EQUAL(static_cast<std::ptrdiff_t>(t1.rows()), static_cast<std::ptrdiff_t>(t2.rows()));
|
||||
TTS_EQUAL(static_cast<std::ptrdiff_t>(t1.cols()), static_cast<std::ptrdiff_t>(t2.cols()));
|
||||
for (std::size_t r = 0; r < static_cast<std::size_t>(t1.rows()); ++r)
|
||||
for (std::size_t c = 0; c < static_cast<std::size_t>(t1.cols()); ++c)
|
||||
for (rotgen::Index r = 0; r < static_cast<rotgen::Index>(t1.rows()); ++r)
|
||||
for (rotgen::Index c = 0; c < static_cast<rotgen::Index>(t1.cols()); ++c)
|
||||
TTS_EQUAL(t1(r, c), t2(r, c));
|
||||
}
|
||||
|
||||
|
|
@ -25,6 +23,10 @@ template<typename Matrix1, typename Matrix2, typename Block1, typename Block2>
|
|||
void test_block_unary_ops(const Matrix1& original_matrix, const Matrix2& ref_matrix,
|
||||
Block1 original_block, Block2 ref_block)
|
||||
{
|
||||
TTS_EXPECT(verify_rotgen_reentrance(original_block.transpose()));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(original_block.conjugate()));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(original_block.adjoint()));
|
||||
|
||||
test_comparison(original_block.transpose(), ref_block.transpose());
|
||||
test_comparison(original_block.conjugate(), ref_block.conjugate());
|
||||
test_comparison(original_block.adjoint(), ref_block.adjoint());
|
||||
|
|
@ -72,8 +74,8 @@ void test_dynamic_block_reductions(rotgen::tests::matrix_block_test_case<MatrixT
|
|||
MatrixType original(matrix_construct.rows, matrix_construct.cols);
|
||||
EigenMatrix ref(matrix_construct.rows, matrix_construct.cols);
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.rows; ++r)
|
||||
for (std::size_t c = 0; c < matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
ref(r, c) = original(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
|
||||
|
||||
std::vector<std::pair<rotgen::block<MatrixType>, Eigen::Block<EigenMatrix>>> test_cases {
|
||||
|
|
@ -113,17 +115,17 @@ TTS_CASE_TPL("Test dynamic block reductions", rotgen::tests::types)
|
|||
|
||||
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> test_cases =
|
||||
{
|
||||
{6, 5, [](auto r, auto c) { return T(r + c); }, 1, 2, 3, 2},
|
||||
{9, 11, [](auto r, auto c) {return T(r + c); }, 0, 1, 4, 9},
|
||||
{3, 3, [](auto , auto ) {return T(0.0); }, 1, 1, 1, 1},
|
||||
{1, 4, [](auto r, auto c) {return T(-r -c*c - 1234); }, 0, 0, 1, 1},
|
||||
{9, 9, [](auto r, auto c) {return T(-r + 2*c); }, 0, 1, 3, 3},
|
||||
{11, 13, [](auto r, auto c) {return T(std::tan(r+c)); }, 1, 1, 2, 2},
|
||||
{4, 1, [](auto , auto ) {return T(7.0); }, 2, 0, 2, 1},
|
||||
{1, 1, [](auto , auto ) {return T(42.0); }, 0, 0, 1, 1},
|
||||
{12, 13, [](auto r, auto c) {return T(std::sin(r + c)); }, 2, 3, 4, 5 },
|
||||
{4, 9, [](auto r, auto c) {return T(-1.5 * r + 2.56 * c); }, 0, 1, 2, 3 },
|
||||
{2, 5, [](auto r, auto c) {return T(r == c ? 1.0 : 0.0); }, 1, 1, 1, 1},
|
||||
{6, 5, [](rotgen::Index r, rotgen::Index c) { return T(r + c); }, 1, 2, 3, 2},
|
||||
{9, 11, [](rotgen::Index r, rotgen::Index c) {return T(r + c); }, 0, 1, 4, 9},
|
||||
{3, 3, [](rotgen::Index , rotgen::Index ) {return T(0.0); }, 1, 1, 1, 1},
|
||||
{1, 4, [](rotgen::Index r, rotgen::Index c) {return T(-r -c*c - 1234); }, 0, 0, 1, 1},
|
||||
{9, 9, [](rotgen::Index r, rotgen::Index c) {return T(-r + 2*c); }, 0, 1, 3, 3},
|
||||
{11, 13, [](rotgen::Index r, rotgen::Index c) {return T(std::tan(r+c)); }, 1, 1, 2, 2},
|
||||
{4, 1, [](rotgen::Index , rotgen::Index ) {return T(7.0); }, 2, 0, 2, 1},
|
||||
{1, 1, [](rotgen::Index , rotgen::Index ) {return T(42.0); }, 0, 0, 1, 1},
|
||||
{12, 13, [](rotgen::Index r, rotgen::Index c) {return T(std::sin(r + c)); }, 2, 3, 4, 5 },
|
||||
{4, 9, [](rotgen::Index r, rotgen::Index c) {return T(-1.5 * r + 2.56 * c); }, 0, 1, 2, 3 },
|
||||
{2, 5, [](rotgen::Index r, rotgen::Index c) {return T(r == c ? 1.0 : 0.0); }, 1, 1, 1, 1},
|
||||
};
|
||||
|
||||
for (const auto& test_case : test_cases)
|
||||
|
|
|
|||
|
|
@ -6,22 +6,21 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <rotgen/extract.hpp>
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
template<typename EigenType, typename F>
|
||||
void for_each_element(EigenType const& m, F&& f)
|
||||
{
|
||||
for(std::size_t i = 0; i < m.rows(); ++i)
|
||||
for(std::size_t j = 0; j < m.cols(); ++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(std::size_t i = 0; i < m.rows(); ++i)
|
||||
for(std::size_t j = 0; j < m.cols(); ++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));
|
||||
}
|
||||
|
||||
|
|
@ -30,8 +29,8 @@ MatrixType make_initialized_matrix(rotgen::tests::matrix_block_test_case<MatrixT
|
|||
{
|
||||
MatrixType matrix(matrix_construct.rows, matrix_construct.cols);
|
||||
|
||||
for(std::size_t i = 0; i < matrix_construct.rows; ++i)
|
||||
for(std::size_t j = 0; j < matrix_construct.cols; ++j)
|
||||
for(rotgen::Index i = 0; i < matrix_construct.rows; ++i)
|
||||
for(rotgen::Index j = 0; j < matrix_construct.cols; ++j)
|
||||
matrix(i, j) = static_cast<T>(matrix_construct.init_fn(i, j));
|
||||
|
||||
return matrix;
|
||||
|
|
@ -39,8 +38,8 @@ MatrixType make_initialized_matrix(rotgen::tests::matrix_block_test_case<MatrixT
|
|||
|
||||
template<typename MatrixType, typename BlockType, typename T>
|
||||
void validate_block_behavior(MatrixType& matrix, BlockType& block,
|
||||
std::size_t i0, std::size_t j0,
|
||||
std::size_t ni, std::size_t nj)
|
||||
rotgen::Index i0, rotgen::Index j0,
|
||||
rotgen::Index ni, rotgen::Index nj)
|
||||
{
|
||||
TTS_EQUAL(block.rows(), ni);
|
||||
TTS_EQUAL(block.cols(), nj);
|
||||
|
|
@ -125,13 +124,13 @@ void test_dynamic_block_extraction(rotgen::tests::matrix_block_test_case<MatrixT
|
|||
|
||||
}
|
||||
|
||||
template<typename MatrixType, typename T, std::size_t NI, std::size_t NJ>
|
||||
template<typename MatrixType, typename T, rotgen::Index NI, rotgen::Index NJ>
|
||||
void test_static_block_extraction(rotgen::tests::static_matrix_block_test_case<MatrixType, NI, NJ> const& matrix_construct)
|
||||
{
|
||||
MatrixType matrix(matrix_construct.rows, matrix_construct.cols);
|
||||
|
||||
for (std::size_t i = 0; i < matrix_construct.rows; ++i)
|
||||
for (std::size_t j = 0; j < matrix_construct.cols; ++j)
|
||||
for (rotgen::Index i = 0; i < matrix_construct.rows; ++i)
|
||||
for (rotgen::Index j = 0; j < matrix_construct.cols; ++j)
|
||||
matrix(i, j) = static_cast<T>(matrix_construct.init_fn(i, j));
|
||||
|
||||
auto block_main = rotgen::extract<NI, NJ>(matrix, matrix_construct.i0, matrix_construct.j0);
|
||||
|
|
@ -206,10 +205,10 @@ TTS_CASE_TPL("Check all dynamic block extractions on a dynamic row-major matrix"
|
|||
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value, 1>;
|
||||
|
||||
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> cases = {
|
||||
{ 6, 11, [](std::size_t i, std::size_t j) { return T(i * 10 + j); }, 1, 2, 3, 2 },
|
||||
{ 7, 10, [](std::size_t i, std::size_t j) { return T(std::sin(i + j)); }, 4, 4, 3, 3 },
|
||||
{ 5, 5, [](std::size_t i, std::size_t j) { return T((i + j) % 7); }, 0, 0, 5, 5 },
|
||||
{ 9, 14, [](std::size_t i, std::size_t 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) {
|
||||
|
|
@ -224,9 +223,9 @@ TTS_CASE_TPL("Check all dynamic block extractions on a static column-major matri
|
|||
using mat_t = rotgen::matrix<T,4,5,O::value, 0>;
|
||||
|
||||
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> cases = {
|
||||
{ 4, 5, [](std::size_t i, std::size_t j) { return T(2*i + j*j*j - 42); }, 1, 2, 3, 2 },
|
||||
{ 4, 5, [](std::size_t i, std::size_t j) { return T(std::tan(i*i*j)); }, 0, 1, 2, 1 },
|
||||
{ 4, 5, [](std::size_t i, std::size_t j) { return T((i*i + j*j) / 6); }, 2, 0, 0, 0 }
|
||||
{ 4, 5, [](auto i, auto j) { return T(2*i + j*j*j - 42); }, 1, 2, 3, 2 },
|
||||
{ 4, 5, [](auto i, auto j) { return T(std::tan(i*i*j)); }, 0, 1, 2, 1 },
|
||||
{ 4, 5, [](auto i, auto j) { return T((i*i + j*j) / 6); }, 2, 0, 0, 0 }
|
||||
};
|
||||
|
||||
for (auto const& matrix_case : cases) {
|
||||
|
|
@ -241,26 +240,26 @@ TTS_CASE_TPL("Check all static block extractions", rotgen::tests::types)
|
|||
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value, 1>;
|
||||
|
||||
test_static_block_extraction<mat_t, T, 1, 2>(
|
||||
rotgen::tests::static_matrix_block_test_case<mat_t, 1, 2>{
|
||||
11, 11,
|
||||
[](std::size_t i, std::size_t j) { return T(i*i*i + 3*j - 127); },
|
||||
3, 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
|
||||
}
|
||||
);
|
||||
|
||||
test_static_block_extraction<mat_t, double, 4, 3>(
|
||||
rotgen::tests::static_matrix_block_test_case<mat_t, 4, 3>{
|
||||
14, 15,
|
||||
[](std::size_t i, std::size_t j) { return T(std::cos(i * j * 2)); },
|
||||
5, 1
|
||||
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
|
||||
}
|
||||
);
|
||||
|
||||
test_static_block_extraction<mat_t, double, 0, 0>(
|
||||
rotgen::tests::static_matrix_block_test_case<mat_t, 0, 0>{
|
||||
5, 5,
|
||||
[](std::size_t i, std::size_t j) { return T((i + j) % 9); },
|
||||
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
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
@ -6,8 +6,7 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <rotgen/extract.hpp>
|
||||
#include <rotgen/rotgen.hpp>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
TTS_CASE_TPL("Matrix norm-related operations", rotgen::tests::types)
|
||||
|
|
@ -17,15 +16,15 @@ TTS_CASE_TPL("Matrix norm-related operations", rotgen::tests::types)
|
|||
|
||||
std::vector<rotgen::tests::matrix_block_test_case<mat_t>> test_cases =
|
||||
{
|
||||
{6, 5, [](auto r, auto c) {return r + c; }, 1, 2, 3, 2},
|
||||
{9, 11, [](auto r, auto c) {return r + c; }, 0, 1, 4, 9},
|
||||
{3, 3, [](auto , auto ) {return 0.0; }, 1, 1, 1, 1},
|
||||
{1, 4, [](auto r, auto c) {return -r -c*c - 1234; }, 0, 0, 1, 1},
|
||||
{4, 1, [](auto , auto ) {return 7.0; }, 2, 0, 2, 1},
|
||||
{1, 1, [](auto , auto ) {return 42.0; }, 0, 0, 1, 1},
|
||||
{12, 13, [](auto r, auto c) {return std::sin(r + c); }, 2, 3, 4, 5 },
|
||||
{4, 9, [](auto r, auto c) {return -1.5 * r + 2.56 * c; }, 0, 1, 2, 3 },
|
||||
{2, 5, [](auto r, auto c) {return (r == c ? 1.0 : 0.0); }, 1, 1, 1, 1},
|
||||
{6, 5, [](rotgen::Index r, rotgen::Index c) {return r + c; }, 1, 2, 3, 2},
|
||||
{9, 11, [](rotgen::Index r, rotgen::Index c) {return r + c; }, 0, 1, 4, 9},
|
||||
{3, 3, [](rotgen::Index , rotgen::Index ) {return 0.0; }, 1, 1, 1, 1},
|
||||
{1, 4, [](rotgen::Index r, rotgen::Index c) {return -r -c*c - 1234; }, 0, 0, 1, 1},
|
||||
{4, 1, [](rotgen::Index , rotgen::Index ) {return 7.0; }, 2, 0, 2, 1},
|
||||
{1, 1, [](rotgen::Index , rotgen::Index ) {return 42.0; }, 0, 0, 1, 1},
|
||||
{12, 13, [](rotgen::Index r, rotgen::Index c) {return std::sin(r + c); }, 2, 3, 4, 5 },
|
||||
{4, 9, [](rotgen::Index r, rotgen::Index c) {return -1.5 * r + 2.56 * c; }, 0, 1, 2, 3 },
|
||||
{2, 5, [](rotgen::Index r, rotgen::Index c) {return (r == c ? 1.0 : 0.0); }, 1, 1, 1, 1},
|
||||
};
|
||||
|
||||
for (const auto& [rows, cols, fn, i0, j0, ni, nj] : test_cases)
|
||||
|
|
@ -33,8 +32,8 @@ TTS_CASE_TPL("Matrix norm-related operations", rotgen::tests::types)
|
|||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> original_matrix(rows, cols);
|
||||
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic,O::value> ref_matrix(rows, cols);
|
||||
|
||||
for (std::size_t r = 0; r < rows; ++r)
|
||||
for (std::size_t c = 0; c < cols; ++c)
|
||||
for (rotgen::Index r = 0; r < rows; ++r)
|
||||
for (rotgen::Index c = 0; c < cols; ++c)
|
||||
ref_matrix(r, c) = original_matrix(r, c) = fn(r,c);
|
||||
|
||||
auto original_block = rotgen::extract(original_matrix, i0, j0, ni, nj);
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <rotgen/extract.hpp>
|
||||
#include <rotgen/rotgen.hpp>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
template <typename MatrixType, typename T>
|
||||
|
|
@ -21,9 +20,11 @@ void test_block_matrix_operations(rotgen::tests::matrix_block_test_case<MatrixTy
|
|||
EigenMatrix ref_a(matrix_construct.rows, matrix_construct.cols);
|
||||
EigenMatrix ref_b(matrix_construct.rows, matrix_construct.cols);
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.rows; ++r)
|
||||
TTS_EXPECT(verify_rotgen_reentrance(ops(a,b)));
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
{
|
||||
for (std::size_t c = 0; c < matrix_construct.cols; ++c)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
{
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
|
||||
ref_b(r,c) = b(r,c) = static_cast<T>(b_init_fn(r, c));
|
||||
|
|
@ -42,20 +43,20 @@ void test_block_matrix_operations(rotgen::tests::matrix_block_test_case<MatrixTy
|
|||
auto result_block = ops(a_block, b_block);
|
||||
auto ref_result_block = ops(ref_a_block, ref_b_block);
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
|
||||
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
TTS_EQUAL(result_block(r, c), ref_result_block(r, c));
|
||||
|
||||
self_ops(a_block,b_block);
|
||||
self_ops(ref_a_block, ref_b_block);
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
|
||||
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
{
|
||||
for (std::size_t c = 0; c < matrix_construct.cols; ++c)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
{
|
||||
TTS_EQUAL(a(r, c), ref_a(r, c));
|
||||
TTS_EQUAL(b(r, c), ref_b(r, c));
|
||||
|
|
@ -72,8 +73,10 @@ void test_block_scalar_operations(rotgen::tests::matrix_block_test_case<MatrixTy
|
|||
MatrixType a(matrix_construct.rows, matrix_construct.cols);
|
||||
EigenMatrix ref_a(matrix_construct.rows, matrix_construct.cols);
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.rows; ++r)
|
||||
for (std::size_t c = 0; c < matrix_construct.cols; ++c)
|
||||
TTS_EXPECT(verify_rotgen_reentrance(ops(a,scalar)));
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
|
||||
|
||||
auto a_block = rotgen::extract(a, matrix_construct.i0, matrix_construct.j0,
|
||||
|
|
@ -84,19 +87,19 @@ void test_block_scalar_operations(rotgen::tests::matrix_block_test_case<MatrixTy
|
|||
auto result = ops(a_block, scalar);
|
||||
auto ref_result = ops(ref_a_block, scalar);
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
|
||||
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
TTS_EQUAL(result(r, c), ref_result(r, c));
|
||||
|
||||
self_ops(a_block,scalar);
|
||||
self_ops(ref_a_block, scalar);
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
|
||||
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.rows; ++r)
|
||||
for (std::size_t c = 0; c < matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
TTS_EQUAL(a(r, c), ref_a(r, c));
|
||||
}
|
||||
|
||||
|
|
@ -109,8 +112,11 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
|
|||
MatrixType a(matrix_construct.rows, matrix_construct.cols);
|
||||
EigenMatrix ref_a(matrix_construct.rows, matrix_construct.cols);
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.rows; ++r)
|
||||
for (std::size_t c = 0; c < matrix_construct.cols; ++c)
|
||||
TTS_EXPECT(verify_rotgen_reentrance(a * scalar));
|
||||
TTS_EXPECT(verify_rotgen_reentrance(scalar * a));
|
||||
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(matrix_construct.init_fn(r, c));
|
||||
|
||||
auto a_block = rotgen::extract(a, matrix_construct.i0, matrix_construct.j0,
|
||||
|
|
@ -123,9 +129,9 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
|
|||
auto a_scalar_multiplication_ref = ref_a_block * scalar;
|
||||
auto scalar_a_multiplication_ref = scalar * ref_a_block;
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
{
|
||||
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.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));
|
||||
|
|
@ -135,12 +141,12 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case<Mat
|
|||
a_block *= scalar;
|
||||
ref_a_block *= scalar;
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.ni; ++r)
|
||||
for (std::size_t c = 0; c < matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.nj; ++c)
|
||||
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
|
||||
|
||||
for (std::size_t r = 0; r < matrix_construct.rows; ++r)
|
||||
for (std::size_t c = 0; c < matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < matrix_construct.cols; ++c)
|
||||
TTS_EQUAL(a(r, c), ref_a(r, c));
|
||||
}
|
||||
|
||||
|
|
@ -155,12 +161,12 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case<MatrixType>
|
|||
EigenMatrix ref_a(a_matrix_construct.rows, a_matrix_construct.cols);
|
||||
EigenMatrix ref_b(b_matrix_construct.rows, b_matrix_construct.cols);
|
||||
|
||||
for (std::size_t r = 0; r < a_matrix_construct.rows; ++r)
|
||||
for (std::size_t c = 0; c < a_matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < a_matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < a_matrix_construct.cols; ++c)
|
||||
ref_a(r,c) = a(r,c) = static_cast<T>(a_matrix_construct.init_fn(r, c));
|
||||
|
||||
for (std::size_t r = 0; r < b_matrix_construct.rows; ++r)
|
||||
for (std::size_t c = 0; c < b_matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < b_matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < b_matrix_construct.cols; ++c)
|
||||
ref_b(r,c) = b(r,c) = static_cast<T>(b_matrix_construct.init_fn(r, c));
|
||||
|
||||
|
||||
|
|
@ -173,26 +179,28 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case<MatrixType>
|
|||
auto ref_b_block = ref_b.block(b_matrix_construct.i0, b_matrix_construct.j0,
|
||||
b_matrix_construct.ni, b_matrix_construct.nj);
|
||||
|
||||
TTS_EXPECT(verify_rotgen_reentrance(a_block * b_block));
|
||||
|
||||
auto a_b_product_original = a_block * b_block;
|
||||
auto a_b_product_ref = ref_a_block * ref_b_block;
|
||||
|
||||
for (std::size_t r = 0; r < a_matrix_construct.ni; ++r)
|
||||
for (std::size_t c = 0; c < a_matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < a_matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < a_matrix_construct.nj; ++c)
|
||||
TTS_EQUAL(a_b_product_original (r, c), a_b_product_ref(r, c));
|
||||
|
||||
a_block *= b_block;
|
||||
ref_a_block *= ref_b_block;
|
||||
|
||||
for (std::size_t r = 0; r < a_matrix_construct.ni; ++r)
|
||||
for (std::size_t c = 0; c < a_matrix_construct.nj; ++c)
|
||||
for (rotgen::Index r = 0; r < a_matrix_construct.ni; ++r)
|
||||
for (rotgen::Index c = 0; c < a_matrix_construct.nj; ++c)
|
||||
TTS_EQUAL(a_block(r, c), ref_a_block(r, c));
|
||||
|
||||
for (std::size_t r = 0; r < a_matrix_construct.rows; ++r)
|
||||
for (std::size_t c = 0; c < a_matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < a_matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < a_matrix_construct.cols; ++c)
|
||||
TTS_EQUAL(a(r, c), ref_a(r, c));
|
||||
|
||||
for (std::size_t r = 0; r < b_matrix_construct.rows; ++r)
|
||||
for (std::size_t c = 0; c < b_matrix_construct.cols; ++c)
|
||||
for (rotgen::Index r = 0; r < b_matrix_construct.rows; ++r)
|
||||
for (rotgen::Index c = 0; c < b_matrix_construct.cols; ++c)
|
||||
TTS_EQUAL(b(r, c), ref_b(r, c));
|
||||
}
|
||||
|
||||
|
|
@ -244,7 +252,7 @@ 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 = [](auto r, auto c) { return r == c ? 1 : 0; };
|
||||
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});
|
||||
|
|
|
|||
|
|
@ -6,40 +6,42 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/block.hpp>
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
void test_size(const auto& matrix, std::size_t rows, std::size_t cols)
|
||||
void test_size(const auto& matrix, rotgen::Index rows, rotgen::Index cols)
|
||||
{
|
||||
TTS_EQUAL(matrix.rows(), rows);
|
||||
TTS_EQUAL(matrix.cols(), cols);
|
||||
TTS_EQUAL(matrix.size(), rows*cols);
|
||||
}
|
||||
|
||||
void test_value(const auto& matrix, std::size_t rows, std::size_t cols, auto constant)
|
||||
void test_value(const auto& matrix, rotgen::Index rows, rotgen::Index cols, auto constant)
|
||||
{
|
||||
TTS_EXPECT(verify_rotgen_reentrance(matrix));
|
||||
test_size(matrix, rows, cols);
|
||||
for(std::size_t r=0;r<rows;++r)
|
||||
for(std::size_t c=0;c<cols;++c)
|
||||
for(rotgen::Index r=0;r<rows;++r)
|
||||
for(rotgen::Index c=0;c<cols;++c)
|
||||
TTS_EQUAL(matrix(r, c), constant);
|
||||
}
|
||||
|
||||
void test_random(const auto& matrix, std::size_t rows, std::size_t cols)
|
||||
void test_random(const auto& matrix, rotgen::Index rows, rotgen::Index cols)
|
||||
{
|
||||
TTS_EXPECT(verify_rotgen_reentrance(matrix));
|
||||
test_size(matrix, rows, cols);
|
||||
for(std::size_t r=0;r<rows;++r)
|
||||
for(std::size_t 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(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(const auto& matrix, rotgen::Index rows, rotgen::Index cols)
|
||||
{
|
||||
TTS_EXPECT(verify_rotgen_reentrance(matrix));
|
||||
test_size(matrix, rows, cols);
|
||||
for(std::size_t r=0;r<rows;++r)
|
||||
for(std::size_t c=0;c<cols;++c)
|
||||
for(rotgen::Index r=0;r<rows;++r)
|
||||
for(rotgen::Index c=0;c<cols;++c)
|
||||
TTS_EQUAL(matrix(r, c), r==c ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue