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 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();