pub struct DLPackCapsule { /* private fields */ }Expand description
Python class wrapping a DLPack-compatible tensor.
Exposes __dlpack__ and __dlpack_device__ so that any DLPack-aware
framework (PyTorch, JAX, CuPy, etc.) can consume the tensor without copying.
Implementations§
Source§impl DLPackCapsule
impl DLPackCapsule
Sourcepub fn new(shape: Vec<i64>, dtype_code: u8, dtype_bits: u8) -> Self
pub fn new(shape: Vec<i64>, dtype_code: u8, dtype_bits: u8) -> Self
Create a new zero-filled DLPack capsule.
§Arguments
shape– tensor dimensionsdtype_code– element type code (0=int, 1=uint, 2=float, 3=bfloat)dtype_bits– element bit-width (e.g. 32 or 64)
Sourcepub fn dlpack_device(&self) -> (i32, i32)
pub fn dlpack_device(&self) -> (i32, i32)
Return (device_type_int, device_id) — the __dlpack_device__ protocol.
Sourcepub fn dlpack<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyCapsule>>
pub fn dlpack<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyCapsule>>
Return a Python PyCapsule named "dltensor" — the __dlpack__ protocol.
The capsule contains a DLManagedTensor with a destructor that frees the
heap allocation created here.
§Safety
The capsule pointer is valid as long as the capsule is live. The deleter
registered in DLManagedTensor ensures the allocation is freed.
Sourcepub fn dtype_code(&self) -> u8
pub fn dtype_code(&self) -> u8
Return the dtype type-code (0=int, 1=uint, 2=float, 3=bfloat).
Sourcepub fn dtype_bits(&self) -> u8
pub fn dtype_bits(&self) -> u8
Return the number of bits per element.
Trait Implementations§
Source§impl<'py> IntoPyObject<'py> for DLPackCapsule
impl<'py> IntoPyObject<'py> for DLPackCapsule
Source§type Target = DLPackCapsule
type Target = DLPackCapsule
Source§type Output = Bound<'py, <DLPackCapsule as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <DLPackCapsule as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for DLPackCapsule
impl PyClass for DLPackCapsule
Source§impl PyClassImpl for DLPackCapsule
impl PyClassImpl for DLPackCapsule
Source§const MODULE: Option<&str> = ::core::option::Option::None
const MODULE: Option<&str> = ::core::option::Option::None
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// Python class wrapping a DLPack-compatible tensor.
///
/// Exposes `__dlpack__` and `__dlpack_device__` so that any DLPack-aware
/// framework (PyTorch, JAX, CuPy, etc.) can consume the tensor without copying.
const RAW_DOC: &'static CStr = /// Python class wrapping a DLPack-compatible tensor. /// /// Exposes `__dlpack__` and `__dlpack_device__` so that any DLPack-aware /// framework (PyTorch, JAX, CuPy, etc.) can consume the tensor without copying.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type Layout = <<DLPackCapsule as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<DLPackCapsule>
type Layout = <<DLPackCapsule as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<DLPackCapsule>
Source§type ThreadChecker = NoopThreadChecker
type ThreadChecker = NoopThreadChecker
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
Source§fn dict_offset() -> Option<PyObjectOffset>
fn dict_offset() -> Option<PyObjectOffset>
Source§fn weaklist_offset() -> Option<PyObjectOffset>
fn weaklist_offset() -> Option<PyObjectOffset>
Source§impl PyClassNewTextSignature for DLPackCapsule
impl PyClassNewTextSignature for DLPackCapsule
const TEXT_SIGNATURE: &'static str = "(shape, dtype_code, dtype_bits)"
Source§impl PyMethods<DLPackCapsule> for PyClassImplCollector<DLPackCapsule>
impl PyMethods<DLPackCapsule> for PyClassImplCollector<DLPackCapsule>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for DLPackCapsule
impl PyTypeInfo for DLPackCapsule
Source§const NAME: &str = <Self as ::pyo3::PyClass>::NAME
const NAME: &str = <Self as ::pyo3::PyClass>::NAME
prefer using ::type_object(py).name() to get the correct runtime value
Source§const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE
const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE
prefer using ::type_object(py).module() to get the correct runtime value
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
impl DerefToPyAny for DLPackCapsule
impl ExtractPyClassWithClone for DLPackCapsule
Auto Trait Implementations§
impl Freeze for DLPackCapsule
impl RefUnwindSafe for DLPackCapsule
impl Send for DLPackCapsule
impl Sync for DLPackCapsule
impl Unpin for DLPackCapsule
impl UnsafeUnpin for DLPackCapsule
impl UnwindSafe for DLPackCapsule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
Source§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
Source§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
Use ::classinfo_object() instead and format the type name at runtime. Note that using built-in cast features is often better than manual PyTypeCheck usage.
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.