Skip to main content

SafeManagedTensorVersioned

Struct SafeManagedTensorVersioned 

Source
pub struct SafeManagedTensorVersioned(/* private fields */);
Expand description

A safe wrapper around a versioned DLPack tensor that manages its memory lifecycle.

This struct provides a safe interface to work with DLPack tensors while ensuring proper memory management through RAII. It wraps a ffi::DlpackVersioned pointer and handles cleanup when the tensor is dropped.

Implementations§

Source§

impl SafeManagedTensorVersioned

Source

pub fn new<T, L>(t: T) -> Result<Self, T::Error>
where T: TensorLike<L>, L: MemoryLayout,

Creates a new SafeManagedTensorVersioned from a tensor-like type.

§Arguments
  • t - A type that implements TensorLike and has a valid MemoryLayout
§Returns

A new SafeManagedTensorVersioned with default flags

Source

pub fn with_flags<T, L>(t: T, flags: Flags) -> Result<Self, T::Error>
where T: TensorLike<L>, L: MemoryLayout,

Creates a new SafeManagedTensorVersioned from a tensor-like type with specified flags.

§Arguments
  • t - A type that implements TensorLike and has a valid MemoryLayout
  • flags - Flags to set on the managed tensor
§Returns

A new SafeManagedTensorVersioned with the specified flags

Source

pub unsafe fn from_raw(ptr: *mut ManagedTensorVersioned) -> Self

Creates a new SafeManagedTensorVersioned from a raw pointer.

§Safety

The caller must ensure that:

  • The pointer is valid and points to a properly initialized ManagedTensorVersioned
  • The pointer is not null
  • The tensor’s memory is managed by a valid deleter function
Source

pub unsafe fn from_non_null(ptr: DlpackVersioned) -> Self

Creates a new SafeManagedTensorVersioned from a NonNull pointer.

§Safety

The caller must ensure that:

  • The pointer is valid and points to a properly initialized ManagedTensorVersioned
  • The tensor’s memory is managed by a valid deleter function
Source

pub unsafe fn into_raw(self) -> *mut ManagedTensorVersioned

Converts the safe wrapper into a raw pointer, transferring ownership.

§Safety

The caller takes responsibility for managing the tensor’s memory after this call. The original wrapper is forgotten to prevent double-free.

Source

pub fn into_non_null(self) -> DlpackVersioned

Converts the safe wrapper into a NonNull pointer, transferring ownership.

The original wrapper is forgotten to prevent double-free.

Source

pub fn flags(&self) -> &Flags

Returns the tensor’s flags as an Option<Flags>. Returns None if the flags contain invalid bits.

Source

pub fn read_only(&self) -> bool

Returns whether the tensor is marked as read-only.

Source

pub fn is_copied(&self) -> bool

Returns whether the tensor is a copy of another tensor.

Source

pub fn is_subbtype_type_padded(&self) -> bool

Returns whether the tensor’s sub-byte type is padded.

Trait Implementations§

Source§

impl AsRef<SafeManagedTensorVersioned> for SafeManagedTensorVersioned

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Drop for SafeManagedTensorVersioned

Source§

fn drop(&mut self)

Implements the Drop trait to ensure proper cleanup of the managed tensor. When this wrapper is dropped, it calls the tensor’s deleter function if one exists.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl TensorView for SafeManagedTensorVersioned

Implements TensorView to provide access to the underlying DLPack tensor.

Source§

fn dl_tensor(&self) -> &Tensor

Returns a reference to the underlying DLPack tensor.

Source§

fn data_ptr(&self) -> *mut c_void

Returns a raw pointer to the tensor’s data. Read more
Source§

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

Returns a slice containing the tensor’s shape dimensions. Read more
Source§

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

Returns an optional slice containing the tensor’s strides. Read more
Source§

fn num_dimensions(&self) -> usize

Returns the number of dimensions in the tensor. Read more
Source§

fn num_elements(&self) -> usize

Returns the total number of elements in the tensor. Read more
Source§

fn data_type(&self) -> &DataType

Returns a reference to the tensor’s data type information. Read more
Source§

fn byte_offset(&self) -> usize

Returns the byte offset from the start of the data pointer. Read more
Source§

fn device(&self) -> &Device

Returns a reference to the tensor’s device. Read more
Source§

fn as_slice_untyped(&self) -> &[u8]

Returns a byte slice view of the tensor’s data. Read more
Source§

fn num_bytes(&self) -> usize

Source§

unsafe fn as_slice<A>(&self) -> Result<&[A]>

Returns a typed slice view of the tensor’s data. Read more
Source§

fn memory_order(&self) -> MemoryOrder

Determines the memory layout order of the tensor. Read more
Source§

fn as_slice_contiguous<A>(&self) -> Result<&[A]>

Returns a typed slice view of the tensor’s data, ensuring it’s contiguous. Read more

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.