5#include <proxsuite/linalg/dense/ldlt.hpp>
11namespace veg = proxsuite::linalg::veg;
12namespace dense_linalg = proxsuite::linalg::dense;
13using byte = proxsuite::linalg::veg::mem::byte;
14using StackType = proxsuite::linalg::veg::Vec<byte>;
15using StackReq = proxsuite::linalg::veg::dynstack::StackReq;
17template <
typename Mat,
typename Rhs>
void solve_impl(Mat &&ld_, Rhs &&rhs_) {
18 auto ld = dense_linalg::util::to_view(ld_);
19 auto rhs = dense_linalg::util::to_view_dyn_rows(rhs_);
20 using Scalar =
typename Mat::Scalar;
22 auto l = ld.template triangularView<Eigen::UnitLower>();
24 dense_linalg::util::trans(ld).template triangularView<Eigen::UnitUpper>();
25 auto d = dense_linalg::util::diagonal(ld);
27 constexpr Scalar eps = std::numeric_limits<Scalar>::min();
30 for (Eigen::Index i = 0; i < d.size(); ++i) {
31 if (abs(d[i]) > eps) {
63 auto req_mat = psldlt_t::solve_in_place_req(rhs_max_cols * nr);
65 StackReq req{psldlt_t::factorize_req(nr) | req_mat};
67 ldl_stack.resize_for_overwrite(req.alloc_req());
71 using veg::dynstack::DynStackMut;
73 DynStackMut stack{veg::from_slice_mut,
ldl_stack.as_mut()};
75 m_ldlt.factorize(mat, stack);
77 m_info = Eigen::ComputationInfo::Success;
81 template <
typename Derived>
83 using veg::dynstack::DynStackMut;
84 isize nrows = rhs.rows();
85 isize ncols = rhs.cols();
87 auto perm_inv =
m_ldlt.pt();
88 DynStackMut stack{veg::from_slice_mut,
89 const_cast<StackType &
>(
ldl_stack).as_mut()};
90 LDLT_TEMP_MAT_UNINIT(
Scalar, work, nrows, ncols, stack);
92 work = perm_inv * rhs;
94 solve_impl(
m_ldlt.ld_col(), work);
101 template <
typename Rhs>
102 typename Rhs::PlainObject
solve(
const Eigen::MatrixBase<Rhs> &rhs)
const {
103 typename Rhs::PlainObject out = rhs;
109 return dense_linalg::util::diagonal(
m_ldlt.ld_col());
118 r = D.asDiagonal() * r;
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
Use the LDLT from proxsuite.
Eigen::ComputationInfo m_info
Rhs::PlainObject solve(const Eigen::MatrixBase< Rhs > &rhs) const
dense_linalg::Ldlt< Scalar > psldlt_t
MatrixXs reconstructedMatrix() const
typename Base::DView DView
ProxSuiteLDLTWrapper & compute(const ConstMatrixRef &mat)
ProxSuiteLDLTWrapper(isize nr, isize rhs_max_cols)
bool solveInPlace(Eigen::MatrixBase< Derived > &rhs) const
Base interface for LDLT solvers.
Eigen::ComputationInfo m_info
Eigen::Map< const VectorXs, Eigen::Unaligned, Eigen::InnerStride< Eigen::Dynamic > > DView