tensor ๐
Interface to the struct vaccel_torch_tensor
C object.
Tensor ๐
Bases: CType
Wrapper for the struct vaccel_torch_tensor
C object.
Manages the creation and initialization of a C struct vaccel_torch_tensor
and provides access to it through Python properties.
Inherits
CType: Abstract base class for defining C data types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| list[int] | The dims to be passed to the C struct. | required |
| TensorType | The data_type to be passed to the C struct. | required |
| list[Any] | The data to be passed to the C struct. | required |
Source code in vaccel/ops/torch/tensor.py
data_type property
๐
The tensor data type.
Returns:
Type | Description |
---|---|
TensorType | The data type of the tensor. |
dims property
๐
shape property
๐
value property
๐
Returns the value of the underlying C struct.
Returns:
Type | Description |
---|---|
CData | The dereferenced 'struct vaccel_torch_tensor` |
as_bytelike ๐
as_bytelike() -> bytes | bytearray | memoryview
Returns the tensor data buffer as a byte-like object.
Returns:
Type | Description |
---|---|
bytes | bytearray | memoryview | The data of the tensor as a byte-like object. |
Source code in vaccel/ops/torch/tensor.py
as_memoryview ๐
as_memoryview() -> memoryview
Returns the tensor data buffer as memoryview.
Returns:
Type | Description |
---|---|
memoryview | The data of the tensor as memoryview. |
Source code in vaccel/ops/torch/tensor.py
as_numpy ๐
Returns the tensor data buffer as a NumPy array.
Returns:
Type | Description |
---|---|
ndarray | The data of the tensor as a NumPy array. |
Source code in vaccel/ops/torch/tensor.py
as_torch ๐
Returns the tensor as a PyTorch tensor.
Returns:
Type | Description |
---|---|
Tensor | The tensor as a PyTorch tensor. |
Raises:
Type | Description |
---|---|
NotImplementedError | If PyTorch is not installed. |
Source code in vaccel/ops/torch/tensor.py
empty classmethod
๐
empty() -> Tensor
Initializes a new empty Tensor
object.
The object has a NULL pointer in place of the C struct.
Returns:
Type | Description |
---|---|
Tensor | A new |
Source code in vaccel/ops/torch/tensor.py
from_buffer classmethod
๐
from_buffer(
dims: list[int], data_type: TensorType, data: bytes | bytearray | memoryview
) -> Tensor
Initializes a new Tensor
object from byte-like data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| list[int] | The dims to be passed to the C struct. | required |
| TensorType | The data_type to be passed to the C struct. | required |
| bytes | bytearray | memoryview | The data to be passed to the C struct. | required |
Returns:
Type | Description |
---|---|
Tensor | A new |
Source code in vaccel/ops/torch/tensor.py
from_c_obj classmethod
๐
Initializes a new Tensor
object from an existing C struct.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| CData | A pointer to a | required |
Returns:
Type | Description |
---|---|
Tensor | A new |
Source code in vaccel/ops/torch/tensor.py
from_numpy classmethod
๐
Initializes a new Tensor
object from a NumPy array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| ndarray | The NumPy array containing the tensor data. | required |
Returns:
Type | Description |
---|---|
Tensor | A new |
Raises:
Type | Description |
---|---|
NotImplementedError | If NumPy is not installed. |
Source code in vaccel/ops/torch/tensor.py
from_torch classmethod
๐
Initializes a new Tensor
object from a PyTorch tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| Tensor | The PyTorch tensor containing the tensor data. | required |
Returns:
Type | Description |
---|---|
Tensor | A new |
Raises:
Type | Description |
---|---|
NotImplementedError | If PyTorch is not installed. |
Source code in vaccel/ops/torch/tensor.py
TensorTypeMapper ๐
Utility for mapping between TensorType
and other common types.
type_from_numpy classmethod
๐
type_from_numpy(dtype: dtype) -> TensorType
Converts a NumPy dtype
to TensorType
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| dtype | A NumPy | required |
Returns:
Type | Description |
---|---|
TensorType | A corresponding tensor type value. |
Raises:
Type | Description |
---|---|
NotImplementedError | If NumPy is not installed. |
ValueError | If the |
Source code in vaccel/ops/torch/tensor.py
type_from_torch classmethod
๐
type_from_torch(dtype: dtype) -> TensorType
Converts a PyTorch dtype
to TensorType
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| dtype | A PyTorch | required |
Returns:
Type | Description |
---|---|
TensorType | A corresponding tensor type value. |
Raises:
Type | Description |
---|---|
NotImplementedError | If PyTorch is not installed. |
ValueError | If the |
Source code in vaccel/ops/torch/tensor.py
type_to_c_size classmethod
๐
type_to_c_size(tensor_type: TensorType) -> int
Converts a TensorType
to a C type size (in bytes).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| TensorType | The tensor type value. | required |
Returns:
Type | Description |
---|---|
int | A corresponding C type size in bytes. |
Raises:
Type | Description |
---|---|
ValueError | If the |
Source code in vaccel/ops/torch/tensor.py
type_to_c_type classmethod
๐
type_to_c_type(tensor_type: TensorType) -> str
Converts a TensorType
to a C type string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| TensorType | The tensor type value. | required |
Returns:
Type | Description |
---|---|
str | A corresponding C type as a string (e.g., "float", "int64_t"). |
Raises:
Type | Description |
---|---|
ValueError | If the |
Source code in vaccel/ops/torch/tensor.py
type_to_numpy classmethod
๐
type_to_numpy(ttype: TensorType) -> dtype
Converts a TensorType
to a NumPy dtype
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| TensorType | A | required |
Returns:
Type | Description |
---|---|
dtype | A corresponding NumPy |
Raises:
Type | Description |
---|---|
NotImplementedError | If NumPy is not installed. |
ValueError | If the |
Source code in vaccel/ops/torch/tensor.py
type_to_torch classmethod
๐
type_to_torch(ttype: TensorType) -> dtype
Converts a TensorType
to a PyTorch dtype
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| TensorType | A | required |
Returns:
Type | Description |
---|---|
dtype | A corresponding PyTorch |
Raises:
Type | Description |
---|---|
NotImplementedError | If PyTorch is not installed. |
ValueError | If the |