Skip to main content

DLPackTensor

Struct DLPackTensor 

pub struct DLPackTensor { /* private fields */ }
Expand description

A managed DLPack tensor, carrying ownership of the data.

Convertion from and to other array types is handled though the different TryFrom implementations.

Implementations§

§

impl DLPackTensor

pub unsafe fn from_ptr(tensor: *mut DLManagedTensorVersioned) -> DLPackTensor

Create a DLPackTensor from a pointer to DLManagedTensorVersioned.

§Safety

The DLManagedTensorVersioned should have a valid deleter that can be called from Rust, or have the deleter set to None.

pub unsafe fn from_raw( tensor: NonNull<DLManagedTensorVersioned>, ) -> DLPackTensor

Create a DLPackTensor from a non-null pointer to DLManagedTensorVersioned.

§Safety

The same safety requirements as from_ptr apply.

pub fn as_ref(&self) -> DLPackTensorRef<'_>

Get a DLPack tensor reference from this owned tensor

pub fn as_mut(&mut self) -> DLPackTensorRefMut<'_>

Get a mutable DLPack tensor reference from this owned tensor

pub fn version(&self) -> DLPackVersion

Get the ABI version of this DLPack tensor.

pub fn data_ptr<T>(&self) -> Result<*const T, CastError>
where T: DLPackPointerCast,

Get a pointer to data in this tensor. This pointer can be a device pointer according to DLPackTensor::device.

pub fn data_ptr_mut<T>(&mut self) -> Result<*mut T, CastError>
where T: DLPackPointerCast,

Get a mutable pointer to data in this tensor. This pointer can be a device pointer according to DLPackTensor::device.

pub fn device(&self) -> DLDevice

Get the device where the data of this tensor lives.

pub fn dtype(&self) -> DLDataType

Get the data type of this tensor

pub fn n_dims(&self) -> usize

Get the number of dimensions of this tensor

pub fn shape(&self) -> &[i64]

Get the shape of this tensor

pub fn strides(&self) -> Option<&[i64]>

Get the strides of this tensor, if any

pub fn flags(&self) -> u64

Get the raw flags bitfield.

pub fn is_read_only(&self) -> bool

Check if the tensor is explicitly marked as read-only.

pub fn is_copied(&self) -> bool

Check if the tensor is unique/owned (IS_COPIED bit).

pub fn is_subbyte_type_padded(&self) -> bool

Check if the sub-byte types (fp4, fp6) are padded to the next byte, or packed together.

pub fn byte_offset(&self) -> usize

Get the byte offset of this tensor, i.e. how many bytes should be added to DLPackTensor::data_ptr and DLPackTensor::data_ptr_mut to get the first element of the tensor.

pub fn as_dltensor(&self) -> &DLTensor

Get a reference to the underlying DLTensor

pub fn into_raw(self) -> NonNull<DLManagedTensorVersioned>

Consumes the DLPackTensor, returning the underlying raw pointer.

§Safety

The caller is responsible for managing the memory and calling the deleter when the tensor is no longer needed.

Trait Implementations§

§

impl Debug for DLPackTensor

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Drop for DLPackTensor

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl<T, D> TryFrom<Arc<Mutex<ArrayBase<OwnedRepr<T>, D>>>> for DLPackTensor
where D: Dimension + 'static, T: GetDLPackDataType + 'static + Clone,

§

type Error = DLPackNDarrayError

The type returned in the event of a conversion error.
§

fn try_from( array: Arc<Mutex<ArrayBase<OwnedRepr<T>, D>>>, ) -> Result<DLPackTensor, <DLPackTensor as TryFrom<Arc<Mutex<ArrayBase<OwnedRepr<T>, D>>>>>::Error>

Performs the conversion.
§

impl<T> TryFrom<Arc<Mutex<Vec<T>>>> for DLPackTensor
where T: GetDLPackDataType + 'static,

§

type Error = DLPackVecError

The type returned in the event of a conversion error.
§

fn try_from( array: Arc<Mutex<Vec<T>>>, ) -> Result<DLPackTensor, <DLPackTensor as TryFrom<Arc<Mutex<Vec<T>>>>>::Error>

Performs the conversion.
§

impl<T, D> TryFrom<ArrayBase<OwnedArcRepr<T>, D>> for DLPackTensor
where D: Dimension, T: GetDLPackDataType + 'static + Clone,

Convert a shared ArcArray into a DLPackTensor. This is ZERO-COPY: it increments the reference count of the data.

§

type Error = DLPackNDarrayError

The type returned in the event of a conversion error.
§

fn try_from( array: ArrayBase<OwnedArcRepr<T>, D>, ) -> Result<DLPackTensor, <DLPackTensor as TryFrom<ArrayBase<OwnedArcRepr<T>, D>>>::Error>

Performs the conversion.
§

impl<T, D> TryFrom<ArrayBase<OwnedRepr<T>, D>> for DLPackTensor
where D: Dimension, T: GetDLPackDataType + 'static,

§

type Error = DLPackNDarrayError

The type returned in the event of a conversion error.
§

fn try_from( array: ArrayBase<OwnedRepr<T>, D>, ) -> Result<DLPackTensor, <DLPackTensor as TryFrom<ArrayBase<OwnedRepr<T>, D>>>::Error>

Performs the conversion.
§

impl<T> TryFrom<Box<[T]>> for DLPackTensor
where T: GetDLPackDataType,

§

type Error = DLPackVecError

The type returned in the event of a conversion error.
§

fn try_from( value: Box<[T]>, ) -> Result<DLPackTensor, <DLPackTensor as TryFrom<Box<[T]>>>::Error>

Performs the conversion.
§

impl<T> TryFrom<DLPackTensor> for Vec<T>
where T: DLPackPointerCast + Clone,

§

type Error = DLPackVecError

The type returned in the event of a conversion error.
§

fn try_from( value: DLPackTensor, ) -> Result<Vec<T>, <Vec<T> as TryFrom<DLPackTensor>>::Error>

Performs the conversion.
§

impl<T, D> TryFrom<ReadOnly<Arc<RwLock<ArrayBase<OwnedRepr<T>, D>>>>> for DLPackTensor
where D: Dimension + 'static, T: GetDLPackDataType + 'static + Clone,

§

type Error = DLPackNDarrayError

The type returned in the event of a conversion error.
§

fn try_from( _: ReadOnly<Arc<RwLock<ArrayBase<OwnedRepr<T>, D>>>>, ) -> Result<DLPackTensor, <DLPackTensor as TryFrom<ReadOnly<Arc<RwLock<ArrayBase<OwnedRepr<T>, D>>>>>>::Error>

Performs the conversion.
§

impl<T> TryFrom<ReadOnly<Arc<RwLock<Vec<T>>>>> for DLPackTensor
where T: GetDLPackDataType + 'static,

§

type Error = DLPackVecError

The type returned in the event of a conversion error.
§

fn try_from( _: ReadOnly<Arc<RwLock<Vec<T>>>>, ) -> Result<DLPackTensor, <DLPackTensor as TryFrom<ReadOnly<Arc<RwLock<Vec<T>>>>>>::Error>

Performs the conversion.
§

impl<T, D> TryFrom<ReadWrite<Arc<RwLock<ArrayBase<OwnedRepr<T>, D>>>>> for DLPackTensor
where D: Dimension + 'static, T: GetDLPackDataType + 'static + Clone,

§

type Error = DLPackNDarrayError

The type returned in the event of a conversion error.
§

fn try_from( _: ReadWrite<Arc<RwLock<ArrayBase<OwnedRepr<T>, D>>>>, ) -> Result<DLPackTensor, <DLPackTensor as TryFrom<ReadWrite<Arc<RwLock<ArrayBase<OwnedRepr<T>, D>>>>>>::Error>

Performs the conversion.
§

impl<T> TryFrom<ReadWrite<Arc<RwLock<Vec<T>>>>> for DLPackTensor
where T: GetDLPackDataType + 'static,

§

type Error = DLPackVecError

The type returned in the event of a conversion error.
§

fn try_from( _: ReadWrite<Arc<RwLock<Vec<T>>>>, ) -> Result<DLPackTensor, <DLPackTensor as TryFrom<ReadWrite<Arc<RwLock<Vec<T>>>>>>::Error>

Performs the conversion.
§

impl<T> TryFrom<Vec<T>> for DLPackTensor
where T: GetDLPackDataType,

§

type Error = DLPackVecError

The type returned in the event of a conversion error.
§

fn try_from( value: Vec<T>, ) -> Result<DLPackTensor, <DLPackTensor as TryFrom<Vec<T>>>::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.