37 DenseTensor(
const std::vector<std::size_t> &
shape,
double *preallocated_ptr);
40 [[nodiscard]]
const std::vector<std::size_t> &
shape()
const;
42 [[nodiscard]] std::size_t
size()
const;
46 [[nodiscard]]
double &
operator[](std::size_t flat_idx);
49 [[nodiscard]]
double operator[](std::size_t flat_idx)
const;
56 [[nodiscard]]
double &
at(
const std::vector<std::size_t> &indices);
62 [[nodiscard]]
double at(
const std::vector<std::size_t> &indices)
const;
68 const double *
data()
const;
83 void fill(
double value);
95 [[nodiscard]] std::size_t
Dense row-major array of doubles with a fixed shape.
double * mapped_data_
borrowed buffer; takes precedence when non-null
std::vector< std::size_t > shape_
DenseTensor(const std::vector< std::size_t > &shape)
Creates an owning tensor filled with zeros.
double & at(const std::vector< std::size_t > &indices)
Checked element access by one index per dimension.
double * data()
Pointer to the first element: the borrowed buffer when one is bound, otherwise the owned storage.
const std::vector< std::size_t > & shape() const
Extent of each dimension, as given at construction.
double & operator[](std::size_t flat_idx)
Element access by flat row-major index.
std::vector< double > owned_data_
empty for a tensor created over caller memory
void multiply_inplace(const DenseTensor &other)
Multiplies this tensor by another, element by element.
std::size_t compute_flat_index(const std::vector< std::size_t > &indices) const
Checked conversion used by at(). Throws as documented there.
void bind_data(double *ptr)
Redirects the tensor to a caller buffer.
void fill(double value)
Sets every element to value.
std::size_t num_elements_
std::vector< std::size_t > strides_
row-major strides, same length as shape_
std::size_t size() const
Total number of elements, the product of the shape.