Skip to content

Accept read-only NumPy arrays in Eigen vector constructors - #7607

Draft
timohl wants to merge 1 commit into
isl-org:mainfrom
timohl:fix/readonly-numpy-eigen-vectors
Draft

timohl wants to merge 1 commit into
isl-org:mainfrom
timohl:fix/readonly-numpy-eigen-vectors

Conversation

@timohl

@timohl timohl commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Type

Motivation and Context

A C-contiguous, correctly typed NumPy array with writeable=False currently raises ValueError: array is not writeable in an Eigen vector constructor, although the constructor only copies its input. For example:

import numpy as np
import open3d as o3d

points = np.array([[1., 2., 3.], [4., 5., 6.]], dtype=np.float64)
points.setflags(write=False)
vector = o3d.utility.Vector3dVector(points)
np.asarray(vector)[0] = [7., 8., 9.]
np.testing.assert_array_equal(points[0], [1., 2., 3.])
assert not points.flags.writeable

After this fix, construction succeeds and the vector remains independently owned and writable. The input values and readonly flag remain unchanged.

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

Use unchecked<2>() and Eigen::Map<const EigenVector> in all four array-to-vector conversion helpers. Preserve dtype conversion, contiguity handling from #7343, shape validation and copying semantics. Correct the shared double-helper comment and document readonly input in the example.

Add 60 parameterized cases across five public vector constructors, writable/readonly inputs, empty and C/Fortran/strided/reversed arrays, and dtype conversion. Tests check values, dtype, input flags, independent storage and mutation isolation; existing invalid-shape tests remain in place. The allocator helper variants receive the same const change; the tests exercise the public constructors rather than adding test-only bindings.

Plan and scope: restrict the fix to the copying bindings, demonstrate the readonly failure, then validate the rebuilt bindings and available CPU suites. No algorithm or ownership changes.

Validation

Windows x64 Release, VS2022/MSVC 19.44, Python 3.14.3, NumPy 2.4.6, rebuilt Open3D 0.20.0+306764175. Verified the package and native extension load from the build output.

  • Focused python/test/test_open3d_eigen.py: 99 passed, including all 60 new cases and the existing benchmark.
  • pytest python/test/ --ignore=python/test/ml_ops --randomly-seed=20261022: 625 passed, 15 skipped. Excluded ML operations because those bindings were not built. Skips cover Linux-only rendering, SYCL/GPU, RealSense, unavailable ML visualization, four existing dataset skips, and optional msgpack.
  • C++ gtest: 1,383 passed, 16 skipped, 0 failed (1,399 enabled tests); 200 existing disabled tests. Skips cover GPU/backend parity and the existing NYU loader test.
  • The standalone example above passes. Before rebuilding, the existing unpatched binary produced 10 readonly failures in the focused tests (88 passed; benchmark deselected).

Build includes Python bindings, C++ tests, GUI, ISPC and IPP. CUDA/SYCL, TensorFlow/PyTorch ops, bundled ML, WebRTC/Jupyter and camera SDKs were disabled. Tests used eight logical CPUs. Other operating systems and GPU configurations were not validated.

Use const accessors and Eigen maps in all four copying conversion helpers.
Preserve contiguity conversion and correct the shared double-vector comment.
Document read-only input and add parameterized tests for five constructors,
input layouts, dtype conversion, preserved input flags and independent storage.

Validation: pinned style checks, Python AST parsing and diff checks pass.
Against the existing unmodified binary, focused tests report 88 passes and
10 expected readonly-input failures. Rebuilt binding validation is pending;
no existing build was available. Related upstream report: isl-org#2557.
@update-docs

update-docs Bot commented Oct 22, 2026

Copy link
Copy Markdown

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot create pointcloud from numpy array, "array is not writeable"

1 participant