11 unstable releases (3 breaking)
Uses new Rust 2024
| 0.4.1 | Jul 27, 2026 |
|---|---|
| 0.3.1 | Jun 12, 2026 |
| 0.1.4 | Mar 10, 2026 |
| 0.1.0 | Dec 1, 2025 |
#87 in Machine learning
15,644 downloads per month
Used in 7 crates
(6 directly)
160KB
3K
SLoC
DLPack integration for Rust.
This crate provides wrappers around the DLPack C API, allowing to exchange tensors with other libraries that support DLPack, such as PyTorch, TensorFlow, MXNet, CuPy, JAX, etc.
The C API is available in the sys module, and the following higher-level
wrappers are provided:
DLPackTensor: an owned DLPack tensorDLPackTensorRef: a borrowed DLPack tensor (immutable)DLPackTensorRefMut: a borrowed DLPack tensor (mutable)
We also provide tools to convert from and to other rust types, using the
TryFrom trait. Conversions to and from std::vec::Vec and slices are
always enabled, in the [vec] module.
Features
sync: enable sharing data behindArc<Mutex<_>>andArc<RwLock<_>>with DLPack, enforcing Rust's borrowing rules at runtime through the locks.ndarray: enable conversion from and tondarray::Arraypyo3: enable passing data from and to python, following the dlpack protocol (the data is passed through aPyCapsuleobject).
dlpk: DLPack integration for Rust
This crate contains a direct translation of the C header for DLPack, which is intended to be used inside Rust projects that want to offer a C API.
We also provide some tools to convert to and from other types, through the following cargo features:
ndarrayto convert from and tondarray::Arraypyo3to convert from and to Python data, following the python specification for dlpack
Conversions to and from std::vec::Vec and slice are always enabled.
License
This crate is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
Dependencies
~0–1.5MB
~30K SLoC