Skip to main content

from_dlpack

Function from_dlpack 

Source
pub fn from_dlpack(
    py: Python<'_>,
    capsule: &Bound<'_, PyAny>,
) -> PyResult<Py<PyAny>>
Expand description

Convert a DLPack capsule (from PyTorch, JAX, CuPy, TensorFlow, …) into a scirs2 NumPy-compatible array.

§Parameters

capsule : PyCapsule A PyCapsule object whose name is "dltensor". Anything that implements __dlpack__() can produce such an object.

§Returns

numpy.ndarray A 1-D float64 NumPy array whose contents are copied from the DLPack tensor. Only CPU, float32, and float64 tensors are currently supported; all other dtypes raise TypeError.

§Notes

GPU tensors raise TypeError until an optional gpu feature is enabled. The capsule is renamed to "used_dltensor" after consumption to prevent double-frees, consistent with the DLPack 1.0 spec.