Skip to content

Fix Tensor.nonzero as_tuple behavior - #7536

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

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

Conversation

@fallenmi

@fallenmi fallenmi commented Aug 15, 2026 •

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

  • Open3D code style was checked for the changed C++ and Python files with the repository-pinned formatter versions.
  • This PR changes Open3D behavior.
    • The injected Python documentation and tensor tutorial are updated accordingly.
    • The Python regression covers the default, explicit False, and True paths.
  • CI failures will be investigated and the patch updated if they are caused by this change.
  • Allow edits from maintainers is enabled for this fork PR.

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 the focused behavior and patch integrity.

Validation recorded for the original branch 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.

Rebase validation on 2026-08-25:

  • Rebased from aab533f onto 22a6a30 and resolved only the additive CHANGELOG.md conflict.
  • The implementation, test, and notebook blobs exactly match the originally validated patch; their stable combined patch ID is unchanged.
  • Focused clang-format 18, YAPF 0.43, Python syntax, notebook schema, and regression-structure checks passed.
  • git diff --check passed.

AI assistance disclosure: OpenAI Codex investigated, implemented, rebased, and validated this change. The GitHub account owner explicitly authorized publication and automated branch and pull-request updates.

@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

@fallenmi
fallenmi force-pushed the agent/fix-nonzero-as-tuple branch from 39cd112 to b94c64a Compare August 25, 2026 12:46
@fallenmi
fallenmi marked this pull request as ready for review August 25, 2026 12:47
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