|
Mila
Deep Neural Network Library
|
Device-aware N-dimensional tensor. More...
Public Types | |
| using | DataType = TensorDataType |
| Abstract data type enumeration. | |
| using | DataTypeTraits = TensorDataTypeTraits<TDataType> |
| Compile-time data type characteristics. | |
| using | host_value_t = std::conditional_t<TensorDataTypeTraits<TDataType>::is_integer_type, int32_t, float> |
| Host value type for scalars. | |
| using | MemoryResource = TMemoryResource |
| Memory resource type for this tensor. | |
Public Member Functions | |
| Tensor (Compute::DeviceId device_id, const shape_t &shape, std::string name={}) | |
| Creates a tensor bound to the specified device id and shape. | |
| Tensor (const Tensor &other)=delete | |
| Copy constructor - explicitly deleted for performance safety. | |
| Tensor (Tensor &&other) noexcept | |
| Efficiently transfers ownership from another tensor. | |
| ~Tensor ()=default | |
| Destructor with automatic resource cleanup via RAII. | |
| constexpr const auto * | data () const noexcept |
| Returns type-safe immutable pointer to tensor data with concrete host type. | |
| constexpr auto * | data () noexcept |
| Returns type-safe pointer to tensor data with concrete host type. | |
| size_t | elementSize () const override |
| Returns the size in bytes of a single tensor element. | |
| bool | empty () const |
| Checks if the tensor contains no elements. | |
| Tensor< TDataType, TMemoryResource > & | flatten () |
| Flattens tensor to 2D shape in-place. | |
| TensorDataType | getDataType () const override |
| Returns the tensor's abstract data type identifier. | |
| std::string | getDataTypeName () const override |
| Returns human-readable name of the tensor's data type. | |
| Compute::DeviceId | getDeviceId () const override |
| Compute::DeviceType | getDeviceType () const override |
| Returns the device type of this tensor's memory resource. | |
| Compute::MemoryResource * | getMemoryResource () const override |
| Returns pointer to the memory resource managing this tensor's storage. | |
| std::string | getName () const override |
| Returns the tensor's optional user-assigned name. | |
| size_t | getStorageSize () const override |
| Returns the total storage size in bytes backing the tensor's buffer. | |
| std::string | getUId () const override |
| Returns the tensor's unique identifier. | |
| bool | isScalar () const noexcept override |
| Checks if tensor is a scalar (0-dimensional). | |
| bool | isValid () const noexcept |
| Check if tensor is in a valid state (not moved-from). | |
| bool | isView () const override |
| Check if this tensor is a view of another tensor's data. | |
| auto & | item () |
| Gets the scalar value for 0-dimensional tensors. | |
| const auto & | item () const |
| Gets the scalar value for 0-dimensional tensors (const version). | |
| Tensor & | operator= (const Tensor &other)=delete |
| Copy assignment operator - explicitly deleted. | |
| Tensor & | operator= (Tensor &&other) noexcept |
| Efficiently moves resources from another tensor. | |
| auto & | operator[] (const index_t &indices) |
| Accesses tensor element using multi-dimensional indices. | |
| const auto & | operator[] (const index_t &indices) const |
| Accesses tensor element using multi-dimensional indices (const version). | |
|
template<typename... Indices> requires TMemoryResource::is_host_accessible | |
| auto & | operator[] (Indices... indices) &&(std |
| Variadic index access (non-const). | |
|
template<typename... Indices> requires TMemoryResource::is_host_accessible | |
| const auto & | operator[] (Indices... indices) const &&(std |
| Variadic index access (const). | |
| size_t | rank () const |
| Returns the number of dimensions in the tensor. | |
| const void * | rawData () const override |
| Returns raw pointer to tensor data (const version). | |
| void * | rawData () override |
| Returns raw pointer to tensor data (implements ITensor protected API). | |
| void | reshape (const shape_t &new_shape) |
| Modifies tensor shape while preserving total element count. | |
| void | setName (const std::string &value) |
| Assigns a descriptive name to the tensor. | |
| const shape_t & | shape () const override |
| Returns the tensor's dimensional shape vector. | |
| dim_t | size () const override |
| Returns the total number of logical elements in the tensor. | |
| const stride_t & | strides () const |
| Returns the tensor's memory stride information. | |
| std::string | toString (bool showBuffer=false) const |
| Generates string representation of the tensor. | |
| Tensor | view (const shape_t &new_shape, dim_t offset=0) const |
| Public Member Functions inherited from Mila::Dnn::ITensor | |
| template<typename T> | |
| bool | isType () const |
| Type-safe check for tensor element type. | |
Device-aware N-dimensional tensor.
Move-only tensor parameterized by an abstract TensorDataType and a MemoryResource. Scalars are represented by an empty shape ({}), which yields size() == 1.
| TDataType | Abstract tensor data type from TensorDataType enumeration |
| TMemoryResource | Memory resource type defining storage location and access patterns |
|
inlineexplicit |
Creates a tensor bound to the specified device id and shape.
Constructs a tensor using a DeviceId. Empty shape {} creates a scalar (0D tensor) with size 1. Shape containing a zero produces an empty tensor.
| device_id | Device identifier (type + index) |
| shape | Vector defining the size of each dimension in row-major order |
| name | Optional tensor name for diagnostics (default: empty) |
| std::invalid_argument | If device id is invalid (checked by validateDeviceId) |
| std::runtime_error | If device type doesn't match memory resource |
| std::bad_alloc | If memory allocation fails |
|
delete |
Copy constructor - explicitly deleted for performance safety.
Use clone() for deep copies or std::move() for ownership transfer.
|
inlinenoexcept |
Efficiently transfers ownership from another tensor.
Moves resources from the source tensor, leaving it in a moved-from state.
|
inlinenodiscardconstexprnoexcept |
Returns type-safe pointer to tensor data with concrete host type.
Only available for host-accessible memory resources.
|
inlineoverridevirtual |
Returns the size in bytes of a single tensor element.
Implements Mila::Dnn::ITensor.
|
inline |
Checks if the tensor contains no elements.
Scalars are NOT empty (size == 1). Empty tensors have size == 0.
|
inline |
Flattens tensor to 2D shape in-place.
No-op for scalars and vectors.
|
inlineoverridevirtual |
Returns the tensor's abstract data type identifier.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns human-readable name of the tensor's data type.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns the device type of this tensor's memory resource.
Equivalent to TMemoryResource::device_type.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns pointer to the memory resource managing this tensor's storage.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns the tensor's optional user-assigned name.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns the total storage size in bytes backing the tensor's buffer.
Forwards to the authoritative TensorBuffer::storageBytes() value and returns 0 when no buffer is allocated.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns the tensor's unique identifier.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtualnoexcept |
Checks if tensor is a scalar (0-dimensional).
Scalars: shape {} and size() == 1.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Check if this tensor is a view of another tensor's data.
Implements Mila::Dnn::ITensor.
|
inline |
Gets the scalar value for 0-dimensional tensors.
Only available for host-accessible memory resources.
| std::runtime_error | If tensor is not a scalar (rank != 0) |
|
inline |
Gets the scalar value for 0-dimensional tensors (const version).
Only available for host-accessible memory resources.
| std::runtime_error | If tensor is not a scalar (rank != 0) |
|
delete |
Copy assignment operator - explicitly deleted.
Use clone() for deep copies or std::move() for transfers.
|
inlinenoexcept |
Efficiently moves resources from another tensor.
Self-assignment safe implementation.
|
inline |
Accesses tensor element using multi-dimensional indices.
Only available for host-accessible memory resources.
|
inlineoverridevirtual |
Returns raw pointer to tensor data (const version).
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns raw pointer to tensor data (implements ITensor protected API).
Implements Mila::Dnn::ITensor.
|
inline |
Modifies tensor shape while preserving total element count.
The new shape must have the same total number of elements as the current shape, unless the tensor is empty.
|
inline |
Assigns a descriptive name to the tensor.
Names must be non-empty strings.
|
inlineoverridevirtual |
Returns the tensor's dimensional shape vector.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns the total number of logical elements in the tensor.
Implements Mila::Dnn::ITensor.
|
inline |
Generates string representation of the tensor.
Includes UID, name, shape, data type and device information.