From c053d00b4cf1fde35364e539d823d708ee0aec0a Mon Sep 17 00:00:00 2001 From: Khizar1 <11738208+Khizar1@users.noreply.github.com> Date: Sun, 12 Oct 2025 15:58:16 +0000 Subject: [PATCH 1/3] Handle non c-contagious numpy arrays efficiently in py_array_to_vectors_* --- cpp/pybind/utility/eigen.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/cpp/pybind/utility/eigen.cpp b/cpp/pybind/utility/eigen.cpp index dd480d2cd78..b8e5981717b 100644 --- a/cpp/pybind/utility/eigen.cpp +++ b/cpp/pybind/utility/eigen.cpp @@ -36,7 +36,12 @@ py::class_ bind_vector_without_repr( // bindings for each py array types. template std::vector py_array_to_vectors_double( - py::array_t array) { + py::array_t array) { // remove the restrictive flags here + // Ensure array is contiguous (C-style) + if (!(array.flags() & (py::array::c_style))) { + // Make a contiguous copy if necessary + array = py::array_t(array); + } int64_t eigen_vector_size = EigenVector::SizeAtCompileTime; if (array.ndim() != 2 || array.shape(1) != eigen_vector_size) { throw py::cast_error(); @@ -54,7 +59,10 @@ std::vector py_array_to_vectors_double( template std::vector py_array_to_vectors_int( - py::array_t array) { + py::array_t array) { + if (!(array.flags() & (py::array::c_style))) { + array = py::array_t(array); + } int64_t eigen_vector_size = EigenVector::SizeAtCompileTime; if (array.ndim() != 2 || array.shape(1) != eigen_vector_size) { throw py::cast_error(); @@ -71,7 +79,10 @@ template > std::vector py_array_to_vectors_int_eigen_allocator( - py::array_t array) { + py::array_t array) { + if (!(array.flags() & (py::array::c_style))) { + array = py::array_t(array); + } int64_t eigen_vector_size = EigenVector::SizeAtCompileTime; if (array.ndim() != 2 || array.shape(1) != eigen_vector_size) { throw py::cast_error(); @@ -88,7 +99,10 @@ template > std::vector py_array_to_vectors_int64_eigen_allocator( - py::array_t array) { + py::array_t array) { + if (!(array.flags() & (py::array::c_style))) { + array = py::array_t(array); + } int64_t eigen_vector_size = EigenVector::SizeAtCompileTime; if (array.ndim() != 2 || array.shape(1) != eigen_vector_size) { throw py::cast_error(); From 31b2ba65a17c1442e75cf1da7b076f6dec4f16e4 Mon Sep 17 00:00:00 2001 From: Khizar1 <11738208+Khizar1@users.noreply.github.com> Date: Sun, 12 Oct 2025 17:16:11 +0000 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff978597cd5..3d293b132a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). - Corrected documentation for Link Open3D in C++ projects (broken links). - Fix DLLs not being found in Python-package. Also prevent PATH from being searched for DLLs, except CUDA (PR #7108) - Fix MSAA sample count not being copied when FilamentView is copied From 07edf669b6f119f3de4eb1902f8e1b9539cbc2bd Mon Sep 17 00:00:00 2001 From: Khizar1 <11738208+Khizar1@users.noreply.github.com> Date: Fri, 31 Oct 2025 05:33:19 +0000 Subject: [PATCH 3/3] Apply check_style.py to pybind/utility/eigen.cpp --- cpp/pybind/utility/eigen.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cpp/pybind/utility/eigen.cpp b/cpp/pybind/utility/eigen.cpp index b8e5981717b..87d055cf4bd 100644 --- a/cpp/pybind/utility/eigen.cpp +++ b/cpp/pybind/utility/eigen.cpp @@ -58,8 +58,7 @@ std::vector py_array_to_vectors_double( } template -std::vector py_array_to_vectors_int( - py::array_t array) { +std::vector py_array_to_vectors_int(py::array_t array) { if (!(array.flags() & (py::array::c_style))) { array = py::array_t(array); } @@ -78,8 +77,7 @@ std::vector py_array_to_vectors_int( template > std::vector -py_array_to_vectors_int_eigen_allocator( - py::array_t array) { +py_array_to_vectors_int_eigen_allocator(py::array_t array) { if (!(array.flags() & (py::array::c_style))) { array = py::array_t(array); } @@ -98,8 +96,7 @@ py_array_to_vectors_int_eigen_allocator( template > std::vector -py_array_to_vectors_int64_eigen_allocator( - py::array_t array) { +py_array_to_vectors_int64_eigen_allocator(py::array_t array) { if (!(array.flags() & (py::array::c_style))) { array = py::array_t(array); }