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

@ -241,6 +241,11 @@ namespace rotgen
parent& base() { return static_cast<parent&>(*this); }
parent const& base() const { return static_cast<parent const&>(*this); }
concrete_type qr_solve(map const& rhs) const
{
return concrete_type(base().qr_solve(rhs.base()));
};
};
template<typename R1, typename R2, int O1, typename S1, int O2, typename S2>

View file

@ -193,6 +193,11 @@ namespace rotgen
void transposeInPlace() { base().transposeInPlace(); }
void adjointInPlace() { base().adjointInPlace(); }
auto qr_solve(map const& rhs) const
{
return concrete_type(base().colPivHouseholderQr().solve(rhs.base()));
};
static auto Zero() requires( requires {Ref::Zero();} ) { return Ref::Zero(); }
static auto Zero(int rows, int cols) { return Ref::Zero(rows,cols); }

View file

@ -52,7 +52,13 @@ namespace rotgen
auto sum(concepts::entity auto const& arg) { return arg.sum(); }
auto prod(concepts::entity auto const& arg) { return arg.prod(); }
auto mean(concepts::entity auto const& arg) { return arg.mean(); }
auto maxCoeff(concepts::entity auto const& arg) { return arg.maxCoeff(); }
auto maxCoeff(auto const& arg)
requires( requires{ arg.maxCoeff(); } )
{
return arg.maxCoeff();
}
auto minCoeff(concepts::entity auto const& arg) { return arg.minCoeff(); }
auto maxCoeff(concepts::entity auto const& arg, Index* row, Index* col)
{

View file

@ -63,6 +63,8 @@ class ROTGEN_EXPORT CLASSNAME
TYPE norm() const;
TYPE lpNorm(int p) const;
SOURCENAME qr_solve(CLASSNAME const& rhs) const;
#if !defined(USE_CONST)
TYPE& operator()(Index i, Index j);
TYPE& operator()(Index i);

View file

@ -26,4 +26,5 @@
#include <rotgen/extract.hpp>
#include <rotgen/functions.hpp>
#include <rotgen/operators.hpp>
#include <rotgen/solver.hpp>
#include <rotgen/alias.hpp>

20
include/rotgen/solver.hpp Normal file
View file

@ -0,0 +1,20 @@
//==================================================================================================
/*
ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once
namespace rotgen::solver
{
template<typename X, typename M, typename RHS>
void qr(X& x, M const& m, RHS const& rhs )
{
auto r_x = generalize_t<X>(x);
auto r_m = generalize_t<M const>(m);
auto r_rhs = generalize_t<RHS const>(rhs);
r_x = r_m.base().qr_solve(r_rhs.base());
}
}