20namespace packed_detail
25template <
class V,
class A>
27 std::same_as<typename V::value_type, make_real_t<typename A::value_type>>;
28template <
class A,
class B>
32template <
class A>
void require_matrix(A
const& a, std::size_t rows, std::size_t cols)
46 PANIC(
"invalid SVD extent");
52 using S =
typename A::value_type;
53 std::size_t m = a.extent(0), n = a.extent(1), k = std::min(m, n);
55 auto work = pack(a,
p);
58 std::vector<make_real_t<typename A::value_type>> w(k);
61 for (std::size_t i = 0; i < k; ++i)
63 return std::pair(std::move(u), std::move(vh));
68template <packed_detail::DecompositionMatrix A,
class X,
class Y,
class... P>
69 requires packed_detail::SameMatrixScalar<A, X> && packed_detail::SameMatrixScalar<A, Y> &&
70 packed_detail::QrScalar<typename A::value_type> &&
71 packed_detail::KernelPrecision<
typename A::value_type, P...>
78template <packed_detail::DecompositionMatrix A,
class X,
class Y,
class... P>
79 requires packed_detail::SameMatrixScalar<A, X> && packed_detail::SameMatrixScalar<A, Y> &&
80 packed_detail::QrScalar<typename A::value_type> &&
81 packed_detail::KernelPrecision<
typename A::value_type, P...>
84 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
87 [&](
auto& xs,
auto& ys,
auto& as) {
88 std::size_t m = as.extent(0), n = as.extent(1), k = std::min(m, n);
104template <packed_detail::DecompositionMatrix A,
class X,
class Y,
class... P>
105 requires packed_detail::SameMatrixScalar<A, X> && packed_detail::SameMatrixScalar<A, Y> &&
106 packed_detail::LqScalar<typename A::value_type> &&
107 packed_detail::KernelPrecision<
typename A::value_type, P...>
114template <packed_detail::DecompositionMatrix A,
class X,
class Y,
class... P>
115 requires packed_detail::SameMatrixScalar<A, X> && packed_detail::SameMatrixScalar<A, Y> &&
116 packed_detail::LqScalar<typename A::value_type> &&
117 packed_detail::KernelPrecision<
typename A::value_type, P...>
120 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
123 [&](
auto& xs,
auto& ys,
auto& as) {
124 std::size_t m = as.extent(0), n = as.extent(1), k = std::min(m, n);
140template <
class V, packed_detail::DecompositionMatrix A,
class... P>
141 requires packed_detail::EighScalar<typename A::value_type> &&
142 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
149template <
class V, packed_detail::DecompositionMatrix A,
class... P>
150 requires packed_detail::EighScalar<typename A::value_type> &&
151 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
154 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
157 [&](
auto& vs,
auto& as) {
158 std::size_t n = as.extent(0);
162 using S =
typename A::value_type;
164 for (std::size_t j = 0; j < n; ++j)
165 for (std::size_t i = 0; i < n; ++i)
167 work[i, j] = scalar_at_precision<S>(S(as[i, j]),
p);
168 std::vector<make_real_t<typename A::value_type>> w(n);
172 for (std::size_t i = 0; i < n; ++i)
180template <packed_detail::DecompositionMatrix A, packed_detail::DecompositionMatrix R,
class... P>
181 requires std::same_as<typename R::value_type, complex<make_real_t<typename A::value_type>>> &&
182 packed_detail::EigenScalar<typename A::value_type> &&
183 packed_detail::KernelPrecision<
typename A::value_type, P...>
191template <packed_detail::DecompositionMatrix A, packed_detail::DecompositionMatrix R,
class... P>
192 requires std::same_as<typename R::value_type, complex<make_real_t<typename A::value_type>>> &&
193 packed_detail::EigenScalar<typename A::value_type> &&
194 packed_detail::KernelPrecision<
typename A::value_type, P...>
196 R& r, P... precision)
198 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
201 [&](
auto& as,
auto& rs) {
202 std::size_t n = as.extent(0);
217template <
class V, packed_detail::DecompositionMatrix A,
class... P>
218 requires packed_detail::SvdScalar<typename A::value_type> &&
219 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
226template <
class V, packed_detail::DecompositionMatrix A,
class... P>
227 requires packed_detail::SvdScalar<typename A::value_type> &&
228 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
231 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
233 [&](
auto& vs,
auto& as) {
243template <
class V, packed_detail::DecompositionMatrix A,
class... P>
244 requires packed_detail::SvdScalar<typename A::value_type> &&
245 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
252template <
class V, packed_detail::DecompositionMatrix A,
class... P>
253 requires packed_detail::SvdScalar<typename A::value_type> &&
254 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
257 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
259 [&](
auto& vs,
auto& as) {
269template <
class V, packed_detail::DecompositionMatrix A,
class... P>
270 requires packed_detail::SvdScalar<typename A::value_type> &&
271 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
278template <
class V, packed_detail::DecompositionMatrix A,
class... P>
279 requires packed_detail::SvdScalar<typename A::value_type> &&
280 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
283 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
285 [&](
auto& vs,
auto& as) {
295template <
class V, packed_detail::DecompositionMatrix A,
class L,
class... P>
296 requires packed_detail::SameMatrixScalar<A, L> && packed_detail::SvdScalar<typename A::value_type> &&
297 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
304template <
class V, packed_detail::DecompositionMatrix A,
class L,
class... P>
305 requires packed_detail::SameMatrixScalar<A, L> && packed_detail::SvdScalar<typename A::value_type> &&
306 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
309 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
311 [&](
auto& vs,
auto& ls,
auto& as) {
312 std::size_t m = as.extent(0), n = as.extent(1), k = std::min(m, n);
323template <
class V, packed_detail::DecompositionMatrix A,
class R,
class... P>
324 requires packed_detail::SameMatrixScalar<A, R> && packed_detail::SvdScalar<typename A::value_type> &&
325 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
332template <
class V, packed_detail::DecompositionMatrix A,
class R,
class... P>
333 requires packed_detail::SameMatrixScalar<A, R> && packed_detail::SvdScalar<typename A::value_type> &&
334 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
337 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
339 [&](
auto& vs,
auto& rs,
auto& as) {
340 std::size_t m = as.extent(0), n = as.extent(1), k = std::min(m, n);
351template <
class V, packed_detail::DecompositionMatrix A,
class L,
class R,
class... P>
352 requires packed_detail::SameMatrixScalar<A, L> && packed_detail::SameMatrixScalar<A, R> &&
353 packed_detail::SvdScalar<typename A::value_type> &&
354 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
361template <
class V, packed_detail::DecompositionMatrix A,
class L,
class R,
class... P>
362 requires packed_detail::SameMatrixScalar<A, L> && packed_detail::SameMatrixScalar<A, R> &&
363 packed_detail::SvdScalar<typename A::value_type> &&
364 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
367 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
369 [&](
auto& vs,
auto& ls,
auto& rs,
auto& as) {
370 std::size_t m = as.extent(0), n = as.extent(1), k = std::min(m, n);
384template <
class V, packed_detail::DecompositionMatrix A,
class F,
class... P>
385 requires packed_detail::SameMatrixScalar<A, F> && packed_detail::SvdScalar<typename A::value_type> &&
386 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
393template <
class V, packed_detail::DecompositionMatrix A,
class F,
class... P>
394 requires packed_detail::SameMatrixScalar<A, F> && packed_detail::SvdScalar<typename A::value_type> &&
395 packed_detail::KernelPrecision<
typename A::value_type, P...> && packed_detail::DecompositionValues<V, A>
398 auto const p = packed_detail::working_precision<typename A::value_type>(precision...);
400 [&](
auto& vs,
auto& fs,
auto& as) {
401 std::size_t m = as.extent(0), n = as.extent(1), k = std::min(m, n);
Exact arithmetic or an explicit binary working precision.
Definition core/precision.hpp:13
General-purpose owning tensor with immediate or deferred mdspan metadata.
Definition basic_tensor.hpp:109
Mutable mdspec metadata supporting host write acquisition.
Definition access.hpp:694
Mutable mdspec-like type with a specified static rank.
Definition mdspan/concepts.hpp:487
Concept for types that are either real or complex.
Definition scalar_concepts.hpp:87
Definition decompositions_packed.hpp:23
Definition decompositions_packed.hpp:26
Definition decompositions_packed.hpp:29
Shared helpers for LAPACK operation-tag backend adapters.
KernelAttempt with_host_write_mdspans(Function &&function, Mdspecs &... mdspecs)
Invoke a LAPACK attempt with host-writable mdspans under simultaneous leases.
Definition linalg/backends/lapack/common.hpp:29
char vector_job(SvdVectorExtent extent)
Definition decompositions_packed.hpp:37
void require_matrix(A const &a, std::size_t rows, std::size_t cols)
Definition decompositions_packed.hpp:32
void unpack(Tensor const &source, Span &target)
Definition packed_matrix.hpp:33
auto compute_svd(V &v, A &a, char jobu, char jobvt, Precision p)
Definition decompositions_packed.hpp:49
auto pack(Span const &span, Precision p, bool read=true)
Definition packed_matrix.hpp:19
auto values(Tensor &tensor)
Definition packed_matrix.hpp:29
Definition linalg/async.hpp:28
KernelAttempt try_kernel(BlasBackend, gemm_op const &, C &c, S const &alpha, A &a, B &b, S const &beta)
Pack logical host values and execute GEMM through value-preserving provider conversion.
Definition linalg/backends/blas/binary80.hpp:30
KernelAttempt
Result of one runtime kernel backend attempt.
Definition kernel_attempt.hpp:27
SvdVectorExtent
Extent policy for one side of an exact singular value decomposition.
Definition operation_tags.hpp:248
consteval auto kernel_accepts_types(BlasBackend, gemm_op const &, C &, S const &, A &, B &, S const &)
Accept host-readable native binary80 operands, including transforming accessors.
Definition linalg/backends/blas/binary80.hpp:19
constexpr KernelAcceptance< KernelTypeAcceptance::yes > kernel_types_yes
Report that a backend accepts every instance of the argument types.
Definition dispatch_error.hpp:40
void eigen(std::size_t n, std::span< float80 > a, std::span< complex160 > values, std::span< complex160 > vectors, bool compute_vectors, Precision p)
Compute unsorted complex eigenvalues and optional right eigenvectors, destroying a.
Definition binary80.cpp:248
void lq(std::size_t m, std::size_t n, std::span< float80 > a, std::span< float80 > q, std::span< float80 > triangular, Precision p)
Overwrite m-by-n input work and return Q (k-by-n) and L (m-by-k), k=min(m,n).
Definition binary80.cpp:231
void eigh(std::size_t n, std::span< float80 > a, std::span< float80 > values, bool vectors, char triangle, Precision p)
Compute ascending eigenvalues and optionally overwrite a with eigenvector columns.
Definition binary80.cpp:237
void svd(std::size_t m, std::size_t n, std::span< float80 > a, std::span< float80 > values, std::span< float80 > u, std::span< float80 > vh, char jobu, char jobvt, Precision p)
Compute descending singular values and requested U/Vh factors, destroying a.
Definition binary80.cpp:242
void qr(std::size_t m, std::size_t n, std::span< float80 > a, std::span< float80 > q, std::span< float80 > triangular, Precision p)
Overwrite m-by-n input work and return Q (m-by-k) and R (k-by-n), k=min(m,n).
Definition binary80.cpp:225
Definition data_table.cpp:8
constexpr uninitialized_t uninitialized
Explicit allocation tag for overwrite outputs and scratch space.
Definition common/initialization.hpp:22
Per-operation eligibility for compiled value-converting provider adapters.
Logical host packing for value-converting BLAS and LAPACK adapters.
Backend family for configured dense LAPACK kernels, including MPLAPACK scalar adapters.
Definition backend_selector.hpp:20
Reduced dense real LQ factorization operation tag.
Definition operation_tags.hpp:187
Dense nonsymmetric eigensystem operation tag.
Definition operation_tags.hpp:308
bool compute_right_vectors
Definition operation_tags.hpp:310
Reduced dense real QR factorization operation tag.
Definition operation_tags.hpp:179
Dense symmetric or Hermitian eigensystem operation tag.
Definition operation_tags.hpp:240
bool compute_vectors
Definition operation_tags.hpp:242
MatrixTriangle triangle
Definition operation_tags.hpp:243
Exact dense singular-values-only operation tag.
Definition operation_tags.hpp:270
Exact dense left singular-vector operation tag.
Definition operation_tags.hpp:276
SvdVectorExtent left
Definition operation_tags.hpp:278
bool overwrite_input
Definition operation_tags.hpp:279
Exact dense singular value decomposition operation tag.
Definition operation_tags.hpp:292
SvdVectorExtent left
Definition operation_tags.hpp:294
SvdVectorExtent right
Definition operation_tags.hpp:295
SvdOverwrite overwrite
Definition operation_tags.hpp:296
Exact dense right singular-vector operation tag.
Definition operation_tags.hpp:284
SvdVectorExtent right
Definition operation_tags.hpp:286
bool overwrite_input
Definition operation_tags.hpp:287
#define CHECK(cond,...)
Definition trace.hpp:299
#define PANIC(...)
Definition trace.hpp:382
#define CHECK_EQUAL(a, b,...)
Definition trace.hpp:309