num::vec¶
Defined in header <container/vector.hpp>
template <typename T>
class vec;
Dense owning vector. vec<real> takes the CPU and GPU backends; other scalars stay on the host.
Members¶
| member | description |
|---|---|
using value_type = T |
|
vec() |
Construct an empty vector. |
explicit vec(idx n) |
Construct n value-initialized elements. |
vec(idx n, T val) |
Construct n elements initialized to val. |
vec(std::initializer_list<T> init) |
Copy values from an initializer list. |
explicit vec(view<const T> values) |
Copy values from a non-owning span. |
explicit vec(const std::vector<T> &values) |
|
vec(const vec &o) |
|
vec(vec &&o) noexcept |
|
vec &operator=(const vec &o) |
|
vec &operator=(vec &&o) noexcept |
|
constexpr idx size() const noexcept |
Return the element count. |
vec &as_vec() |
Expose the vector itself for field-compatible generic code. |
const vec &as_vec() const |
|
T *data() noexcept |
Return contiguous host storage, aligned to num::storage_alignment. The assume_storage_aligned wrapper is what carries the guarantee into the caller's codegen; the aligned allocation on its own is invisible to the optimizer across a function boundary. |
const T *data() const noexcept |
|
view<T> span() noexcept |
A view over the whole vector, for interfaces that take std::span. The storage is contiguous, so this is a pointer and a length. It exists because several routines (sample_categorical, categorical_sampler, the diagonal helpers) accept a span, and spelling that out at every call site is noise. |
view<const T> span() const noexcept |
|
T &operator[](idx i) |
|
T operator[](idx i) const |
|
T &front() |
First and last elements. Undefined when the vector is empty, as for any sequence container. |
const T &front() const |
|
T &back() |
|
const T &back() const |
|
T *begin() |
|
T *end() |
|
const T *begin() const |
|
const T *end() const |
|
void to_gpu() |
Copy host data to a lazily allocated device mirror. |
void to_cpu() |
Copy the device mirror back to host and release device storage. |
real *gpu_data() |
Return device storage, or null when no mirror exists. |
const real *gpu_data() const |
|
bool on_gpu() const |