Fix: Improve performance for non-contiguous NumPy arrays in pybind vector converters #7343
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…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_style
flag 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 --apply
to 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.cpp
by replacingthe static
py::array::c_style
flag 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_allocator
andpy_array_to_vectors_int64_eigen_allocator
to:array.flags()
).Benchmark Results
Reproducible script: benchmark_all_vectors.py
Tested on Ubuntu 24.04, Python 3.12 inside a Docker environment.