Add UT for unary cwise
This commit is contained in:
parent
fbe54c9f2c
commit
1f8663aad2
4 changed files with 213 additions and 0 deletions
42
test/unit/block/cwise.cpp
Normal file
42
test/unit/block/cwise.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
//==================================================================================================
|
||||||
|
/*
|
||||||
|
ROTGEN - Runtime Overlay for Eigen
|
||||||
|
Copyright : CODE RECKONS
|
||||||
|
SPDX-License-Identifier: BSL-1.0
|
||||||
|
*/
|
||||||
|
//==================================================================================================
|
||||||
|
#include "unit/tests.hpp"
|
||||||
|
#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>> )
|
||||||
|
{
|
||||||
|
auto const cases = rotgen::tests::generate_block_references<T,O>();
|
||||||
|
for (const auto& [matrix_desc, i0, j0, ni, nj] : cases)
|
||||||
|
{
|
||||||
|
auto[rows,cols,fn] = matrix_desc;
|
||||||
|
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> m(rows, cols);
|
||||||
|
rotgen::tests::prepare(rows,cols,fn,m);
|
||||||
|
auto input = rotgen::extract(m, i0, j0, ni, nj);
|
||||||
|
rotgen::tests::check_cwise_functions(input);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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 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);
|
||||||
|
};
|
||||||
93
test/unit/common/cwise.hpp
Normal file
93
test/unit/common/cwise.hpp
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
//==================================================================================================
|
||||||
|
/*
|
||||||
|
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_cwise_functions(const T& 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>;
|
||||||
|
|
||||||
|
TTS_WHEN("Unary Cwise operations")
|
||||||
|
{
|
||||||
|
EigenMatrix e_ref(input.rows(), input.cols());
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
TTS_EQUAL(input.cwiseInverse(), ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
TTS_AND_THEN(".cwiseSqrt")
|
||||||
|
{
|
||||||
|
e_ref = e_ref.cwiseAbs().cwiseSqrt();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TTS_AND_THEN("abs()")
|
||||||
|
{
|
||||||
|
e_ref = e_ref.cwiseAbs();
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
TTS_EQUAL(rotgen::rec(input), ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
TTS_AND_THEN("sqrt")
|
||||||
|
{
|
||||||
|
e_ref = e_ref.cwiseAbs().cwiseSqrt();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
41
test/unit/map/cwise.cpp
Normal file
41
test/unit/map/cwise.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
//==================================================================================================
|
||||||
|
/*
|
||||||
|
ROTGEN - Runtime Overlay for Eigen
|
||||||
|
Copyright : CODE RECKONS
|
||||||
|
SPDX-License-Identifier: BSL-1.0
|
||||||
|
*/
|
||||||
|
//==================================================================================================
|
||||||
|
#include "unit/tests.hpp"
|
||||||
|
#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>> )
|
||||||
|
{
|
||||||
|
auto const cases = rotgen::tests::generate_matrix_references();
|
||||||
|
for (const auto& [rows, cols, fn] : cases)
|
||||||
|
{
|
||||||
|
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::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>> )
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
};
|
||||||
37
test/unit/matrix/cwise.cpp
Normal file
37
test/unit/matrix/cwise.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
//==================================================================================================
|
||||||
|
/*
|
||||||
|
ROTGEN - Runtime Overlay for Eigen
|
||||||
|
Copyright : CODE RECKONS
|
||||||
|
SPDX-License-Identifier: BSL-1.0
|
||||||
|
*/
|
||||||
|
//==================================================================================================
|
||||||
|
#include "unit/tests.hpp"
|
||||||
|
#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>> )
|
||||||
|
{
|
||||||
|
auto const cases = rotgen::tests::generate_matrix_references();
|
||||||
|
for (const auto& [rows, cols, fn] : cases)
|
||||||
|
{
|
||||||
|
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>> )
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
rotgen::tests::check_cwise_functions(input);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::apply([&](auto const&... d) { (process(d),...);}, cases);
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue