DLPackTensorRef

Struct DLPackTensorRef 

Source
pub struct DLPackTensorRef<'a> {
    pub raw: DLTensor,
    /* private fields */
}
Expand description

A reference to a DLPack tensor, with data borrowed from some owner, potentially in another language.

Fields§

§raw: DLTensor

Implementations§

Source§

impl<'a> DLPackTensorRef<'a>

Source

pub unsafe fn from_raw(tensor: DLTensor) -> DLPackTensorRef<'a>

Create a DLPackTensorRef from a raw DLTensor

§Safety

The lifetime of the returned reference should be constrained to the actual lifetime of the DLTensor.

Source

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

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

Source

pub fn device(&self) -> DLDevice

Get the device where the data of this tensor lives.

Source

pub fn dtype(&self) -> DLDataType

Get the data type of this tensor

Source

pub fn n_dims(&self) -> usize

Get the number of dimensions of this tensor

Source

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

Get the shape of this tensor

Source

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

Get the strides of this tensor, if any

Source

pub fn byte_offset(&self) -> usize

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

Source

pub fn as_dltensor(&self) -> &DLTensor

Get a reference to the underlying DLTensor

Trait Implementations§

Source§

impl Debug for DLPackTensorRef<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a, T, D> TryFrom<&'a ArrayBase<OwnedArcRepr<T>, D>> for DLPackTensorRef<'a>

Source§

type Error = DLPackNDarrayError

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

fn try_from(array: &'a ArcArray<T, D>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a, T, D> TryFrom<&'a ArrayBase<OwnedRepr<T>, D>> for DLPackTensorRef<'a>

Source§

type Error = DLPackNDarrayError

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

fn try_from(array: &'a Array<T, D>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a, T, D> TryFrom<&'a ArrayBase<ViewRepr<&'a T>, D>> for DLPackTensorRef<'a>

Source§

type Error = DLPackNDarrayError

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

fn try_from(array: &'a ArrayView<'a, T, D>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'py> TryFrom<Bound<'py, PyCapsule>> for DLPackTensorRef<'py>

Source§

type Error = PyErr

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

fn try_from(value: Bound<'py, PyCapsule>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a, T> TryFrom<DLPackTensorRef<'a>> for &'a [T]

Source§

type Error = DLPackVecError

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

fn try_from(value: DLPackTensorRef<'a>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a, T, D> TryFrom<DLPackTensorRef<'a>> for ArrayView<'a, T, D>
where T: DLPackPointerCast + 'static, D: DimFromVec + 'static,

Source§

type Error = DLPackNDarrayError

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

fn try_from(tensor: DLPackTensorRef<'a>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'a> Freeze for DLPackTensorRef<'a>

§

impl<'a> RefUnwindSafe for DLPackTensorRef<'a>

§

impl<'a> !Send for DLPackTensorRef<'a>

§

impl<'a> !Sync for DLPackTensorRef<'a>

§

impl<'a> Unpin for DLPackTensorRef<'a>

§

impl<'a> UnwindSafe for DLPackTensorRef<'a>

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.