Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
ops/schur.hpp
Go to the documentation of this file.
1#pragma once
2
13
14#include <span>
15#include <utility>
16
17namespace uni20::linalg
18{
19
35template <class BackendSelector, uni20::MutableRankedTensorView<2> MatrixTensor, class EigenScalar,
36 uni20::MutableRankedTensorView<2> SchurVectorTensor>
37void schur(BackendSelector&& selector, MatrixTensor&& matrix_work, std::span<EigenScalar> eigenvalues,
38 SchurVectorTensor&& schur_vectors, bool compute_vectors)
39{
40 auto matrix_descriptor = uni20::mdspec_of(matrix_work);
41 auto vector_descriptor = uni20::mdspec_of(schur_vectors);
42 dispatch_kernel(std::forward<BackendSelector>(selector), schur_op{.compute_vectors = compute_vectors},
43 matrix_descriptor, eigenvalues, vector_descriptor);
44}
45
47template <uni20::MutableRankedTensorView<2> MatrixTensor, class EigenScalar,
48 uni20::MutableRankedTensorView<2> SchurVectorTensor>
49void schur(MatrixTensor&& matrix_work, std::span<EigenScalar> eigenvalues, SchurVectorTensor&& schur_vectors,
50 bool compute_vectors)
51{
52 auto operation = schur_op{.compute_vectors = compute_vectors};
53 auto selector = select_backend(operation, matrix_work, schur_vectors);
54 schur(selector, std::forward<MatrixTensor>(matrix_work), eigenvalues, std::forward<SchurVectorTensor>(schur_vectors),
55 compute_vectors);
56}
57
67template <class BackendSelector, uni20::MutableRankedTensorView<2> MatrixTensor, class EigenScalar,
68 uni20::MutableRankedTensorView<2> SchurVectorTensor>
69void hessenberg_schur(BackendSelector&& selector, MatrixTensor&& matrix_work, std::span<EigenScalar> eigenvalues,
70 SchurVectorTensor&& schur_vectors, bool compute_vectors)
71{
72 auto matrix_descriptor = uni20::mdspec_of(matrix_work);
73 auto vector_descriptor = uni20::mdspec_of(schur_vectors);
74 dispatch_kernel(std::forward<BackendSelector>(selector), hessenberg_schur_op{.compute_vectors = compute_vectors},
75 matrix_descriptor, eigenvalues, vector_descriptor);
76}
77
79template <uni20::MutableRankedTensorView<2> MatrixTensor, class EigenScalar,
80 uni20::MutableRankedTensorView<2> SchurVectorTensor>
81void hessenberg_schur(MatrixTensor&& matrix_work, std::span<EigenScalar> eigenvalues, SchurVectorTensor&& schur_vectors,
82 bool compute_vectors)
83{
84 auto operation = hessenberg_schur_op{.compute_vectors = compute_vectors};
85 auto selector = select_backend(operation, matrix_work, schur_vectors);
86 hessenberg_schur(selector, std::forward<MatrixTensor>(matrix_work), eigenvalues,
87 std::forward<SchurVectorTensor>(schur_vectors), compute_vectors);
88}
89
107template <class BackendSelector, uni20::MutableRankedTensorView<2> SchurFormTensor,
108 uni20::MutableRankedTensorView<2> SchurVectorTensor>
109void reorder_schur(BackendSelector&& selector, SchurFormTensor&& schur_form, SchurVectorTensor&& schur_vectors,
110 std::size_t from, std::size_t to, bool update_vectors)
111{
112 auto form_descriptor = uni20::mdspec_of(schur_form);
113 auto vector_descriptor = uni20::mdspec_of(schur_vectors);
114 dispatch_kernel(std::forward<BackendSelector>(selector),
115 schur_reorder_op{.from = from, .to = to, .update_vectors = update_vectors}, form_descriptor,
116 vector_descriptor);
117}
118
120template <uni20::MutableRankedTensorView<2> SchurFormTensor, uni20::MutableRankedTensorView<2> SchurVectorTensor>
121void reorder_schur(SchurFormTensor&& schur_form, SchurVectorTensor&& schur_vectors, std::size_t from, std::size_t to,
122 bool update_vectors)
123{
124 auto operation = schur_reorder_op{.from = from, .to = to, .update_vectors = update_vectors};
125 auto selector = select_backend(operation, schur_form, schur_vectors);
126 reorder_schur(selector, std::forward<SchurFormTensor>(schur_form), std::forward<SchurVectorTensor>(schur_vectors),
127 from, to, update_vectors);
128}
129
130} // namespace uni20::linalg
LAPACK backend for dense Schur decomposition and block reordering.
Operation-tag backend dispatch over tensor-view operands.
Definition linalg/async.hpp:28
void hessenberg_schur(BackendSelector &&selector, MatrixTensor &&matrix_work, std::span< EigenScalar > eigenvalues, SchurVectorTensor &&schur_vectors, bool compute_vectors)
Replace a real upper-Hessenberg matrix by its real Schur form.
Definition ops/schur.hpp:69
void reorder_schur(BackendSelector &&selector, SchurFormTensor &&schur_form, SchurVectorTensor &&schur_vectors, std::size_t from, std::size_t to, bool update_vectors)
Reorder a Schur form in place, optionally updating its Schur vectors.
Definition ops/schur.hpp:109
void schur(BackendSelector &&selector, MatrixTensor &&matrix_work, std::span< EigenScalar > eigenvalues, SchurVectorTensor &&schur_vectors, bool compute_vectors)
Replace a square matrix by its Schur form and optionally return Schur vectors.
Definition ops/schur.hpp:37
constexpr auto select_backend(Operation const &operation, FirstTensor const &, RestTensors const &...)
Select the default backend list for an operation on Tensor operands.
Definition backend_selector.hpp:252
void dispatch_kernel(BackendSelector &&selector, Op op, Args &&... args)
Normalize a selector and dispatch or report that every eligible backend declined.
Definition dispatch.hpp:374
constexpr decltype(auto) mdspec_of(Tensor &tensor) noexcept(noexcept(tensor.mdspec()))
Return a tensor's immediate or descriptor-backed multidimensional metadata.
Definition tensor/concepts.hpp:50
Backend-independent operation values used with normalized kernel operands.
Schur decomposition of an already upper-Hessenberg real matrix.
Definition operation_tags.hpp:322
bool compute_vectors
Definition operation_tags.hpp:324
Dense Schur decomposition operation tag.
Definition operation_tags.hpp:315
bool compute_vectors
Definition operation_tags.hpp:317
Move one Schur block or entry to a requested position.
Definition operation_tags.hpp:329
std::size_t from
Definition operation_tags.hpp:331
Concepts for tensor-level objects that resolve mdspan kernel operands.