Skip to main content

validate_dlpack_tensor

Function validate_dlpack_tensor 

Source
pub fn validate_dlpack_tensor(
    tensor: &DLTensor,
) -> Result<DLTensorInfo, DlpackError>
Expand description

Validate a DLTensor and extract structured metadata.

This is the entry point for consuming tensors produced by DLPack-aware frameworks (PyTorch, JAX, CuPy, etc.). It checks that:

  • data is non-null,
  • the device type is parseable,
  • the dtype code is recognised.

On success, returns a DLTensorInfo with all metadata decoded.

ยงSafety

tensor.shape must point to at least tensor.ndim valid i64 values. The caller must ensure the tensor is not concurrently mutated.