5#ifndef PROXSUITE_LINALG_DENSE_LDLT_FACTORIZE_HPP
6#define PROXSUITE_LINALG_DENSE_LDLT_FACTORIZE_HPP
20 isize* perm_inv_indices,
22 T
const* diagonal_data,
25 for (isize k = 0; k < n; ++k) {
30 std::sort(perm_indices,
32 [diagonal_data, stride](isize i, isize j)
noexcept ->
bool {
34 auto lhs = fabs(diagonal_data[stride * i]);
35 auto rhs = fabs(diagonal_data[stride * j]);
43 for (isize k = 0; k < n; ++k) {
44 perm_inv_indices[perm_indices[k]] = k;
48template<
typename Diag>
51 isize* perm_inv_indices,
54 _detail::compute_permutation_impl<typename Diag::Scalar>(
59 diagonal.innerStride());
62template<
typename Mat,
typename Work>
66 using T =
typename proxsuite::linalg::veg::uncvref_t<Mat>::Scalar;
75 auto mat_coeff = [&](isize i, isize j)
noexcept -> T& {
76 return i >= j ? mat(i, j) : mat(j, i);
79 for (isize j = 0; j < n; ++j) {
80 for (isize i = j; i < n; ++i) {
81 work(i, j) = mat_coeff(perm_indices[i], perm_indices[j]);
85 mat.template triangularView<Eigen::Lower>() =
86 work.template triangularView<Eigen::Lower>();
97 using T =
typename Mat::Scalar;
103 auto _work = stack.make_new_for_overwrite(
106 _detail::align<T>());
108 Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1>, Eigen::Unaligned>{
133 mat(j, j) -= work.dot(l10);
139 isize rem = n - j - 1;
145 l21 *= 1 / mat(j, j);
150template<
typename Mat>
158 using T =
typename Mat::Scalar;
161 isize n = mat.rows();
169 isize bs = min2(n - j, block_size);
178 isize rem = n - j - bs;
180 isize work_stride = _detail::adjusted_stride<T>(rem);
182 auto _work = stack.make_new_for_overwrite(
185 _detail::align<T>());
187 auto work = Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>,
189 Eigen::OuterStride<Eigen::Dynamic>>{
193 Eigen::OuterStride<Eigen::Dynamic>{ work_stride },
199 .template triangularView<Eigen::UnitUpper>()
200 .template solveInPlace<Eigen::OnTheRight>(l21);
203 l21 = l21 * d1.asDiagonal().inverse();
207 l22.template triangularView<Eigen::Lower>() -= l21 *
util::trans(work);
215template<
typename Mat>
222 using T =
typename Mat::Scalar;
225 isize n = mat.rows();
241 isize bs = (n + 1) / 2;
252 isize work_stride = _detail::adjusted_stride<T>(rem);
255 .template triangularView<Eigen::UnitUpper>()
256 .template solveInPlace<Eigen::OnTheRight>(l10);
259 auto _work = stack.make_new_for_overwrite(
262 _detail::align<T>());
264 auto work = Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>,
266 Eigen::OuterStride<Eigen::Dynamic>>{
270 Eigen::OuterStride<Eigen::Dynamic>{ work_stride },
273 l10 = l10 * d0.asDiagonal().inverse();
275 l11.template triangularView<Eigen::Lower>() -= l10 *
util::trans(work);
289 n * isize{
sizeof(T) },
298 isize block_size)
noexcept
303 _detail::adjusted_stride<T>(
304 _detail::max2(n - block_size, isize(0))) *
305 block_size * isize{
sizeof(T) },
320 isize bs = (n + 1) / 2;
323 bs * _detail::adjusted_stride<T>(rem) * isize{
sizeof(T) },
328template<
typename Mat>
335template<
typename Mat>
343template<
typename Mat>
360template<
typename Mat>
364 isize n = mat.rows();
#define VEG_ASSERT_ALL_OF(...)
void apply_permutation_tri_lower(Mat &&mat, Work &&work, isize const *perm_indices)
VEG_NO_INLINE void compute_permutation(isize *perm_indices, isize *perm_inv_indices, Diag const &diagonal)
void factorize_unblocked_impl(Mat mat, proxsuite::linalg::veg::dynstack::DynStackMut stack)
void factorize_blocked_impl(Mat mat, isize block_size, proxsuite::linalg::veg::dynstack::DynStackMut stack)
VEG_NO_INLINE void compute_permutation_impl(isize *perm_indices, isize *perm_inv_indices, isize n, T const *diagonal_data, isize stride)
void factorize_recursive_impl(Mat mat, proxsuite::linalg::veg::dynstack::DynStackMut stack)
auto trans(Mat &&mat) noexcept -> Eigen::Map< _detail::const_if< _detail::ptr_is_const< decltype(mat.data())>::value, Eigen::Matrix< typename proxsuite::linalg::veg::uncvref_t< Mat >::Scalar, proxsuite::linalg::veg::uncvref_t< Mat >::ColsAtCompileTime, proxsuite::linalg::veg::uncvref_t< Mat >::RowsAtCompileTime, bool(proxsuite::linalg::veg::uncvref_t< Mat >::IsRowMajor) ? Eigen::ColMajor :Eigen::RowMajor > >, Eigen::Unaligned, _detail::StrideOf< proxsuite::linalg::veg::uncvref_t< Mat > > >
void noalias_mul_add(Dst &&dst, Lhs const &lhs, Rhs const &rhs, T factor)
auto subcols(Mat &&mat, isize col_start, isize ncols) noexcept -> Eigen::Map< _detail::const_if< _detail::ptr_is_const< decltype(mat.data())>::value, _detail::OwnedCols< proxsuite::linalg::veg::uncvref_t< Mat > > >, Eigen::Unaligned, _detail::StrideOf< proxsuite::linalg::veg::uncvref_t< Mat > > >
auto diagonal(Mat &&mat) noexcept -> Eigen::Map< _detail::const_if< _detail::ptr_is_const< decltype(mat.data())>::value, Eigen::Matrix< typename proxsuite::linalg::veg::uncvref_t< Mat >::Scalar, Eigen::Dynamic, 1, Eigen::ColMajor > >, Eigen::Unaligned, Eigen::InnerStride< Eigen::Dynamic > >
auto row(T &&mat, isize row_idx) noexcept -> typename _detail::RowColAccessImpl< !bool(proxsuite::linalg::veg::uncvref_t< T >::IsRowMajor)>::template Row< T >
auto subrows(Mat &&mat, isize row_start, isize nrows) noexcept -> Eigen::Map< _detail::const_if< _detail::ptr_is_const< decltype(mat.data())>::value, _detail::OwnedRows< proxsuite::linalg::veg::uncvref_t< Mat > > >, Eigen::Unaligned, _detail::StrideOf< proxsuite::linalg::veg::uncvref_t< Mat > > >
auto submatrix(Mat &&mat, isize row_start, isize col_start, isize nrows, isize ncols) noexcept -> Eigen::Map< _detail::const_if< _detail::ptr_is_const< decltype(mat.data())>::value, _detail::OwnedMatrix< proxsuite::linalg::veg::uncvref_t< Mat > > >, Eigen::Unaligned, _detail::StrideOf< proxsuite::linalg::veg::uncvref_t< Mat > > >
auto to_view_dyn(Mat &&mat) noexcept -> Eigen::Map< _detail::const_if< _detail::ptr_is_const< decltype(mat.data())>::value, _detail::OwnedMatrix< proxsuite::linalg::veg::uncvref_t< Mat > > >, Eigen::Unaligned, _detail::StrideOf< proxsuite::linalg::veg::uncvref_t< Mat > > >
auto col(T &&mat, isize col_idx) noexcept -> typename _detail::RowColAccessImpl< !bool(proxsuite::linalg::veg::uncvref_t< T >::IsRowMajor)>::template Col< T >
auto factorize_recursive_req(proxsuite::linalg::veg::Tag< T > tag, isize n) noexcept -> proxsuite::linalg::veg::dynstack::StackReq
auto factorize_blocked_req(proxsuite::linalg::veg::Tag< T > tag, isize n, isize block_size) noexcept -> proxsuite::linalg::veg::dynstack::StackReq
auto factorize_unblocked_req(proxsuite::linalg::veg::Tag< T >, isize n) noexcept -> proxsuite::linalg::veg::dynstack::StackReq
void factorize_blocked(Mat &&mat, isize block_size, proxsuite::linalg::veg::dynstack::DynStackMut stack)
void factorize(Mat &&mat, proxsuite::linalg::veg::dynstack::DynStackMut stack)
void factorize_unblocked(Mat &&mat, proxsuite::linalg::veg::dynstack::DynStackMut stack)
void factorize_recursive(Mat &&mat, proxsuite::linalg::veg::dynstack::DynStackMut stack)
auto factorize_req(proxsuite::linalg::veg::Tag< T > tag, isize n) noexcept -> proxsuite::linalg::veg::dynstack::StackReq
VEG_NODISCARD auto ptr_mut() const VEG_NOEXCEPT -> void *