Skip to content

Fix Tensor.nonzero as_tuple behavior - #7536

Draft
fallenmi wants to merge 2 commits into
isl-org:mainfrom
fallenmi:agent/fix-nonzero-as-tuple
Draft

Fix Tensor.nonzero as_tuple behavior#7536
fallenmi wants to merge 2 commits into
isl-org:mainfrom
fallenmi:agent/fix-nonzero-as-tuple

Conversation

@fallenmi

Copy link
Copy Markdown

Type

Motivation and Context

Tensor.nonzero() called its two existing core methods from the opposite as_tuple branches. As a result, the default and explicit False returned a per-dimension list, while True returned a single tensor.

This restores the branch mapping that existed before the pure-C++ pybind rewrite. It intentionally preserves Open3D's existing [num_dims, num_non_zeros] tensor orientation and the historical per-dimension list behavior. Changing the orientation or introducing a literal Python tuple is outside this bug fix.

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

Plan summary:

  1. Lock the documented historical branch contract.
  2. Add a regression for the default, explicit False, and True paths.
  3. Swap only the existing NonZero and NonZeroNumpy calls.
  4. Align the injected Python documentation and tutorial output.
  5. Validate with a clean CPU/Python build and core tests.

Validation on macOS arm64 with AppleClang 21 and Python 3.14:

  • RED on main: the focused regression failed because the default path returned a list.
  • Release CPU/Python package build: 722/722 build steps completed.
  • Focused regression: 1 passed.
  • python/test/core/test_core.py: 279 passed.
  • Broader core test set: 359 passed, 1 skipped.
  • python util/check_style.py --apply --no_parallel: passed.
  • git diff --check: passed.

AI assistance disclosure: OpenAI Codex helped investigate and draft this change. I reproduced the regression, reviewed every changed line, and ran the validation above.

@update-docs

update-docs Bot commented Aug 15, 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.

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

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.

inconsistent behavior of as_tuple in nonzero method between open3d and pytorch

1 participant