Skip to main content

check_tensor_contiguous

Function check_tensor_contiguous 

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

Check that a DLTensor’s strides represent a C-order (row-major) contiguous layout.

A tensor is contiguous if its strides pointer is null (which is the DLPack convention for C-contiguous tensors) or if the non-null strides match the row-major pattern: strides[i] == product(shape[i+1..]).

Returns Ok(()) when contiguous, Err(DlpackError::NonContiguous) otherwise.

§Safety

When tensor.strides is non-null, it must be valid for tensor.ndim elements. When tensor.shape is non-null, it must be valid for tensor.ndim elements.