Skip to main content

DLPackTensorRefMut

Struct DLPackTensorRefMut 

Source
pub struct DLPackTensorRefMut<'a> { /* private fields */ }
Expand description

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

Implementations§

Source§

impl<'a> DLPackTensorRefMut<'a>

Source

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

Create a DLPackTensorRefMut from a raw DLTensor

§Safety

The lifetime of the returned reference should be constrained to the actual lifetime of the DLTensor. The DLTensor should also be mutable, and there should not be any other references (mutable or not) to the same DLTensor.

Source

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

Convert this mutable reference to an immutable reference.

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 DLPackTensorRefMut::device.

Source

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

Get a mutable pointer to data in this tensor. This pointer can be a device pointer according to DLPackTensorRefMut::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 DLPackTensorRefMut::data_ptr and DLPackTensorRefMut::data_ptr_mut 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 DLPackTensorRefMut<'_>

Source§

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

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

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

Source§

type Error = DLPackVecError

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

fn try_from(value: DLPackTensorRefMut<'a>) -> Result<Self, Self::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.