Closes #18 Co-authored-by: Jules Pénuchot <jules@penuchot.com> See merge request oss/rotgen!50
106 lines
3.3 KiB
C++
106 lines
3.3 KiB
C++
//==================================================================================================
|
|
/*
|
|
ROTGEN - Runtime Overlay for Eigen
|
|
Copyright : CODE RECKONS
|
|
SPDX-License-Identifier: BSL-1.0
|
|
*/
|
|
//==================================================================================================
|
|
|
|
#include <rotgen/rotgen.hpp>
|
|
|
|
#include "unit/common/arithmetic.hpp"
|
|
#include "unit/common/references.hpp"
|
|
#include "unit/tests.hpp"
|
|
|
|
TTS_CASE_TPL("Test dynamic matrix transposition-like operations",
|
|
rotgen::tests::types)
|
|
|
|
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
|
{
|
|
auto const cases = rotgen::tests::generate_matrix_references();
|
|
for (auto const& [rows, cols, fn] : cases)
|
|
{
|
|
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> input(rows,
|
|
cols);
|
|
rotgen::tests::prepare(rows, cols, fn, input);
|
|
rotgen::tests::check_shape_functions(input);
|
|
}
|
|
};
|
|
|
|
TTS_CASE_TPL("Test static matrix transposition-like operations",
|
|
rotgen::tests::types)
|
|
|
|
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
|
{
|
|
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(rows(input), cols(input), desc.init_fn, input);
|
|
rotgen::tests::check_shape_functions(input);
|
|
};
|
|
|
|
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
|
|
};
|
|
|
|
TTS_CASE_TPL("Test dynamic matrix reduction-like operations",
|
|
rotgen::tests::types)
|
|
|
|
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
|
{
|
|
auto const cases = rotgen::tests::generate_matrix_references();
|
|
for (auto const& [rows, cols, fn] : cases)
|
|
{
|
|
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> input(rows,
|
|
cols);
|
|
rotgen::tests::prepare(rows, cols, fn, input);
|
|
rotgen::tests::check_reduction_functions(input);
|
|
}
|
|
};
|
|
|
|
TTS_CASE_TPL("Test static matrix reduction-like operations",
|
|
rotgen::tests::types)
|
|
|
|
<typename T, typename O>(tts::type<tts::types<T, O>>)
|
|
{
|
|
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(rows(input), cols(input), desc.init_fn, input);
|
|
rotgen::tests::check_reduction_functions(input);
|
|
};
|
|
|
|
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
|
|
};
|
|
|
|
TTS_CASE_TPL("Test dot product", float, double)
|
|
<typename T>(tts::type<T>){
|
|
{auto a = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 8, 2);
|
|
auto b = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 8, 2);
|
|
|
|
TTS_EQUAL(rotgen::dot(a, b), 32);
|
|
}
|
|
|
|
{
|
|
auto a = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(8, 1, 2);
|
|
auto b = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(8, 1, 2);
|
|
|
|
TTS_EQUAL(rotgen::dot(a, b), 32);
|
|
}
|
|
|
|
{
|
|
auto a = rotgen::setConstant<rotgen::matrix<T, 1, 8>>(2);
|
|
auto b = rotgen::setConstant<rotgen::matrix<T, 1, 8>>(2);
|
|
|
|
TTS_EQUAL(rotgen::dot(a, b), 32);
|
|
}
|
|
|
|
{
|
|
auto a = rotgen::setConstant<rotgen::matrix<T, 8, 1>>(2);
|
|
auto b = rotgen::setConstant<rotgen::matrix<T, 8, 1>>(2);
|
|
|
|
TTS_EQUAL(rotgen::dot(a, b), 32);
|
|
}
|
|
}
|
|
;
|