114 lines
3.8 KiB
C++
114 lines
3.8 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 block transposition-like 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 (auto const& [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_shape_functions(input);
|
|
}
|
|
};
|
|
|
|
TTS_CASE_TPL("Test static block transposition-like 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_shape_functions(input);
|
|
};
|
|
|
|
std::apply([&](auto const&... d) { (process(d), ...); }, cases);
|
|
};
|
|
|
|
TTS_CASE_TPL("Test dynamic block reduction-like 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 (auto const& [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_reduction_functions(input);
|
|
}
|
|
};
|
|
|
|
TTS_CASE_TPL("Test static block reduction-like 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_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 v = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1,
|
|
16,
|
|
2);
|
|
auto a = rotgen::head(v, 8);
|
|
auto b = rotgen::tail(v, 8);
|
|
|
|
TTS_EQUAL(rotgen::dot(a, b), 32);
|
|
}
|
|
|
|
{
|
|
auto v = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(16, 1, 2);
|
|
auto a = rotgen::head(v, 8);
|
|
auto b = rotgen::tail(v, 8);
|
|
|
|
TTS_EQUAL(rotgen::dot(a, b), 32);
|
|
}
|
|
|
|
{
|
|
auto v = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 16, 2);
|
|
auto a = rotgen::head<8>(v);
|
|
auto b = rotgen::tail<8>(v);
|
|
|
|
TTS_EQUAL(rotgen::dot(a, b), 32);
|
|
}
|
|
|
|
{
|
|
auto v = rotgen::setConstant<rotgen::matrix<T, rotgen::Dynamic, 1>>(16, 1, 2);
|
|
auto a = rotgen::head<8>(v);
|
|
auto b = rotgen::tail<8>(v);
|
|
|
|
TTS_EQUAL(rotgen::dot(a, b), 32);
|
|
}
|
|
}
|
|
;
|