batmat 0.0.24
Batched linear algebra routines
Loading...
Searching...
No Matches
sterf.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <batmat/assume.hpp>
9
10#include <expected>
11
12namespace batmat::linalg {
13
14using batmat::linalg::micro_kernels::sterf::SterfOptions;
15
16namespace detail {
17
18template <class T, class Abi>
19std::expected<index_t, index_t> sterf(view<T, Abi, StorageOrder::ColMajor> diag,
21 SterfOptions options) {
22 static_assert(!std::is_const_v<T>);
23 BATMAT_ASSERT(diag.cols() == 1);
24 BATMAT_ASSERT(subdiag.cols() == 1);
25 const index_t n = diag.rows();
26 if (n > 0)
27 BATMAT_ASSERT(subdiag.rows() == n - 1);
28 else
29 BATMAT_ASSERT(subdiag.rows() == 0);
30 if (n <= 1)
31 return 0;
32 return micro_kernels::sterf::sterf<T, Abi>(diag, subdiag, options);
33}
34
35} // namespace detail
36
37/// Eigenvalues of a symmetric tridiagonal matrix given by `diag` and `subdiag`, computed in-place
38/// using the Pal-Walker-Kahan variant of the implicit QR/QL method with Wilkinson shifts.
39/// @return Number of QR steps taken. An unexpected value signals failure to converge within the
40/// maximum number of iterations specified in `options`.
41template <simdifiable Vd, simdifiable Vs>
43std::expected<index_t, index_t> sterf(Vd &&diag, Vs &&subdiag, SterfOptions options = {}) {
44 static_assert(decltype(simdify(diag))::storage_order == StorageOrder::ColMajor);
45 static_assert(decltype(simdify(subdiag))::storage_order == StorageOrder::ColMajor);
47 simdify(subdiag), options);
48}
49
50/// Extracts the diagonal and one off-diagonal from a matrix. Pass a triangular view to specify
51/// which off-diagonal to extract.
52template <simdifiable VA, simdifiable Vd, simdifiable Vs, MatrixStructure SA>
54void extract_bidiag(Structured<VA, SA> A, Vd &&diag, Vs &&offdiag) {
55 BATMAT_ASSERT(rows(A.value) == cols(A.value));
56 BATMAT_ASSERT(rows(A.value) == rows(diag));
57 BATMAT_ASSERT(cols(diag) == 1);
58 copy_diag(A.value, diag);
59 if (const index_t n = rows(A.value); n > 1) {
60 BATMAT_ASSERT(rows(offdiag) == n - 1);
61 BATMAT_ASSERT(cols(offdiag) == 1);
62 if constexpr (SA == MatrixStructure::UpperTriangular)
63 copy_diag(A.value.top_right(n - 1, n - 1), offdiag);
64 else
65 copy_diag(A.value.bottom_left(n - 1, n - 1), offdiag);
66 }
67}
68
69} // namespace batmat::linalg
#define BATMAT_ASSERT(x)
Definition assume.hpp:14
void copy_diag(VA &&A, VB &&B)
Copy the diagonal elements of a matrix.
std::expected< index_t, index_t > sterf(view< T, Abi, StorageOrder::ColMajor > diag, view< T, Abi, StorageOrder::ColMajor > subdiag, SterfOptions options)
Definition sterf.hpp:19
std::expected< index_t, index_t > sterf(view< T, Abi, StorageOrder::ColMajor > diag, view< T, Abi, StorageOrder::ColMajor > subdiag, SterfOptions options) noexcept
Eigenvalues of a symmetric tridiagonal matrix given by diag and subdiag, computed in-place using the ...
Definition sterf.tpp:227
typename detail::simdified_abi< V >::type simdified_abi_t
Definition simdify.hpp:216
constexpr bool simdify_compatible
Definition simdify.hpp:221
constexpr auto simdify(simdifiable auto &&a) -> simdified_view_t< decltype(a)>
Definition simdify.hpp:228
std::expected< index_t, index_t > sterf(Vd &&diag, Vs &&subdiag, SterfOptions options={})
Eigenvalues of a symmetric tridiagonal matrix given by diag and subdiag, computed in-place using the ...
Definition sterf.hpp:43
simd_view_types< std::remove_const_t< T >, Abi >::template view< T, Order > view
Definition uview.hpp:70
void extract_bidiag(Structured< VA, SA > A, Vd &&diag, Vs &&offdiag)
Extracts the diagonal and one off-diagonal from a matrix.
Definition sterf.hpp:54
int index_t
Definition config.hpp:13
Light-weight wrapper class used for overload resolution of triangular and symmetric matrices.