rotgen/test/unit/functions/qr.cpp
Jules Pénuchot 648dd768ee Adding clang-format configuration file and formatting all source files
Co-authored-by: Jules Pénuchot <jules@penuchot.com>
Co-authored-by: Joel FALCOU <jfalcou@codereckons.com>

See merge request oss/rotgen!41
2025-10-14 16:19:03 +02:00

35 lines
1.3 KiB
C++

//==================================================================================================
/*
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> a{{2.3, -1, 0.1},
{-1.6, 2.6, -1},
{0.3, -1, 2}};
rotgen::matrix<T, rotgen::Dynamic, 1> b(3, 1);
b(0) = b(2) = 1;
b(1) = 0;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic> 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";
};