Implement fixed size options for rotgen containers

See merge request oss/rotgen!11
This commit is contained in:
Joel Falcou 2025-07-20 20:23:51 +02:00
parent 8e545dd51a
commit 2084874b1b
39 changed files with 1247 additions and 323 deletions

View file

@ -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)

View file

@ -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
}
);
};

View file

@ -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);

View file

@ -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});

View file

@ -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);
}

View file

@ -5,11 +5,9 @@
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#define TTS_MAIN
#include <rotgen/matrix.hpp>
#include "tts.hpp"
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
#include <Eigen/Dense>
#include "rotgen/functions.hpp"
template <typename MatrixType>
struct MatrixDescriptor
@ -38,6 +36,10 @@ void test_matrix_unary_ops(std::size_t rows, std::size_t cols,
TTS_EQUAL(rotgen::conjugate(original), original);
TTS_EQUAL(rotgen::adjoint(original), transposed_matrix);
TTS_EXPECT(verify_rotgen_reentrance(rotgen::transpose(original)));
TTS_EXPECT(verify_rotgen_reentrance(rotgen::conjugate(original)));
TTS_EXPECT(verify_rotgen_reentrance(rotgen::adjoint(original)));
rotgen::transposeInPlace(original);
TTS_EQUAL(original, transposed_matrix);

View file

@ -5,15 +5,11 @@
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#define TTS_MAIN
#include <rotgen/matrix.hpp>
#include <rotgen/functions.hpp>
#include "tts.hpp"
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
#include <functional>
#include <array>
template <typename MatrixType>
struct MatrixDescriptor
{

View file

@ -5,10 +5,8 @@
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#define TTS_MAIN
#include <rotgen/matrix.hpp>
#include <rotgen/functions.hpp>
#include "tts.hpp"
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
#include <Eigen/Dense>
template <typename MatrixType>

View file

@ -6,7 +6,7 @@
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/matrix.hpp>
#include <rotgen/rotgen.hpp>
#include <Eigen/Dense>
template<typename MatrixType>
@ -27,6 +27,10 @@ void test_matrix_unary_ops(std::size_t rows, std::size_t cols, auto const &init_
TTS_EQUAL(original.conjugate(), original);
TTS_EQUAL(original.adjoint(), transposed_matrix);
TTS_EXPECT(verify_rotgen_reentrance(original.transpose()));
TTS_EXPECT(verify_rotgen_reentrance(original.conjugate()));
TTS_EXPECT(verify_rotgen_reentrance(original.adjoint()));
original.transposeInPlace();
TTS_EQUAL(original, transposed_matrix);

View file

@ -6,15 +6,15 @@
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/matrix.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>> )
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> matrix;
TTS_EQUAL(matrix.rows(), 0ULL);
TTS_EQUAL(matrix.cols(), 0ULL);
TTS_EQUAL(matrix.rows(), rotgen::Index{0});
TTS_EQUAL(matrix.cols(), rotgen::Index{0});
};
TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types)
@ -22,8 +22,8 @@ TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types)
{
rotgen::matrix<T,4,9,O::value> matrix;
TTS_EQUAL(matrix.rows(), 4ULL);
TTS_EQUAL(matrix.cols(), 9ULL);
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)
@ -31,8 +31,8 @@ TTS_CASE_TPL("Dynamic matrix constructor with row and columns", rotgen::tests::t
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> matrix(10, 5);
TTS_EQUAL(matrix.rows(), 10ULL);
TTS_EQUAL(matrix.cols(), 5ULL);
TTS_EQUAL(matrix.rows(), rotgen::Index{10});
TTS_EQUAL(matrix.cols(), rotgen::Index{5});
};
TTS_CASE_TPL("Static matrix constructor with row and columns", rotgen::tests::types)
@ -40,8 +40,8 @@ TTS_CASE_TPL("Static matrix constructor with row and columns", rotgen::tests::ty
{
rotgen::matrix<T,6,11,O::value> matrix(6, 11);
TTS_EQUAL(matrix.rows(), 6ULL);
TTS_EQUAL(matrix.cols(), 11ULL);
TTS_EQUAL(matrix.rows(), rotgen::Index{6});
TTS_EQUAL(matrix.cols(), rotgen::Index{11});
};
TTS_CASE_TPL("Copy constructor produces identical but independent matrix", rotgen::tests::types)
@ -49,8 +49,8 @@ TTS_CASE_TPL("Copy constructor produces identical but independent matrix", rotge
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(3, 3);
for(std::size_t r=0;r<a.rows();r++)
for(std::size_t c=0;c<a.cols();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;
@ -58,8 +58,8 @@ TTS_CASE_TPL("Copy constructor produces identical but independent matrix", rotge
TTS_EQUAL(b.rows(), a.rows());
TTS_EQUAL(b.cols(), a.cols());
for(std::size_t r=0;r<a.rows();r++)
for(std::size_t c=0;c<a.cols();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);
@ -75,8 +75,8 @@ TTS_CASE_TPL("Copy constructor on default matrix", rotgen::tests::types)
{
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(), 0ULL);
TTS_EQUAL(b.cols(), 0ULL);
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)
@ -84,17 +84,17 @@ TTS_CASE_TPL("Copy constructor from const matrix", rotgen::tests::types)
{
const rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 2);
auto b = a;
TTS_EQUAL(b.rows(), 2ULL);
TTS_EQUAL(b.cols(), 2ULL);
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>> )
{
rotgen::matrix<T, 2, 5> a;
rotgen::matrix<T, 2, 5> b = a;
TTS_EQUAL(b.rows(), 2ULL);
TTS_EQUAL(b.cols(), 5ULL);
rotgen::matrix<T, 2, 5> a;
rotgen::matrix<T, 2, 5> b = a;
TTS_EQUAL(b.rows(), rotgen::Index{2});
TTS_EQUAL(b.cols(), rotgen::Index{5});
};
/*
@ -126,8 +126,8 @@ TTS_CASE_TPL("Move constructor transfers contents", rotgen::tests::types)
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b = std::move(a);
TTS_EQUAL(b(1,1), 7);
TTS_EQUAL(b.rows(), 3ULL);
TTS_EQUAL(b.cols(), 3ULL);
TTS_EQUAL(b.rows(), rotgen::Index{3});
TTS_EQUAL(b.cols(), rotgen::Index{3});
TTS_EXPECT(b.data() == ptr);
};
@ -135,31 +135,32 @@ 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);
TTS_EQUAL(b.rows(), 2ULL);
TTS_EQUAL(b.cols(), 2ULL);
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>> )
{
rotgen::matrix<T,1,1,O::value> b1 = {3.5};
TTS_EQUAL(b1.rows(), 1ULL);
TTS_EQUAL(b1.cols(), 1ULL);
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);
rotgen::matrix<T,5,1,O::value> b9 = {0.25, 0.5, 1, 2, 4};
TTS_EQUAL(b9.rows(), 5ULL);
TTS_EQUAL(b9.cols(), 1ULL);
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(std::size_t r=0;r<b9.rows();++r) {
for(rotgen::Index r=0;r<b9.rows();++r)
{
TTS_EQUAL(b9(r,0), i);
i *= 2;
}
rotgen::matrix<T,1,3,O::value> b13 = {1.2,2.3,3.4};
TTS_EQUAL(b13.rows(), 1ULL);
TTS_EQUAL(b13.cols(), 3ULL);
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));
@ -168,16 +169,18 @@ TTS_CASE_TPL("Constructor from Initializer list", rotgen::tests::types)
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}};
TTS_EQUAL(b1.rows(), 1ULL);
TTS_EQUAL(b1.cols(), 1ULL);
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));
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b23 = { {1.2,2.3,3.4}
, {10,200,3000}
};
TTS_EQUAL(b23.rows(), 2ULL);
TTS_EQUAL(b23.cols(), 3ULL);
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));

View file

@ -6,7 +6,7 @@
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/matrix.hpp>
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("Function size", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
@ -16,10 +16,10 @@ TTS_CASE_TPL("Function size", rotgen::tests::types)
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(), 0ULL);
TTS_EQUAL(matrix.size(), 12ULL);
TTS_EQUAL(row_vector.size(), 9ULL);
TTS_EQUAL(column_vector.size(), 5ULL);
TTS_EQUAL(empty_matrix.size(), rotgen::Index{0});
TTS_EQUAL(matrix.size(), rotgen::Index{12});
TTS_EQUAL(row_vector.size(), rotgen::Index{9});
TTS_EQUAL(column_vector.size(), rotgen::Index{5});
};
TTS_CASE_TPL("Resizing dynamic matrix", rotgen::tests::types)
@ -27,21 +27,21 @@ TTS_CASE_TPL("Resizing dynamic matrix", rotgen::tests::types)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 3);
for(std::size_t r=0;r<a.rows();++r)
for(std::size_t c=0;c<a.cols();++c)
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(), 3ULL);
TTS_EQUAL(a.cols(), 2ULL);
TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(a.cols(), rotgen::Index(2));
for(std::size_t r=0;r<a.rows();++r)
for(std::size_t c=0;c<a.cols();++c)
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);
TTS_EQUAL(a.rows(), 2ULL);
TTS_EQUAL(a.cols(), 2ULL);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), rotgen::Index(2));
};
TTS_CASE_TPL("Resizing static matrix", rotgen::tests::types)
@ -57,52 +57,52 @@ TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types)
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 3);
int i = 1;
for(std::size_t r=0;r<a.rows();++r)
for(std::size_t c=0;c<a.cols();++c)
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(), 2ULL);
TTS_EQUAL(a.cols(), 3ULL);
TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(a.cols(), rotgen::Index(3));
i = 1;
for(std::size_t r=0;r<a.rows();++r)
for(std::size_t c=0;c<a.cols();++c)
for(rotgen::Index r=0;r<a.rows();++r)
for(rotgen::Index c=0;c<a.cols();++c)
TTS_EQUAL(a(r,c),i++);
a.conservativeResize(3, 2);
TTS_EQUAL(a.rows(), 3ULL);
TTS_EQUAL(a.cols(), 2ULL);
TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(a.cols(), rotgen::Index(2));
int expected[3][2] = { {1, 2}, {4, 5} };
for(std::size_t r = 0; r < 2; ++r)
for(std::size_t c = 0; c < 2; ++c)
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(), 4ULL);
TTS_EQUAL(a.cols(), 4ULL);
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);
a.conservativeResize(2, 2);
TTS_EQUAL(a.rows(), 2ULL);
TTS_EQUAL(a.cols(), 2ULL);
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);
a.conservativeResize(1, 2);
TTS_EQUAL(a.rows(), 1ULL);
TTS_EQUAL(a.cols(), 2ULL);
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);
a.conservativeResize(0, 0);
TTS_EQUAL(a.rows(), 0ULL);
TTS_EQUAL(a.cols(), 0ULL);
TTS_EQUAL(a.rows(), rotgen::Index(0));
TTS_EQUAL(a.cols(), rotgen::Index(0));
a.conservativeResize(3, 3);
TTS_EQUAL(a.rows(), 3ULL);
TTS_EQUAL(a.cols(), 3ULL);
TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(a.cols(), rotgen::Index(3));
};
TTS_CASE_TPL("Static matrix conservative resizing", rotgen::tests::types)
@ -117,8 +117,8 @@ TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(3, 5);
for(std::size_t r=0;r<a.rows();++r)
for(std::size_t c=0;c<a.cols();++c)
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);
@ -143,19 +143,19 @@ TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types)
int i = 1;
if constexpr(!O::value)
{
for(std::size_t c=0;c<a.cols();++c)
for(std::size_t r=0;r<a.rows();++r)
for(rotgen::Index c=0;c<a.cols();++c)
for(rotgen::Index r=0;r<a.rows();++r)
a(r, c) = i++;
}
else
{
for(std::size_t r=0;r<a.rows();++r)
for(std::size_t c=0;c<a.cols();++c)
for(rotgen::Index r=0;r<a.rows();++r)
for(rotgen::Index c=0;c<a.cols();++c)
a(r, c) = i++;
}
i = 1;
for(std::size_t r=0;r<a.rows()*a.cols();++r)
for(rotgen::Index r=0;r<a.rows()*a.cols();++r)
TTS_EQUAL(a(r), i++) << a;
T& ref = a(2);

View file

@ -6,7 +6,7 @@
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/matrix.hpp>
#include <rotgen/rotgen.hpp>
#include <sstream>
TTS_CASE_TPL("Sample test", rotgen::tests::types)
@ -17,4 +17,4 @@ TTS_CASE_TPL("Sample test", rotgen::tests::types)
os << x;
TTS_EQUAL(os.str(), std::string{"1 2\n3 4"});
};
};

View file

@ -6,7 +6,7 @@
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/matrix.hpp>
#include <rotgen/rotgen.hpp>
#include <Eigen/Dense>
TTS_CASE_TPL("Matrix norm-related operations", rotgen::tests::types)
@ -30,9 +30,9 @@ TTS_CASE_TPL("Matrix norm-related operations", rotgen::tests::types)
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> matrix(rows, cols);
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic,O::value> ref(rows, cols);
for (std::size_t r = 0; r < rows; ++r)
for (rotgen::Index r = 0; r < rows; ++r)
{
for (std::size_t c = 0; c < cols; ++c)
for (rotgen::Index c = 0; c < cols; ++c)
{
ref(r, c) = matrix(r, c) = fn(r,c);
}
@ -40,8 +40,8 @@ TTS_CASE_TPL("Matrix norm-related operations", rotgen::tests::types)
TTS_EQUAL(matrix.norm(), ref.norm());
TTS_EQUAL(matrix.squaredNorm(), ref.squaredNorm());
TTS_EQUAL(matrix.template lp_norm<1>() , ref.template lpNorm<1>());
TTS_EQUAL(matrix.template lp_norm<2>() , ref.template lpNorm<2>());
TTS_EQUAL(matrix.template lp_norm<rotgen::Infinity>(), ref.template lpNorm<Eigen::Infinity>());
TTS_EQUAL(matrix.template lpNorm<1>() , ref.template lpNorm<1>());
TTS_EQUAL(matrix.template lpNorm<2>() , ref.template lpNorm<2>());
TTS_EQUAL(matrix.template lpNorm<rotgen::Infinity>(), ref.template lpNorm<Eigen::Infinity>());
}
};

View file

@ -6,18 +6,18 @@
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/matrix.hpp>
#include <rotgen/rotgen.hpp>
template <typename MatrixType>
void test_matrix_operations(std::size_t rows, std::size_t cols, auto a_init_fn, auto b_init_fn, auto ops, auto self_ops)
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);
MatrixType ref(rows, cols);
for (std::size_t r = 0; r < rows; ++r)
for (rotgen::Index r = 0; r < rows; ++r)
{
for (std::size_t c = 0; c < cols; ++c)
for (rotgen::Index c = 0; c < cols; ++c)
{
a(r,c) = a_init_fn(r, c);
b(r,c) = b_init_fn(r, c);
@ -28,17 +28,20 @@ void test_matrix_operations(std::size_t rows, std::size_t cols, auto a_init_fn,
TTS_EQUAL(ops(a, b), ref);
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(std::size_t rows, std::size_t cols, auto a_init_fn, auto s, auto ops, auto self_ops)
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);
for (std::size_t r = 0; r < rows; ++r)
for (rotgen::Index r = 0; r < rows; ++r)
{
for (std::size_t c = 0; c < cols; ++c)
for (rotgen::Index c = 0; c < cols; ++c)
{
a(r,c) = a_init_fn(r, c);
ref(r, c) = ops(a(r,c),s);
@ -48,17 +51,20 @@ void test_scalar_operations(std::size_t rows, std::size_t cols, auto a_init_fn,
TTS_EQUAL(ops(a, s), ref);
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(std::size_t rows, std::size_t cols, auto fn, auto s)
void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn, auto s)
{
MatrixType a(rows, cols);
MatrixType ref(rows, cols);
for (std::size_t r = 0; r < rows; ++r)
for (rotgen::Index r = 0; r < rows; ++r)
{
for (std::size_t c = 0; c < cols; ++c)
for (rotgen::Index c = 0; c < cols; ++c)
{
a(r,c) = fn(r, c);
ref(r, c) = a(r,c) * s;
@ -69,34 +75,39 @@ void test_scalar_multiplications(std::size_t rows, std::size_t cols, auto fn, au
TTS_EQUAL(s * a, ref);
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));
}
template <typename MatrixType>
void test_matrix_multiplication(std::size_t rows, std::size_t cols, auto a_init_fn, auto b_init_fn)
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 (std::size_t r = 0; r < a.rows(); ++r)
for (std::size_t c = 0; c < a.cols(); ++c)
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 (std::size_t r = 0; r < b.rows(); ++r)
for (std::size_t c = 0; c < b.cols(); ++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 (std::size_t i = 0; i < a.rows(); ++i)
for (rotgen::Index i = 0; i < a.rows(); ++i)
{
for (std::size_t j = 0; j < b.cols(); ++j)
for (rotgen::Index j = 0; j < b.cols(); ++j)
{
ref(i, j) = 0;
for (std::size_t k = 0; k < a.cols(); ++k)
for (rotgen::Index k = 0; k < a.cols(); ++k)
ref(i, j) += a(i, k) * b(k, j);
}
}
TTS_EQUAL(a * b, ref);
TTS_EXPECT(verify_rotgen_reentrance(a*b));
}
// Basic initializers

View file

@ -6,10 +6,11 @@
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/matrix.hpp>
#include <rotgen/rotgen.hpp>
void test_value(const auto& 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);
@ -17,6 +18,7 @@ void test_value(const auto& matrix, std::size_t rows, std::size_t cols, auto con
void test_random(const auto& 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)
{
@ -27,6 +29,7 @@ void test_random(const auto& matrix, std::size_t rows, std::size_t cols)
void test_identity(const auto& 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);

View file

@ -6,8 +6,11 @@
*/
//==================================================================================================
#define TTS_MAIN
#define TTS_CUSTOM_DRIVER_FUNCTION rotgen_main
#include "tts.hpp"
#include <rotgen/detail/static_info.hpp>
#include <rotgen/config.hpp>
#include <rotgen/concepts.hpp>
#include <functional>
namespace rotgen::tests
@ -25,25 +28,50 @@ namespace rotgen::tests
struct matrix_descriptor
{
std::size_t rows, cols;
rotgen::Index rows, cols;
std::function<double(std::size_t,std::size_t)> init_fn;
};
template<typename MatrixType>
struct matrix_block_test_case
{
std::size_t rows, cols;
std::function<typename MatrixType::scalar_type(std::size_t, std::size_t)> init_fn;
std::size_t i0, j0, ni, nj;
rotgen::Index rows, cols;
std::function<typename MatrixType::scalar_type(std::size_t, rotgen::Index)> init_fn;
rotgen::Index i0, j0, ni, nj;
};
template<typename MatrixType, std::size_t NI, std::size_t NJ>
template<typename MatrixType, rotgen::Index NI, rotgen::Index NJ>
struct static_matrix_block_test_case
{
std::size_t rows, cols;
std::function<typename MatrixType::scalar_type(std::size_t, std::size_t)> init_fn;
static constexpr std::size_t ni = NI;
static constexpr std::size_t nj = NJ;
std::size_t i0, j0;
rotgen::Index rows, cols;
std::function<typename MatrixType::scalar_type(std::size_t, rotgen::Index)> init_fn;
static constexpr rotgen::Index ni = NI;
static constexpr rotgen::Index nj = NJ;
rotgen::Index i0, j0;
};
}
#include <iostream>
template<typename T>
constexpr bool verify_rotgen_reentrance(T const&)
{
return rotgen::concepts::entity<T>;
}
int main(int argc, char const **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;
rotgen::setup_summary(std::cout);
rotgen_main(argc, argv);
return tts::report(0,0);
}