numerics 0.1.0
Loading...
Searching...
No Matches
dense.cpp
Go to the documentation of this file.
1/// @file kernel/dense.cpp
2/// @brief Implementations for num::kernel::dense (seq_t, par_t, and no-policy
3/// ops).
4
5#include "kernel/dense.hpp"
6#include "kernel/raw.hpp"
7#include <stdexcept>
8
9namespace num::kernel::dense {
10
11void ger(real alpha, const Vector& x, const Vector& y, Matrix& A, seq_t) noexcept {
12 raw::ger(A.data(), x.data(), y.data(), alpha, x.size(), y.size());
13}
14
15void ger(real alpha, const Vector& x, const Vector& y, Matrix& A, par_t) {
16#ifdef NUMERICS_HAS_OMP
17 const idx m = x.size();
18 const idx n = y.size();
19 const real* xd = x.data();
20 const real* yd = y.data();
21 real* Ad = A.data();
22 #pragma omp parallel for schedule(static)
23 for (idx i = 0; i < m; ++i) {
24 const real axi = alpha * xd[i];
25 real* row = Ad + (i * n);
26 for (idx j = 0; j < n; ++j) {
27 row[j] += axi * yd[j];
28 }
29 }
30#else
31 ger(alpha, x, y, A, seq_t{});
32#endif
33}
34
35void trsv_lower(const Matrix& L, const Vector& b, Vector& x) {
36 const idx n = L.rows();
37 if (L.cols() != n || b.size() != n) {
38 throw std::invalid_argument("kernel::dense::trsv_lower: dimension mismatch");
39 }
40 if (x.size() != n) {
41 x = Vector(n);
42 }
43 raw::trsv_lower(x.data(), L.data(), b.data(), n);
44}
45
46void trsv_upper(const Matrix& U, const Vector& b, Vector& x) {
47 const idx n = U.rows();
48 if (U.cols() != n || b.size() != n) {
49 throw std::invalid_argument("kernel::dense::trsv_upper: dimension mismatch");
50 }
51 if (x.size() != n) {
52 x = Vector(n);
53 }
54 raw::trsv_upper(x.data(), U.data(), b.data(), n);
55}
56
57} // namespace num::kernel::dense
constexpr idx rows() const noexcept
Definition matrix.hpp:87
constexpr idx cols() const noexcept
Definition matrix.hpp:88
constexpr idx size() const noexcept
Definition vector.hpp:83
Dense matrix inner kernels (namespace num::kernel::dense)
void trsv_upper(const Matrix &U, const Vector &b, Vector &x)
Back substitution: solve Ux = b.
Definition dense.cpp:46
void trsv_lower(const Matrix &L, const Vector &b, Vector &x)
Forward substitution: solve Lx = b.
Definition dense.cpp:35
void ger(real alpha, const Vector &x, const Vector &y, Matrix &A, seq_t) noexcept
Sequential rank-1 update.
Definition dense.cpp:11
NUM_K_AINLINE void trsv_upper(T *NUM_K_RESTRICT x, const T *NUM_K_RESTRICT U, const T *NUM_K_RESTRICT b, idx n) noexcept
Back substitution: solve Ux = b, U upper triangular (n x n, row-major).
Definition raw.hpp:200
NUM_K_AINLINE void ger(T *NUM_K_RESTRICT A, const T *NUM_K_RESTRICT x, const T *NUM_K_RESTRICT y, T alpha, idx m, idx n) noexcept
Rank-1 update: A[i*n + j] += alpha * x[i] * y[j] (m x n row-major)
Definition raw.hpp:160
NUM_K_AINLINE void trsv_lower(T *NUM_K_RESTRICT x, const T *NUM_K_RESTRICT L, const T *NUM_K_RESTRICT b, idx n) noexcept
Forward substitution: solve Lx = b, L lower triangular (n x n, row-major).
Definition raw.hpp:181
double real
Definition types.hpp:10
std::size_t idx
Definition types.hpp:11
BasicVector< real > Vector
Real-valued dense vector with full backend dispatch (CPU + GPU)
Definition vector.hpp:129
Tier-1 kernel: raw-pointer, inline, zero-overhead inner loops.
Parallel execution policy tag.
Definition policy.hpp:13
Sequential execution policy tag.
Definition policy.hpp:10