Skip to main content

array_from_dlpack_f32

Function array_from_dlpack_f32 

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

Generic DLPack array construction — accepts f32 tensors from any framework.

Builds an ndarray view backed by the tensor’s data pointer. Only CPU tensors are supported; non-CPU tensors return DlpackError::NonCpuDevice.

§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 bytes of valid f32 values in native byte order.
  • The tensor remains live and unmodified for the lifetime of the returned view 'a.

§Errors

Returns DlpackError if the tensor is not CPU-resident or not f32.