batmat 0.0.13
Batched linear algebra routines
Loading...
Searching...
No Matches
potrf.hpp
Go to the documentation of this file.
1#pragma once
2
10#include <batmat/loop.hpp>
12#include <guanaqo/trace.hpp>
13
14namespace batmat::linalg {
15
16namespace detail {
17template <class T, class Abi, micro_kernels::potrf::KernelConfig Conf, StorageOrder OA,
18 StorageOrder OCD>
19 requires(Conf.struc_C != MatrixStructure::General)
21 T regularization) {
22 // Check dimensions
23 BATMAT_ASSERT(D.rows() >= D.cols());
24 BATMAT_ASSERT(A.cols() == 0 || A.rows() == D.rows());
25 BATMAT_ASSERT(C.rows() == D.rows());
26 BATMAT_ASSERT(C.cols() == D.cols());
27 const index_t M = D.rows(), N = D.cols();
28 GUANAQO_TRACE_LINALG("potrf", total(flops::syrk_potrf(M, N, A.cols())) * C.depth());
29 // Degenerate case
30 if (M == 0 || N == 0) [[unlikely]]
31 return;
32 return micro_kernels::potrf::potrf_copy_register<T, Abi, Conf>(A, C, D, regularization);
33}
34} // namespace detail
35
36/// @addtogroup topic-linalg
37/// @{
38
39/// @name Cholesky factorization of batches of matrices
40/// @{
41
42/// D = chol(C + AAᵀ) with C symmetric, D triangular
43template <MatrixStructure SC, simdifiable VA, simdifiable VC, simdifiable VD>
46 simdified_value_t<VA> regularization = 0) {
47 detail::potrf<simdified_value_t<VA>, simdified_abi_t<VA>, {.negate_A = false, .struc_C = SC}>(
48 simdify(A).as_const(), simdify(C.value).as_const(), simdify(D.value), regularization);
49}
50/// D = chol(D + AAᵀ) with D symmetric/triangular
51template <MatrixStructure SC, simdifiable VA, simdifiable VD>
54 syrk_add_potrf(A, D.ref(), D.ref());
55}
56
57/// D = chol(C - AAᵀ) with C symmetric, D triangular
58template <MatrixStructure SC, simdifiable VA, simdifiable VC, simdifiable VD>
61 simdified_value_t<VA> regularization = 0) {
62 detail::potrf<simdified_value_t<VA>, simdified_abi_t<VA>, {.negate_A = true, .struc_C = SC}>(
63 simdify(A).as_const(), simdify(C.value).as_const(), simdify(D.value), regularization);
64}
65/// D = chol(D - AAᵀ) with D symmetric/triangular
66template <MatrixStructure SC, simdifiable VA, simdifiable VD>
68void syrk_sub_potrf(VA &&A, Structured<VD, SC> D, simdified_value_t<VA> regularization = 0) {
69 syrk_sub_potrf(A, D.ref(), D.ref(), regularization);
70}
71
72/// D = chol(C) with C symmetric, D triangular
73template <MatrixStructure SC, simdifiable VC, simdifiable VD>
76 decltype(simdify(C.value).as_const()) null{{.data = nullptr, .rows = 0, .cols = 0}};
78 null, simdify(C.value).as_const(), simdify(D.value), regularization);
79}
80
81/// D = chol(D) with D symmetric/triangular
82template <MatrixStructure SD, simdifiable VD>
83void potrf(Structured<VD, SD> D, simdified_value_t<VD> regularization = 0) {
84 decltype(simdify(D.value).as_const()) null{{.data = nullptr, .rows = 0, .cols = 0}};
86 null, simdify(D.value).as_const(), simdify(D.value), regularization);
87}
88
89/// @}
90
91/// @}
92
93} // namespace batmat::linalg
#define BATMAT_ASSERT(x)
Definition assume.hpp:14
constexpr FlopCount syrk_potrf(index_t m, index_t n, index_t k)
Fused symmetric rank-k update and Cholesky factorization of an m×n matrix with m≥n.
Definition flops.hpp:182
void syrk_add_potrf(VA &&A, Structured< VC, SC > C, Structured< VD, SC > D, simdified_value_t< VA > regularization=0)
D = chol(C + AAᵀ) with C symmetric, D triangular.
Definition potrf.hpp:45
void syrk_sub_potrf(VA &&A, Structured< VC, SC > C, Structured< VD, SC > D, simdified_value_t< VA > regularization=0)
D = chol(C - AAᵀ) with C symmetric, D triangular.
Definition potrf.hpp:60
void potrf(Structured< VC, SC > C, Structured< VD, SC > D, simdified_value_t< VC > regularization=0)
D = chol(C) with C symmetric, D triangular.
Definition potrf.hpp:75
#define GUANAQO_TRACE_LINALG(name, gflops)
void potrf(view< const T, Abi, OA > A, view< const T, Abi, OCD > C, view< T, Abi, OCD > D, T regularization)
Definition potrf.hpp:20
void potrf_copy_register(view< const T, Abi, OA > A, view< const T, Abi, OCD > C, view< T, Abi, OCD > D, T regularization) noexcept
Definition potrf.tpp:185
typename detail::simdified_value< V >::type simdified_value_t
Definition simdify.hpp:202
typename detail::simdified_abi< V >::type simdified_abi_t
Definition simdify.hpp:204
constexpr bool simdify_compatible
Definition simdify.hpp:207
constexpr auto simdify(simdifiable auto &&a) -> simdified_view_t< decltype(a)>
Definition simdify.hpp:214
simd_view_types< std::remove_const_t< T >, Abi >::template view< T, Order > view
Definition uview.hpp:70
Aligned allocation for matrix storage.
Light-weight wrapper class used for overload resolution of triangular and symmetric matrices.