Fix a lot of ref issues reagrding extarction, rvalueness and proper use of temporary memory.

This commit is contained in:
Joel Falcou 2025-10-28 20:12:33 +01:00
parent d5c41bf43e
commit 379d77ebef
50 changed files with 2945 additions and 1397 deletions

View file

@ -7,7 +7,6 @@
//==================================================================================================
#include <rotgen/rotgen.hpp>
#include "unit/common/arithmetic.hpp"
#include "unit/tests.hpp"
TTS_CASE_TPL("Test dynamic matrix inverse",
@ -17,52 +16,50 @@ TTS_CASE_TPL("Test dynamic matrix inverse",
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto eps = std::numeric_limits<T>::epsilon();
auto const cases = rotgen::tests::generate_matrix_references();
for (auto const& [r, c, fn] : cases)
for (int n = 2; n < 15; n *= 1.5)
{
if (r == c)
{
auto input = mat_t::Random(r, c);
auto inv = rotgen::inverse(input);
auto input = 10 * rotgen::setRandom<mat_t>(n, n);
auto inv = rotgen::inverse(input);
auto rec = input * inv;
auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec));
auto error = rec - id;
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_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 256.)
<< "Result:\n"
<< rec << "\n"
<< "Residuals:\n"
<< error << "\n";
}
};
template<typename T, typename O, int N> void check_static_inverse()
{
using mat_t = rotgen::matrix<T, N, N, O::value>;
auto eps = std::numeric_limits<T>::epsilon();
auto input = rotgen::setRandom<mat_t>();
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, 256.)
<< "Result:\n"
<< rec << "\n"
<< "Residuals:\n"
<< error << "\n";
}
TTS_CASE_TPL("Test static matrix inverse",
rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
{
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto eps = std::numeric_limits<T>::epsilon();
auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = [&]<typename D>(D const&) {
if constexpr (D::rows == D::cols)
{
auto input = rotgen::matrix<T, D::rows, D::cols, O::value>::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);
check_static_inverse<T, O, 2>();
check_static_inverse<T, O, 3>();
check_static_inverse<T, O, 4>();
check_static_inverse<T, O, 6>();
check_static_inverse<T, O, 9>();
check_static_inverse<T, O, 13>();
};