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
impl SafeManagedTensorVersioned
Sourcepub fn new<T, L>(t: T) -> Result<Self, T::Error>where
T: TensorLike<L>,
L: MemoryLayout,
pub fn new<T, L>(t: T) -> Result<Self, T::Error>where
T: TensorLike<L>,
L: MemoryLayout,
Sourcepub fn with_flags<T, L>(t: T, flags: Flags) -> Result<Self, T::Error>where
T: TensorLike<L>,
L: MemoryLayout,
pub fn with_flags<T, L>(t: T, flags: Flags) -> Result<Self, T::Error>where
T: TensorLike<L>,
L: MemoryLayout,
Sourcepub unsafe fn from_raw(ptr: *mut ManagedTensorVersioned) -> Self
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
Sourcepub unsafe fn from_non_null(ptr: DlpackVersioned) -> Self
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
Sourcepub unsafe fn into_raw(self) -> *mut ManagedTensorVersioned
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.
Sourcepub fn into_non_null(self) -> DlpackVersioned
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.
Sourcepub fn flags(&self) -> &Flags
pub fn flags(&self) -> &Flags
Returns the tensor’s flags as an Option<Flags>.
Returns None if the flags contain invalid bits.
Sourcepub fn is_subbtype_type_padded(&self) -> bool
pub fn is_subbtype_type_padded(&self) -> bool
Returns whether the tensor’s sub-byte type is padded.
Trait Implementations§
Source§impl Drop for SafeManagedTensorVersioned
impl Drop for SafeManagedTensorVersioned
Source§impl TensorView for SafeManagedTensorVersioned
Implements TensorView to provide access to the underlying DLPack tensor.
impl TensorView for SafeManagedTensorVersioned
Implements TensorView to provide access to the underlying DLPack tensor.