//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== #include #include "rotgen/functions/functions.hpp" #include "unit/common/references.hpp" #include "unit/tests.hpp" void test_value(auto const& matrix, auto value, rotgen::Index i0, rotgen::Index j0, rotgen::Index rows, rotgen::Index cols) { for (rotgen::Index r = 0; r < rows; ++r) for (rotgen::Index c = 0; c < cols; ++c) TTS_EQUAL(matrix(i0 + r, j0 + c), value); } void test_identity(auto const& matrix, rotgen::Index i0, rotgen::Index j0, rotgen::Index rows, rotgen::Index cols) { for (rotgen::Index r = 0; r < rows; ++r) for (rotgen::Index c = 0; c < cols; ++c) TTS_EQUAL(matrix(i0 + r, j0 + c), r == c ? 1 : 0); } void test_random(auto const& matrix, rotgen::Index i0, rotgen::Index j0, rotgen::Index rows, rotgen::Index cols) { for (rotgen::Index r = 0; r < rows; ++r) for (rotgen::Index c = 0; c < cols; ++c) { TTS_GREATER_EQUAL(matrix(i0 + r, j0 + c), -1.0); TTS_LESS_EQUAL(matrix(i0 + r, j0 + c), 1.0); } } TTS_CASE_TPL("Test dynamic block::setZero", rotgen::tests::types) (tts::type>) { auto const cases = rotgen::tests::generate_block_references(); for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { auto [rows, cols, fn] = matrix_desc; rotgen::matrix m(rows, cols); rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); rotgen::setZero(input); test_value(m, T{0}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); auto values = rotgen::setZero(ni, nj); test_value(values, T{0}, 0, 0, ni, nj); } }; TTS_CASE_TPL("Test static block::setZero", rotgen::tests::types) (tts::type>) { auto const cases = rotgen::tests::generate_static_block_references(); auto process = [](D const& d) { auto [desc, i0, j0] = d; auto [rows, cols, fn] = desc; rotgen::matrix m(rows, cols); rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0); rotgen::setZero(input); test_value(m, T{0}, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); auto values = rotgen::setZero(); test_value(values, T{0}, 0, 0, D::ni, D::nj); }; std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; TTS_CASE_TPL("Test dynamic block::setOnes", rotgen::tests::types) (tts::type>) { auto const cases = rotgen::tests::generate_block_references(); for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { auto [rows, cols, fn] = matrix_desc; rotgen::matrix m(rows, cols); rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); rotgen::setOnes(input); test_value(m, T{1}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); auto values = rotgen::setOnes(ni, nj); test_value(values, T{1}, 0, 0, ni, nj); } }; TTS_CASE_TPL("Test static block::setOnes", rotgen::tests::types) (tts::type>) { auto const cases = rotgen::tests::generate_static_block_references(); auto process = [](D const& d) { auto [desc, i0, j0] = d; auto [rows, cols, fn] = desc; rotgen::matrix m(rows, cols); rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0); rotgen::setOnes(input); test_value(m, T{1}, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); auto values = rotgen::setOnes(); test_value(values, T{1}, 0, 0, D::ni, D::nj); }; std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; TTS_CASE_TPL("Test dynamic block::setConstant", rotgen::tests::types) (tts::type>) { auto const cases = rotgen::tests::generate_block_references(); for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { auto [rows, cols, fn] = matrix_desc; rotgen::matrix m(rows, cols); rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); rotgen::setConstant(input, T{13.37f}); test_value(m, T{13.37f}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); auto values = rotgen::setConstant(ni, nj, T{13.37f}); test_value(values, T{13.37f}, 0, 0, ni, nj); } }; TTS_CASE_TPL("Test static block::setConstant", rotgen::tests::types) (tts::type>) { auto const cases = rotgen::tests::generate_static_block_references(); auto process = [](D const& d) { auto [desc, i0, j0] = d; auto [rows, cols, fn] = desc; rotgen::matrix m(rows, cols); rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0); rotgen::setConstant(input, T{13.37f}); test_value(m, T{13.37f}, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); auto values = rotgen::setConstant(T{13.37f}); test_value(values, T{13.37f}, 0, 0, D::ni, D::nj); }; std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; TTS_CASE_TPL("Test dynamic block::setIdentity", rotgen::tests::types) (tts::type>) { auto const cases = rotgen::tests::generate_block_references(); for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { auto [rows, cols, fn] = matrix_desc; rotgen::matrix m(rows, cols); rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); rotgen::setIdentity(input); test_identity(m, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); auto values = rotgen::setIdentity(ni, nj); test_identity(values, 0, 0, ni, nj); } }; TTS_CASE_TPL("Test static block::setIdentity", rotgen::tests::types) (tts::type>) { auto const cases = rotgen::tests::generate_static_block_references(); auto process = [](D const& d) { auto [desc, i0, j0] = d; auto [rows, cols, fn] = desc; rotgen::matrix m(rows, cols); rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0); rotgen::setIdentity(input); test_identity(m, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); auto values = rotgen::setIdentity(); test_identity(values, 0, 0, D::ni, D::nj); }; std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; TTS_CASE_TPL("Test dynamic block::setRandom", rotgen::tests::types) (tts::type>) { auto const cases = rotgen::tests::generate_block_references(); for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { auto [rows, cols, fn] = matrix_desc; rotgen::matrix m(rows, cols); rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); rotgen::setRandom(input); test_random(m, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); auto values = rotgen::setRandom(ni, nj); test_random(values, 0, 0, ni, nj); } }; TTS_CASE_TPL("Test static block::setRandom", rotgen::tests::types) (tts::type>) { auto const cases = rotgen::tests::generate_static_block_references(); auto process = [](D const& d) { auto [desc, i0, j0] = d; auto [rows, cols, fn] = desc; rotgen::matrix m(rows, cols); rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0); rotgen::setRandom(input); test_random(m, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); auto values = rotgen::setRandom(); test_random(values, 0, 0, D::ni, D::nj); }; std::apply([&](auto const&... d) { (process(d), ...); }, cases); };