16template<std::
floating_po
int T>
33 std::fill_n(data_.get(),
size(), val);
37 if constexpr (std::is_same_v<T, real>) {
47 data_(new T[o.
size()]) {
48 std::copy_n(o.data_.get(),
size(), data_.get());
54 data_(std::move(o.data_)),
56 o.rows_ = o.cols_ = 0;
64 data_.reset(
new T[
size()]);
65 std::copy_n(o.data_.get(),
size(), data_.get());
72 if constexpr (std::is_same_v<T, real>) {
79 data_ = std::move(o.data_);
81 o.rows_ = o.cols_ = 0;
87 [[nodiscard]]
constexpr idx rows() const noexcept {
return rows_; }
88 [[nodiscard]]
constexpr idx cols() const noexcept {
return cols_; }
89 [[nodiscard]]
constexpr idx size() const noexcept {
return rows_ * cols_; }
91 T*
data() {
return data_.get(); }
92 const T*
data()
const {
return data_.get(); }
98 if constexpr (std::is_same_v<T, real>) {
107 if constexpr (std::is_same_v<T, real>) {
118 [[nodiscard]]
bool on_gpu()
const {
return d_data_ !=
nullptr; }
121 idx rows_ = 0, cols_ = 0;
122 std::unique_ptr<T[]> data_;
123 T* d_data_ =
nullptr;
Dense row-major owning matrix.
constexpr idx rows() const noexcept
T operator()(idx i, idx j) const
BasicMatrix(idx rows, idx cols)
BasicMatrix(const BasicMatrix &o)
BasicMatrix(BasicMatrix &&o) noexcept
BasicMatrix & operator=(BasicMatrix &&o) noexcept
BasicMatrix(idx rows, idx cols, T val)
BasicMatrix & operator=(const BasicMatrix &o)
constexpr idx size() const noexcept
T & operator()(idx i, idx j)
constexpr idx cols() const noexcept
const T * gpu_data() const
Backend enum and default backend selection.
void to_device(real *dst, const real *src, idx n)
Copy host to device.
void free(real *ptr)
Free device memory.
real * alloc(idx n)
Allocate device memory.
void to_host(real *dst, const real *src, idx n)
Copy device to host.
void matmul_simd(const Matrix &A, const Matrix &B, Matrix &C, idx block_size=64)
C = A * B (SIMD-accelerated)
void matvec_simd(const Matrix &A, const Vector &x, Vector &y)
y = A * x (SIMD-accelerated)
real beta(real a, real b)
B(a, b) – beta function.
void matvec(const Matrix &A, const Vector &x, Vector &y, Backend b=default_backend)
y = A * x
void matmul_blocked(const Matrix &A, const Matrix &B, Matrix &C, idx block_size=64)
C = A * B (cache-blocked)
void matmul(const Matrix &A, const Matrix &B, Matrix &C, Backend b=default_backend)
C = A * B.
constexpr Backend default_backend
void matadd(real alpha, const Matrix &A, real beta, const Matrix &B, Matrix &C, Backend b=default_backend)
C = alpha*A + beta*B.
void matmul_register_blocked(const Matrix &A, const Matrix &B, Matrix &C, idx block_size=64, idx reg_size=4)
C = A * B (register-blocked)
Dense vector storage and operations.