|
pulsatrix
|
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – the backend must outlive every Tensor constructed against it, per cpp_style_guide/context_style_project_conventions.md's ownership table. More...
#include <tensor.hpp>
Public Member Functions | |
| Tensor (Shape shape, DeviceBackend *backend) | |
| Constructs a zero-initialized tensor on backend's own device (backend->device()). | |
| Tensor (Shape shape, DeviceBackend *backend, DeviceType device) | |
| Constructs a zero-initialized tensor with an explicit device tag. | |
| Tensor (Shape shape, DeviceBackend *backend, std::initializer_list< float > values, DeviceType device) | |
| Constructs a tensor from explicit values. | |
| Tensor (Shape shape, DeviceBackend *backend, std::initializer_list< float > values) | |
| As above, tagged with backend->device(). | |
| Tensor (Shape shape, DeviceBackend *backend, const std::vector< float > &values, DeviceType device) | |
| Constructs a tensor from explicit values, runtime-sized source. | |
| Tensor (Shape shape, DeviceBackend *backend, const std::vector< float > &values) | |
| As above, tagged with backend->device(). | |
| ~Tensor () | |
| Tensor (const Tensor &other) | |
| Deep-copies another tensor's buffer. | |
| Tensor & | operator= (const Tensor &other) |
| Tensor (Tensor &&other) noexcept | |
| Tensor & | operator= (Tensor &&other) noexcept |
| const Shape & | shape () const |
| This tensor's shape. | |
| int64_t | numel () const |
| Total element count – shape().numel(). | |
| int64_t | rank () const |
| Number of dimensions – shape().rank(). | |
| DeviceType | device () const |
| Which device this tensor's buffer conceptually resides on. | |
| DeviceBackend * | backend () const |
| The backend that owns this tensor's buffer. Not owned by the Tensor. | |
| bool | requires_grad () const |
| Whether a module's backward() should accumulate a gradient for this tensor when it is a parameter, and whether optimizers should update it. Defaults to true. | |
| void | set_requires_grad (bool requires_grad) |
| Sets requires_grad(); see there. | |
| float | read_element (int64_t flat_index) const |
| Reads one element to the host through the owning backend, on any device. | |
| std::vector< float > | to_host_vector () const |
| Copies the whole buffer to a host vector through the owning backend, on any device. | |
| void | write_element (int64_t flat_index, float value) |
| Writes one element from the host through the owning backend, on any device. | |
| const float * | data () const |
| Raw buffer access. nullptr iff numel() == 0. | |
| float * | data () |
| Raw buffer access (mutable). nullptr iff numel() == 0. | |
| float & | at (std::initializer_list< int64_t > index) |
| Element access by multi-dimensional index (row-major). | |
| const float & | at (std::initializer_list< int64_t > index) const |
| Const overload of at(). | |
| float & | operator[] (int64_t flat_index) |
| Flat (rank-agnostic) element access by linear offset into the row-major buffer. | |
| const float & | operator[] (int64_t flat_index) const |
| Const overload of operator[]. | |
| Tensor & | fill (float value) |
| Sets every element to value. Safe no-op on a zero-element tensor. | |
| Tensor & | accumulate (const Tensor &other) |
| In-place elementwise accumulation: this[i] += other[i] for every element. | |
| Tensor & | reshape (Shape new_shape) |
| Reinterprets this tensor's dimensions in place – same buffer, new shape. | |
| Tensor & | to (DeviceType target) |
| Same-device no-op form of to(). | |
| Tensor & | to (DeviceType target, DeviceBackend *target_backend) |
| Moves this tensor's buffer to another device, owned by target_backend. | |
Static Public Member Functions | |
| static Tensor | Stack (const std::vector< Tensor > &tensors, DeviceBackend *backend) |
| Concatenates N tensors along their leading dimension into one batch Tensor – pulsatrix's collate-time primitive (campaign_exai_dl_library_data_pipeline, Mission 0). E.g. stacking three (1, 28, 28) MNIST-style per-sample images produces one (3, 28, 28) batch. | |
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – the backend must outlive every Tensor constructed against it, per cpp_style_guide/context_style_project_conventions.md's ownership table.
| pulsatrix::Tensor::Tensor | ( | Shape | shape, |
| DeviceBackend * | backend | ||
| ) |
| pulsatrix::Tensor::Tensor | ( | Shape | shape, |
| DeviceBackend * | backend, | ||
| DeviceType | device | ||
| ) |
Constructs a zero-initialized tensor with an explicit device tag.
| shape | Tensor shape. |
| backend | Backend to allocate/fill through. Not owned; must outlive this Tensor. |
| device | Which device this tensor's buffer conceptually resides on. Should equal backend->device(); deliberately not enforced, because tests tag a host-backed buffer Cuda/Hip to exercise device guards without GPU hardware. |
| pulsatrix::Tensor::Tensor | ( | Shape | shape, |
| DeviceBackend * | backend, | ||
| std::initializer_list< float > | values, | ||
| DeviceType | device | ||
| ) |
Constructs a tensor from explicit values.
| shape | Tensor shape. values.size() must equal shape.numel(). |
| backend | Backend to allocate/copy through. |
| values | Initial values, in row-major order. |
| device | Which device this tensor's buffer conceptually resides on. |
| pulsatrix::Tensor::Tensor | ( | Shape | shape, |
| DeviceBackend * | backend, | ||
| std::initializer_list< float > | values | ||
| ) |
As above, tagged with backend->device().
| pulsatrix::Tensor::Tensor | ( | Shape | shape, |
| DeviceBackend * | backend, | ||
| const std::vector< float > & | values, | ||
| DeviceType | device | ||
| ) |
Constructs a tensor from explicit values, runtime-sized source.
| shape | Tensor shape. values.size() must equal shape.numel(). |
| backend | Backend to allocate/copy through. |
| values | Initial values, in row-major order. |
| device | Which device this tensor's buffer conceptually resides on. |
| pulsatrix::Tensor::Tensor | ( | Shape | shape, |
| DeviceBackend * | backend, | ||
| const std::vector< float > & | values | ||
| ) |
As above, tagged with backend->device().
| pulsatrix::Tensor::~Tensor | ( | ) |
| pulsatrix::Tensor::Tensor | ( | const Tensor & | other | ) |
Deep-copies another tensor's buffer.
|
noexcept |
In-place elementwise accumulation: this[i] += other[i] for every element.
| other | Tensor to add into this one. Must have the same shape. |
| float & pulsatrix::Tensor::at | ( | std::initializer_list< int64_t > | index | ) |
Element access by multi-dimensional index (row-major).
| index | One index per dimension; index.size() must equal rank(). |
| const float & pulsatrix::Tensor::at | ( | std::initializer_list< int64_t > | index | ) | const |
Const overload of at().
|
inline |
The backend that owns this tensor's buffer. Not owned by the Tensor.
|
inline |
Raw buffer access (mutable). nullptr iff numel() == 0.
|
inline |
Raw buffer access. nullptr iff numel() == 0.
|
inline |
Which device this tensor's buffer conceptually resides on.
| Tensor & pulsatrix::Tensor::fill | ( | float | value | ) |
Sets every element to value. Safe no-op on a zero-element tensor.
| value | Fill value. |
|
inline |
Flat (rank-agnostic) element access by linear offset into the row-major buffer.
|
inline |
Const overload of operator[].
| float pulsatrix::Tensor::read_element | ( | int64_t | flat_index | ) | const |
Reads one element to the host through the owning backend, on any device.
|
inline |
Whether a module's backward() should accumulate a gradient for this tensor when it is a parameter, and whether optimizers should update it. Defaults to true.
weight_ = loaded;) therefore leaves it frozen, matching PyTorch's param.data = x.
|
inline |
Sets requires_grad(); see there.
|
inline |
This tensor's shape.
|
static |
Concatenates N tensors along their leading dimension into one batch Tensor – pulsatrix's collate-time primitive (campaign_exai_dl_library_data_pipeline, Mission 0). E.g. stacking three (1, 28, 28) MNIST-style per-sample images produces one (3, 28, 28) batch.
| tensors | Non-empty list of tensors, each rank >= 1, each on the same device, all identical in every dimension except the leading one. |
| backend | Backend to allocate the output buffer through. Not owned. |
| std::invalid_argument | if tensors is empty, any tensor has rank 0, ranks differ across tensors, non-leading dimensions differ across tensors, or devices differ across tensors – external boundary: the list of tensors to stack is assembled by a DataLoader/collate function from independently constructed Dataset samples, not a compile-time-known invariant. |
| Tensor & pulsatrix::Tensor::to | ( | DeviceType | target | ) |
Same-device no-op form of to().
| target | Target device. Must equal device(). |
| std::invalid_argument | if target != device(). |
| Tensor & pulsatrix::Tensor::to | ( | DeviceType | target, |
| DeviceBackend * | target_backend | ||
| ) |
Moves this tensor's buffer to another device, owned by target_backend.
| target | Device the new buffer resides on. Must be the device target_backend allocates on (Cpu for CPUBackend, Cuda for CUDABackend, Hip for HIPBackend) – not checkable here, since DeviceBackend does not report its own device. |
| target_backend | Backend to allocate the new buffer through. Not owned; must outlive this Tensor, exactly as the constructor's backend must. |
| std::invalid_argument | if target_backend is nullptr. |
| std::vector< float > pulsatrix::Tensor::to_host_vector | ( | ) | const |
Copies the whole buffer to a host vector through the owning backend, on any device.
| void pulsatrix::Tensor::write_element | ( | int64_t | flat_index, |
| float | value | ||
| ) |
Writes one element from the host through the owning backend, on any device.