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:
datais 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.
§Examples
use scirs2_numpy::dlpack::{dlpack_from_slice, validate_dlpack_tensor, DLDataTypeCode};
let data = vec![1.0_f64, 2.0, 3.0];
let shape = vec![3_i64];
let tensor = dlpack_from_slice(&data, &shape);
let info = validate_dlpack_tensor(&tensor).unwrap();
assert_eq!(info.shape, vec![3_i64]);
assert_eq!(info.dtype_bits, 64);
assert_eq!(info.dtype_code, DLDataTypeCode::Float);