numerics 0.1.0
Loading...
Searching...
No Matches
subspace.hpp
Go to the documentation of this file.
1/// @file kernel/subspace.hpp
2/// @brief Subspace construction and orthogonalization kernels.
3#pragma once
4
5#include "core/matrix.hpp"
6#include "core/types.hpp"
7#include "core/vector.hpp"
8#include <vector>
9
11
12/// @brief Modified Gram-Schmidt against basis[0..k-1].
13[[nodiscard]] real mgs_orthogonalize(const std::vector<Vector>& basis,
14 Vector& v,
15 std::vector<real>& h,
16 idx k);
17
18/// @brief Modified Gram-Schmidt against columns 0..k-1 of a row-major matrix.
19[[nodiscard]] real mgs_orthogonalize(const Matrix& basis, idx k, Vector& v);
20
21/// @brief One Arnoldi step: expand the orthonormal basis by one vector.
22template<class Op>
23 requires requires(const Op& A, const Vector& x, Vector& y) { A.apply(x, y); }
24[[nodiscard]] real arnoldi_step(const Op& A,
25 std::vector<Vector>& basis,
26 std::vector<real>& h,
27 idx k,
28 Vector& scratch,
29 real breakdown_tol = real(1e-14)) {
30 A.apply(basis[k], scratch);
31
32 const real beta = mgs_orthogonalize(basis, scratch, h, k + 1);
33 h[k + 1] = beta;
34
35 if (beta > breakdown_tol) {
36 scale(scratch, real(1) / beta);
37 basis.push_back(scratch);
38 }
39
40 return beta;
41}
42
43} // namespace num::kernel::subspace
Core type definitions.
Dense row-major matrix templated over scalar type T.
real arnoldi_step(const Op &A, std::vector< Vector > &basis, std::vector< real > &h, idx k, Vector &scratch, real breakdown_tol=real(1e-14))
One Arnoldi step: expand the orthonormal basis by one vector.
Definition subspace.hpp:24
real mgs_orthogonalize(const std::vector< Vector > &basis, Vector &v, std::vector< real > &h, idx k)
Modified Gram-Schmidt against basis[0..k-1].
Definition subspace.cpp:9
double real
Definition types.hpp:10
real beta(real a, real b)
B(a, b) – beta function.
Definition math.hpp:248
std::size_t idx
Definition types.hpp:11
void scale(Vector &v, real alpha, Backend b=default_backend)
Compute .
Definition vector.cpp:15
constexpr real e
Definition math.hpp:44
Dense vector storage and operations.