- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.5k
 
Fix: Improve performance for non-contiguous NumPy arrays in pybind vector converters #7343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix: Improve performance for non-contiguous NumPy arrays in pybind vector converters #7343
Conversation
| 
           Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a performance bottleneck when converting non-contiguous NumPy arrays (e.g., from Pandas DataFrames) to Open3D vector types. The fix removes restrictive compile-time flags and uses runtime contiguity checks instead, achieving up to 50× speedup for non-contiguous inputs while maintaining identical behavior for contiguous arrays.
Key Changes:
- Modified four conversion functions to perform runtime contiguity checks instead of compile-time enforcement
 - Non-contiguous arrays now trigger a single fast NumPy copy instead of slow element-by-element deep copies
 - Updated CHANGELOG to document the performance improvement
 
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description | 
|---|---|
| cpp/pybind/utility/eigen.cpp | Replaced static py::array::c_style flags with runtime contiguity checks in py_array_to_vectors_double, py_array_to_vectors_int, py_array_to_vectors_int_eigen_allocator, and py_array_to_vectors_int64_eigen_allocator | 
| CHANGELOG.md | Added entry documenting the performance fix for non-contiguous NumPy array conversion | 
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,4 +1,5 @@ | |||
| ## Main | |||
| - Fix performance for non-contiguous NumPy array conversion in pybind vector converters. This change removes restrictive `py::array::c_style` flags and adds a runtime contiguity check, improving Pandas-to-Open3D conversion speed by up to ~50×. (issue #5250)(PR #7343). | |||
    
      
    
      Copilot
AI
    
    
    
      Oct 30, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Add a space between '(issue #5250)' and '(PR #7343)' for consistency with formatting in other changelog entries.
| - Fix performance for non-contiguous NumPy array conversion in pybind vector converters. This change removes restrictive `py::array::c_style` flags and adds a runtime contiguity check, improving Pandas-to-Open3D conversion speed by up to ~50×. (issue #5250)(PR #7343). | |
| - Fix performance for non-contiguous NumPy array conversion in pybind vector converters. This change removes restrictive `py::array::c_style` flags and adds a runtime contiguity check, improving Pandas-to-Open3D conversion speed by up to ~50×. (issue #5250) (PR #7343). | 
| 
           @ssheorey I have fixed styling in   | 
    
…rs_*
Type
Motivation and Context
This PR fixes slow performance when constructing Open3D vectors (Vector3dVector) from non-contiguous NumPy arrays, such as Pandas DataFrames. Previously, pybind11 performed slow element-by-element deep copies due to the restrictive
py::array::c_styleflag inpy_array_to_vectors_*. This change relaxes that restriction and performs a lightweight runtime check instead:Up to ~50× faster conversion for non-contiguous arrays. Please refer to benchmark results below.
Checklist:
python util/check_style.py --applyto apply Open3D code styleto my code.
updated accordingly.
results (e.g. screenshots or numbers) here.
Description
This PR improves array conversion performance in
cpp/pybind/utility/eigen.cppby replacingthe static
py::array::c_styleflag with a runtime check for contiguity.Summary of Changes
py_array_to_vectors_double,py_array_to_vectors_int,py_array_to_vectors_int_eigen_allocatorandpy_array_to_vectors_int64_eigen_allocatorto:array.flags()).Benchmark Results
Reproducible script: benchmark_all_vectors.py
Tested on Ubuntu 24.04, Python 3.12 inside a Docker environment.