numerics 0.1.0
Loading...
Searching...
No Matches
subspace.cpp
Go to the documentation of this file.
1/// @file kernel/subspace.cpp
2/// @brief Implementations for num::kernel::subspace.
3
4#include "kernel/subspace.hpp"
5#include <stdexcept>
6
7namespace num::kernel::subspace {
8
9real mgs_orthogonalize(const std::vector<Vector>& basis,
10 Vector& v,
11 std::vector<real>& h,
12 idx k) {
13 for (idx i = 0; i < k; ++i) {
14 h[i] = dot(v, basis[i]);
15 axpy(-h[i], basis[i], v);
16 }
17 return norm(v);
18}
19
20real mgs_orthogonalize(const Matrix& basis, idx k, Vector& v) {
21 const idx n = basis.rows();
22
23 for (idx l = 0; l < k; ++l) {
24 real proj = 0.0;
25 for (idx i = 0; i < n; ++i) {
26 proj += basis(i, l) * v[i];
27 }
28 for (idx i = 0; i < n; ++i) {
29 v[i] -= proj * basis(i, l);
30 }
31 }
32 return norm(v);
33}
34
35} // namespace num::kernel::subspace
constexpr idx rows() const noexcept
Definition matrix.hpp:87
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
std::size_t idx
Definition types.hpp:11
real dot(const Vector &x, const Vector &y, Backend b=default_backend)
Compute .
Definition vector.cpp:65
real norm(const Vector &x, Backend b=default_backend)
Compute .
Definition vector.cpp:83
void axpy(real alpha, const Vector &x, Vector &y, Backend b=default_backend)
Compute .
Definition vector.cpp:44
Subspace construction and orthogonalization kernels.