Implement a QR solver wrapper

This commit is contained in:
Joel Falcou 2025-09-09 16:27:22 +02:00
parent bb5d739e5d
commit bb47b07422
10 changed files with 90 additions and 6 deletions

View file

@ -17,12 +17,13 @@ target_link_libraries(rotgen_test INTERFACE rotgen Eigen3::Eigen)
##======================================================================================================================
## Unit Tests registration
##======================================================================================================================
rotgen_glob_unit(QUIET PATTERN "unit/*.cpp" INTERFACE rotgen_test)
rotgen_glob_unit(QUIET PATTERN "unit/matrix/*.cpp" INTERFACE rotgen_test)
rotgen_glob_unit(QUIET PATTERN "unit/block/*.cpp" INTERFACE rotgen_test)
rotgen_glob_unit(QUIET PATTERN "unit/map/*.cpp" INTERFACE rotgen_test)
rotgen_glob_unit(QUIET PATTERN "unit/*.cpp" INTERFACE rotgen_test)
rotgen_glob_unit(QUIET PATTERN "unit/matrix/*.cpp" INTERFACE rotgen_test)
rotgen_glob_unit(QUIET PATTERN "unit/block/*.cpp" INTERFACE rotgen_test)
rotgen_glob_unit(QUIET PATTERN "unit/map/*.cpp" INTERFACE rotgen_test)
rotgen_glob_unit(QUIET PATTERN "unit/functions/*.cpp" INTERFACE rotgen_test)
##======================================================================================================================
## Integrations Tests registration
##======================================================================================================================
rotgen_glob_unit(QUIET PATTERN "integration/*.cpp" INTERFACE rotgen_test)
rotgen_glob_unit(QUIET PATTERN "integration/*.cpp" INTERFACE rotgen_test)

View file

@ -0,0 +1,34 @@
//==================================================================================================
/*
ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#include "unit/tests.hpp"
#include <rotgen/rotgen.hpp>
TTS_CASE_TPL("System solver using QR", rotgen::tests::types)
<typename T, typename O>( tts::type< tts::types<T,O>> )
{
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>
a { { 2.3, -1, 0.1}
, {-1.6, 2.6, -1}
, { 0.3, -1, 2}
};
rotgen::matrix<T,rotgen::Dynamic,1,O::value> b(3,1);
b(0) = b(2) = 1; b(1) = 0;
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> r(3,1), error;
auto x = rotgen::extract(r,0,0,3,1);
rotgen::solver::qr(x, a, b);
error = a * r - b;
auto eps = std::numeric_limits<T>::epsilon();
TTS_LESS(rotgen::maxCoeff(rotgen::abs(error)) / eps, 5)
<< "Result:\n" << r << "\n"
<< "Residuals:\n" << error << "\n";
};