Skip to content

Add a dense-layout query for Tensor - #7604

Open
Fstarnb wants to merge 2 commits into
isl-org:mainfrom
Fstarnb:codex/open3d-7363-is-dense
Open

Fstarnb wants to merge 2 commits into
isl-org:mainfrom
Fstarnb:codex/open3d-7363-is-dense

Conversation

@Fstarnb

@Fstarnb Fstarnb commented Oct 18, 2026

Copy link
Copy Markdown

Type

Motivation and Context

Tensor::IsContiguous() intentionally means C-contiguous, so a tensor with a different axis order can still occupy one gap-free, non-overlapping memory span while returning false. This adds a separate query for that layout without changing existing IsContiguous() behavior.

Checklist

  • I have run python util/check_style.py --apply to apply Open3D code style.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ and Python API documentation are updated, including a Python usage example.
    • C++ and Python regression tests cover dense permutations, C-order layouts, negative strides, holes, overlap/broadcast, singleton dimensions, empty/scalar tensors, malformed metadata, and signed-span overflow.
  • I will follow up and update the code if CI fails.
  • For this fork PR, maintainers can edit the branch.

Description

Adds Tensor::IsDense() and Tensor.is_dense() to report non-overlapping tensors whose elements cover one contiguous span in any dimension order. Singleton strides are ignored; empty tensors and scalars are dense. Negative strides are checked by magnitude, with documentation warning that density alone does not make a forward memcpy safe. Spans outside Open3D's signed int64_t element/offset range are rejected.

Verification

Passed locally:

  • A standalone C++17 harness calling the implementation in Tensor.h, including the issue layout, negative strides, empty/scalar, holes, overlap, and overflow cases.
  • Syntax-only compilation of cpp/tests/core/Tensor.cpp with the generated Open3D compile flags.
  • Python syntax compilation of python/test/core/test_core.py.
  • Changed-line clang-format and YAPF checks, plus git diff --check.

The repository tests executable and Python runtime test were not run locally. The combined C++ test target begins by building Open3D's full VTK dependency chain, and the local build was stopped before reaching the test binary. Please use CI to validate the complete test matrix.

Preserve C-contiguous semantics while exposing non-overlapping dense layouts for any axis order. Add C++ and Python documentation and regression coverage for stride and layout edge cases.
@update-docs

update-docs Bot commented Oct 18, 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.

Record the new C++ and Python dense-layout queries under Main.
@Fstarnb

Fstarnb commented Oct 19, 2026

Copy link
Copy Markdown
Author

All GitHub Actions workflows for this PR currently show action_required, and no jobs have executed. The PR description documents the local test limitations, and Codacy passed. Could a maintainer approve the workflow runs when convenient so the full CI matrix can run?

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.

1 participant