31 std::fill_n(data_.get(), n_, val);
35 : n_(init.
size()), data_(new T[n_]) {
36 std::copy(init.begin(), init.end(), data_.get());
40 if constexpr (std::is_same_v<T, real>) {
47 std::copy_n(o.data_.get(), n_, data_.get());
51 : n_(o.n_), data_(std::move(o.data_)), d_data_(o.d_data_) {
59 data_.reset(
new T[n_]);
60 std::copy_n(o.data_.get(), n_, data_.get());
67 if constexpr (std::is_same_v<T, real>) {
72 data_ = std::move(o.data_);
80 constexpr idx size() const noexcept {
return n_; }
86 T *
data() {
return data_.get(); }
87 const T *
data()
const {
return data_.get(); }
92 T *
begin() {
return data_.get(); }
93 T *
end() {
return data_.get() + n_; }
94 const T *
begin()
const {
return data_.get(); }
95 const T *
end()
const {
return data_.get() + n_; }
100 if constexpr (std::is_same_v<T, real>) {
109 if constexpr (std::is_same_v<T, real>) {
120 bool on_gpu()
const {
return d_data_ !=
nullptr; }
124 std::unique_ptr<T[]> data_;
Dense vector with optional GPU storage, templated over scalar type T.
const real * gpu_data() const
BasicVector(idx n, T val)
BasicVector & operator=(BasicVector &&o) noexcept
BasicVector & operator=(const BasicVector &o)
T operator[](idx i) const
BasicVector(BasicVector &&o) noexcept
const BasicVector & vec() const
BasicVector & vec()
Satisfy the VecField concept: a Vector is its own underlying vector.
constexpr idx size() const noexcept
BasicVector(const BasicVector &o)
BasicVector(std::initializer_list< T > init)
Backend enum for linear algebra operations.
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.
Backend
Selects which backend handles a linalg operation.
void scale(Vector &v, real alpha, Backend b=default_backend)
v *= alpha
real dot(const Vector &x, const Vector &y, Backend b=default_backend)
dot product
real norm(const Vector &x, Backend b=default_backend)
Euclidean norm.
std::complex< real > cplx
void axpy(real alpha, const Vector &x, Vector &y, Backend b=default_backend)
y += alpha * x
constexpr Backend default_backend
void add(const Vector &x, const Vector &y, Vector &z, Backend b=default_backend)
z = x + y
BasicVector< cplx > CVector
Complex-valued dense vector (sequential; no GPU)
Read-only variant of Vec2View for const Vectors.
real x(idx i) const noexcept
real y(idx i) const noexcept
idx size() const noexcept
Non-owning view of a flat Vector as an array of 2D points.
real x(idx i) const noexcept
idx size() const noexcept
Number of 2D points (= v.size() / 2).
real y(idx i) const noexcept