pub fn validate_torch_dlpack_tensor(
tensor: &DLTensor,
) -> Result<(), DlpackError>Expand description
Validate that a DLTensor is compatible with PyTorch DLPack interop.
Checks:
datapointer is non-null,- device type is CPU (
DLDeviceType::Cpu), - memory layout is C-order contiguous (null strides or row-major strides),
- dtype code is float (code 2),
- dtype bits are either 32 or 64.
Returns Ok(()) on success, or a DlpackError describing the first
unsatisfied constraint.
ยงExamples
use scirs2_numpy::dlpack::{dlpack_from_slice, validate_torch_dlpack_tensor};
let data = vec![1.0_f64, 2.0, 3.0];
let shape = vec![3_i64];
let tensor = dlpack_from_slice(&data, &shape);
assert!(validate_torch_dlpack_tensor(&tensor).is_ok());