numerics 0.1.0
Loading...
Searching...
No Matches
operator.cpp
Go to the documentation of this file.
1#include "operator/dense.hpp"
2#include "operator/sparse.hpp"
3
4#include <stdexcept>
5
6namespace num::operators {
7
8void DenseOp::apply(const Vector& x, Vector& y) const {
9 if (x.size() != A_.cols()) {
10 throw std::invalid_argument("DenseOp::apply: input dimension mismatch");
11 }
12 if (y.size() != A_.rows()) {
13 y = Vector(A_.rows());
14 }
15 matvec(A_, x, y, b_);
16}
17
18void SparseOp::apply(const Vector& x, Vector& y) const {
19 if (x.size() != A_.n_cols()) {
20 throw std::invalid_argument("SparseOp::apply: input dimension mismatch");
21 }
22 if (y.size() != A_.n_rows()) {
23 y = Vector(A_.n_rows());
24 }
25 sparse_matvec(A_, x, y);
26}
27
28} // namespace num::operators
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
idx n_cols() const
Definition sparse.hpp:34
idx n_rows() const
Definition sparse.hpp:33
void matvec(const Matrix &A, const Vector &x, Vector &y, Backend b=default_backend)
y = A * x
Definition matrix.cpp:45
void sparse_matvec(const SparseMatrix &A, const Vector &x, Vector &y)
y = A * x
Definition sparse.cpp:122
BasicVector< real > Vector
Real-valued dense vector with full backend dispatch (CPU + GPU)
Definition vector.hpp:129
Dense Matrix adapter for the operator protocol.
SparseMatrix adapter for the operator protocol.
void apply(const Vector &x, Vector &y) const
Definition operator.cpp:8
void apply(const Vector &x, Vector &y) const
Definition operator.cpp:18