feat: Zero-Copy Data Transfer with rust-numpy#73
Conversation
Validation Successful!This pull request has been verified and linked to issue #17. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes. |
1 similar comment
Validation Successful!This pull request has been verified and linked to issue #17. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes. |
|
Thank you for opening this PR! Our automated system is currently verifying the PR requirements. |
There was a problem hiding this comment.
Pull request overview
This PR replaces Python list-based data conversion with numpy array buffer access at the Python-Rust boundary. The implementation uses the rust-numpy crate to accept PyReadonlyArray2<f32> parameters instead of PyList, eliminating the need for element-by-element Python object extraction. The Python preprocessing layer now returns numpy arrays directly, and the API layer ensures contiguous float32 memory layout before passing data to Rust.
Changes:
- Added
numpy = 0.27dependency to enable numpy array integration with pyo3 - Replaced
pylist_to_vec2(PyList)withndarray_to_vec2(PyReadonlyArray2)for bulk row conversion - Updated Python preprocessing and API to return/pass numpy arrays instead of converting to lists
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| etna_core/Cargo.toml | Added rust-numpy 0.27 dependency for PyReadonlyArray2 support |
| etna_core/src/lib.rs | Replaced PyList-based conversion with ndarray-based bulk copy; removed PyList import |
| etna/preprocessing.py | Returns numpy arrays directly instead of calling .tolist() |
| etna/api.py | Ensures contiguous float32 arrays via np.ascontiguousarray before Rust calls |
| tests/test_tqdm_progress.py | Fixed mock patching to ensure reloaded module uses mock extension |
| Cargo.lock | Added transitive dependencies for numpy crate (ndarray, matrixmultiply, num-*, etc.) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Validation Successful!This pull request has been verified and linked to issue #17. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes. |
d685029 to
f985953
Compare
Validation Successful!This pull request has been verified and linked to issue #17. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes. |
Aamod007
left a comment
There was a problem hiding this comment.
@verdhanyash Good work.
Validation Successful!This pull request has been verified and linked to issue #17. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes. |
1c187e2 to
21851d2
Compare
Validation Successful!This pull request has been verified and linked to issue #17. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes. |
1 similar comment
Validation Successful!This pull request has been verified and linked to issue #17. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes. |
3c76372 to
cc1b552
Compare
Validation Successful!This pull request has been verified and linked to issue #17. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes. |
Replace pylist_to_vec2 with numpy::PyReadonlyArray2 for zero-copy buffer access at the Python-Rust bridge. Eliminates per-element Python object extraction and .tolist() overhead. Changes: - etna_core/Cargo.toml: added numpy = 0.27 dependency - etna_core/src/lib.rs: replaced pylist_to_vec2/PyList with ndarray_to_vec2/PyReadonlyArray2 - etna/preprocessing.py: return numpy arrays instead of .tolist() - etna/api.py: pass contiguous float32 arrays directly to Rust - tests/test_tqdm_progress.py: fixed mock patching for compiled extension
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Validation Successful!This pull request has been verified and linked to issue #17. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes. |
Aamod007
left a comment
There was a problem hiding this comment.
Great Work @verdhanyash !
|
This PR has been successfully merged. We appreciate your effort in improving the library and look forward to your future contributions to the Etsi AI ecosystem. |
Summary
Implements zero-copy data transfer between Python (NumPy) and Rust using
rust-numpy'sPyReadonlyArray2. This eliminates thepylist_to_vec2bottleneck that iterated over Python list objects one element at a time, replacing it with direct buffer access to NumPy's contiguous memory.Closes #17
Changes
Rust Core
lib.rs: Replacedpylist_to_vec2(&Bound<'_, PyList>)withndarray_to_vec2(PyReadonlyArray2<f32>)lib.rs: Updatedtrain()andpredict()signatures to acceptPyReadonlyArray2<'_, f32>Cargo.toml: Addednumpy = 0.27dependencyPython API
api.py: Passes contiguousfloat32NumPy arrays directly to Rust (no.tolist()conversion)preprocessing.py: Returns NumPy arrays fromfit_transform()andtransform()instead of.tolist()Testing
test_tqdm_progress.pymock patching to work alongside compiled Rust extensionBefore vs After
Before:
After:
Acceptance Criteria
lib.rspylist_to_vec2andPyListcompletely removedScreenshots