Skip to main content

dlarray_from_torch_f32

Function dlarray_from_torch_f32 

Source
pub unsafe fn dlarray_from_torch_f32<'a>(
    tensor: *const DLTensor,
) -> Result<ArrayViewD<'a, f32>, DlpackError>
Expand description

Convert a raw DLTensor pointer (from a PyTorch DLPack capsule) to an ndarray dynamic array view of f32 elements.

§Safety

The caller must guarantee that:

  • tensor is a valid, aligned, non-null pointer to a DLTensor.
  • The tensor’s data field points to at least product(shape) * 4 valid bytes of f32 values in native byte order.
  • The tensor (and its data) remains live and unmodified for the lifetime of the returned view 'a.

§Errors

Returns DlpackError if the tensor is not a 32-bit float CPU tensor.