Implements map and ref for both static & dynamic mode
See merge request oss/rotgen!12
This commit is contained in:
parent
aacae1cbb1
commit
6c2b260229
58 changed files with 4121 additions and 1205 deletions
126
test/unit/common/arithmetic.hpp
Normal file
126
test/unit/common/arithmetic.hpp
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include <rotgen/rotgen.hpp>
|
||||
#include <Eigen/Dense>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
namespace rotgen::tests
|
||||
{
|
||||
template<typename T>
|
||||
void check_shape_functions(T original)
|
||||
{
|
||||
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);
|
||||
|
||||
TTS_EQUAL(original.transpose(), result );
|
||||
TTS_EQUAL(original.conjugate(), original);
|
||||
TTS_EQUAL(original.adjoint() , 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::RowsAtCompileTime == T::ColsAtCompileTime)
|
||||
{
|
||||
mat_t ref = original;
|
||||
original.transposeInPlace();
|
||||
TTS_EQUAL(original, result);
|
||||
|
||||
original.adjointInPlace();
|
||||
TTS_EQUAL(original, ref);
|
||||
|
||||
transposeInPlace(original);
|
||||
TTS_EQUAL(original, result);
|
||||
|
||||
adjointInPlace(original);
|
||||
TTS_EQUAL(original, ref);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (original.rows() == original.cols())
|
||||
{
|
||||
mat_t ref = original;
|
||||
original.transposeInPlace();
|
||||
TTS_EQUAL(original, result);
|
||||
|
||||
original.adjointInPlace();
|
||||
TTS_EQUAL(original, ref);
|
||||
|
||||
transposeInPlace(original);
|
||||
TTS_EQUAL(original, result);
|
||||
|
||||
adjointInPlace(original);
|
||||
TTS_EQUAL(original, ref);
|
||||
}
|
||||
}
|
||||
|
||||
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()) );
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void check_reduction_functions(const T& input)
|
||||
{
|
||||
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);
|
||||
|
||||
TTS_ULP_EQUAL(input.sum(), ref.sum() , 2);
|
||||
TTS_ULP_EQUAL(sum(input) , ref.sum() , 2);
|
||||
|
||||
TTS_ULP_EQUAL(input.prod(), ref.prod(), 2);
|
||||
TTS_ULP_EQUAL(prod(input) , ref.prod(), 2);
|
||||
|
||||
TTS_ULP_EQUAL(input.mean(), ref.mean(), 2);
|
||||
TTS_ULP_EQUAL(mean(input) , ref.mean(), 2);
|
||||
|
||||
TTS_EQUAL(input.trace(), ref.trace());
|
||||
TTS_EQUAL(trace(input) , ref.trace());
|
||||
|
||||
TTS_EQUAL(input.minCoeff(), ref.minCoeff());
|
||||
TTS_EQUAL(minCoeff(input) , ref.minCoeff());
|
||||
|
||||
TTS_EQUAL(input.maxCoeff(), ref.maxCoeff());
|
||||
TTS_EQUAL(maxCoeff(input) , ref.maxCoeff());
|
||||
|
||||
{
|
||||
rotgen::Index row, col, ref_row, ref_col;
|
||||
|
||||
TTS_EQUAL(input.minCoeff(&row, &col), ref.minCoeff(&ref_row, &ref_col));
|
||||
TTS_EQUAL(row, ref_row);
|
||||
TTS_EQUAL(col, ref_col);
|
||||
|
||||
TTS_EQUAL(input.maxCoeff(&row, &col), ref.maxCoeff(&ref_row, &ref_col));
|
||||
TTS_EQUAL(row, ref_row);
|
||||
TTS_EQUAL(col, ref_col);
|
||||
}
|
||||
|
||||
{
|
||||
rotgen::Index row, col, 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(row, ref_row);
|
||||
TTS_EQUAL(col, ref_col);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
test/unit/common/norms.hpp
Normal file
35
test/unit/common/norms.hpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include <rotgen/rotgen.hpp>
|
||||
#include <Eigen/Dense>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
namespace rotgen::tests
|
||||
{
|
||||
template<typename T>
|
||||
void check_norms_functions(const T& input)
|
||||
{
|
||||
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);
|
||||
|
||||
TTS_EQUAL(input.norm() , ref.norm());
|
||||
TTS_EQUAL(input.squaredNorm() , ref.squaredNorm());
|
||||
TTS_EQUAL(input.template lpNorm<1>() , ref.template lpNorm<1>());
|
||||
TTS_EQUAL(input.template lpNorm<2>() , ref.template lpNorm<2>());
|
||||
TTS_EQUAL(input.template lpNorm<rotgen::Infinity>() , ref.template lpNorm<Eigen::Infinity>());
|
||||
|
||||
TTS_EQUAL(norm(input) , ref.norm());
|
||||
TTS_EQUAL(squaredNorm(input) , ref.squaredNorm());
|
||||
TTS_EQUAL(lpNorm<1>(input) , ref.template lpNorm<1>());
|
||||
TTS_EQUAL(lpNorm<2>(input) , ref.template lpNorm<2>());
|
||||
TTS_EQUAL(lpNorm<rotgen::Infinity>(input) , ref.template lpNorm<Eigen::Infinity>());
|
||||
}
|
||||
}
|
||||
192
test/unit/common/references.hpp
Normal file
192
test/unit/common/references.hpp
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
|
||||
#include <rotgen/rotgen.hpp>
|
||||
#include <Eigen/Dense>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
namespace rotgen::tests
|
||||
{
|
||||
struct matrix_descriptor
|
||||
{
|
||||
rotgen::Index rows, cols;
|
||||
std::function<double(std::size_t,std::size_t)> init_fn;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
template<typename MatrixType>
|
||||
struct matrix_block_test_case
|
||||
{
|
||||
matrix_descriptor matrix_desc;
|
||||
rotgen::Index i0, j0, ni, nj;
|
||||
};
|
||||
|
||||
template<typename MatrixType, rotgen::Index NI, rotgen::Index NJ>
|
||||
struct static_matrix_block_test_case
|
||||
{
|
||||
matrix_descriptor matrix_desc;
|
||||
static constexpr rotgen::Index ni = NI;
|
||||
static constexpr rotgen::Index nj = NJ;
|
||||
rotgen::Index i0, j0;
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
auto generate_matrix_references()
|
||||
{
|
||||
auto fn = [](auto r, auto c) { return r + 3 * c - 2.5; };
|
||||
std::vector<rotgen::tests::matrix_descriptor> cases =
|
||||
{
|
||||
// Singular matrix
|
||||
{1, 1, fn},
|
||||
// Square matrix below MAX_SIZE
|
||||
{3, 3, fn},
|
||||
// Square matrix at MAX_SIZE
|
||||
{4, 4, fn},
|
||||
// Square matrix above MAX_SIZE
|
||||
{7, 7, fn},
|
||||
// Tall matrix below MAX_SIZE
|
||||
{5, 2, fn},
|
||||
// Tall matrix at MAX_SIZE
|
||||
{8, 2, fn},
|
||||
// Tall matrix above MAX_SIZE
|
||||
{10, 3, fn},
|
||||
// Thick matrix below MAX_SIZE
|
||||
{2, 5, fn},
|
||||
// Thick matrix at MAX_SIZE
|
||||
{2, 8, fn},
|
||||
// Thick matrix above MAX_SIZE
|
||||
{3, 10, fn}
|
||||
};
|
||||
|
||||
return cases;
|
||||
}
|
||||
|
||||
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}
|
||||
};
|
||||
|
||||
return cases;
|
||||
}
|
||||
|
||||
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; }};
|
||||
|
||||
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
||||
|
||||
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},
|
||||
// Square block below MAX_SIZE
|
||||
{base,7,9, 3, 3},
|
||||
// Square block at MAX_SIZE
|
||||
{base,6,3, 4, 4},
|
||||
// Square block above MAX_SIZE
|
||||
{base,6,3, 6, 6},
|
||||
// Tall block below MAX_SIZE
|
||||
{base,6,3, 5, 2},
|
||||
// Tall block at MAX_SIZE
|
||||
{base,6,3, 8, 2},
|
||||
// Tall block above MAX_SIZE
|
||||
{base,6,3, 7, 3},
|
||||
// Thick block below MAX_SIZE
|
||||
{base,6,3, 2, 5},
|
||||
// Thick block at MAX_SIZE
|
||||
{base,6,3, 2, 8},
|
||||
// Thick block above MAX_SIZE
|
||||
{base,6,3, 3, 7}
|
||||
};
|
||||
|
||||
return cases;
|
||||
}
|
||||
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; }};
|
||||
|
||||
using mat_t = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
||||
|
||||
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},
|
||||
// Square block below MAX_SIZE
|
||||
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},
|
||||
// Square block above MAX_SIZE
|
||||
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},
|
||||
// Tall block at MAX_SIZE
|
||||
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},
|
||||
// Thick block below MAX_SIZE
|
||||
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},
|
||||
// Thick block above MAX_SIZE
|
||||
static_matrix_block_test_case<mat_t, 3, 7>{base,6,3}
|
||||
};
|
||||
|
||||
return cases;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue