numerics 0.1.0
Loading...
Searching...
No Matches
sparse_op.hpp
Go to the documentation of this file.
1/// @file linalg/sparse/sparse_op.hpp
2/// @brief SparseMatrix adapter for the operator protocol.
3///
4/// Lives beside SparseMatrix (rather than under operator/) so the operator
5/// module stays free of any linalg dependency; the LinearOperator contract it
6/// models is defined in core/concepts.hpp.
7#pragma once
8
9#include "core/concepts.hpp"
11
12namespace num::operators {
13
14/// @brief Adapt a SparseMatrix to the operator protocol.
15struct SparseOp final {
16 explicit SparseOp(const SparseMatrix& A)
17 : A_(A) {}
18
19 void apply(const Vector& x, Vector& y) const;
20 [[nodiscard]] idx rows() const noexcept { return A_.n_rows(); }
21 [[nodiscard]] idx cols() const noexcept { return A_.n_cols(); }
22
23private:
24 const SparseMatrix& A_;
25};
26
27static_assert(LinearOperator<SparseOp>);
28
29} // namespace num::operators
Sparse matrix in Compressed Sparse Row (CSR) format.
Definition sparse.hpp:17
idx n_cols() const
Definition sparse.hpp:36
idx n_rows() const
Definition sparse.hpp:35
Compile-time contract for the matrix-free product y = A*x.
Definition concepts.hpp:67
Storage and operator concepts for numerical routines.
std::size_t idx
Definition types.hpp:11
Compressed Sparse Row (CSR) matrix and operations.
Adapt a SparseMatrix to the operator protocol.
Definition sparse_op.hpp:15
idx rows() const noexcept
Definition sparse_op.hpp:20
idx cols() const noexcept
Definition sparse_op.hpp:21
void apply(const Vector &x, Vector &y) const
Definition sparse_op.cpp:7
SparseOp(const SparseMatrix &A)
Definition sparse_op.hpp:16