Expand description
Conversion between DLPack and ndarray, this module requires the ndarray
feature to be enabled.
The following conversions are supported:
DLPackTensor=>ndarray::Array(makes a copy of the data)DLPackTensor=>ndarray::ArcArray(makes a copy of the data)DLPackTensorRef=>ndarray::ArrayViewDLPackTensorRefMut=>ndarray::ArrayViewMutndarray::Array=>DLPackTensor&ndarray::Array=>DLPackTensorRef&mut ndarray::Array=>DLPackTensorRefMutndarray::ArrayView=>DLPackTensorRefndarray::ArrayViewMut=>DLPackTensorRefMutndarray::ArcArray=>DLPackTensor(share data, but creates a read-only DLPackTensor)&ndarray::ArcArray=>DLPackTensorRef
§Examples
use dlpk::{DLPackTensor, DLPackTensorRef};
let tensor: DLPackTensor = get_tensor_from_somewhere();
// makes a copy of the data
let array: ndarray::ArrayD<f32> = tensor.try_into().unwrap();
// no copy, share data with the original tensor
let tensor: DLPackTensor = get_tensor_from_somewhere();
let tensor_ref: DLPackTensorRef = tensor.as_ref();
let reference: ndarray::ArrayView2<f32> = tensor_ref.try_into().unwrap();
// convert an ndarray array into a DLPack tensor
let array = ndarray::Array::from_elem((2, 3), 1.0f32);
let tensor: DLPackTensor = array.clone().try_into().unwrap();
let tensor_ref: DLPackTensorRef = (&array).try_into().unwrap();Modules§
- sync
- This module provides conversions between
Arc<Mutex<Array<T, D>>>andArc<RwLock<Array<T, D>>>toDLPackTensor, allowing you to share data between Rust and DLPack while ensuring that the data is not modified by Rust while it’s used by DLPack and reciprocally. The locks will be held until theDLPackTensoris dropped, ensuring safe access to the data.
Enums§
- DLPackN
Darray Error - Possible error causes when converting between ndarray and DLPack
Traits§
- DimFrom
Vec - Internal trait that will convert a
Vec<usize>into one of ndarray’s Dim type.