//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== #include "unit/tests.hpp" #include "unit/common/arithmetic.hpp" #include TTS_CASE_TPL("Test dynamic matrix inverse", rotgen::tests::types) ( tts::type< tts::types> ) { using mat_t = rotgen::matrix; auto eps = std::numeric_limits::epsilon(); auto const cases = rotgen::tests::generate_matrix_references(); for (const auto& [r, c, fn] : cases) { if(r == c) { auto input = mat_t::Random(r, c); auto inv = rotgen::inverse(input); auto rec = input * inv; auto id = mat_t::Identity(rotgen::rows(rec),rotgen::cols(rec)); auto error = rec - id; TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 64.) << "Result:\n" << rec << "\n" << "Residuals:\n" << error << "\n"; } } }; TTS_CASE_TPL("Test static matrix inverse", rotgen::tests::types) ( tts::type< tts::types> ) { using mat_t = rotgen::matrix; auto eps = std::numeric_limits::epsilon(); auto const cases = rotgen::tests::generate_static_matrix_references(); auto process = [&](D const&) { if constexpr(D::rows == D::cols) { auto input = rotgen::matrix::Random(); auto inv = rotgen::inverse(input); auto rec = input * inv; auto id = mat_t::Identity(rotgen::rows(rec),rotgen::cols(rec)); auto error = rec - id; TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 64.) << "Result:\n" << rec << "\n" << "Residuals:\n" << error << "\n"; } }; std::apply([&](auto const&... d) { (process(d),...);}, cases); };