Changed o3c.Tensor.arange signature to be like np.arange.#7095
Merged
ssheorey merged 2 commits intoisl-org:mainfrom Dec 16, 2024
Merged
Changed o3c.Tensor.arange signature to be like np.arange.#7095ssheorey merged 2 commits intoisl-org:mainfrom
ssheorey merged 2 commits intoisl-org:mainfrom
Conversation
|
Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes. |
ssheorey
approved these changes
Dec 16, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type
Motivation and Context
The current signatures of
open3d.core.Tensor.arangeare not valid:in the second signature,
starthas a default value but is beforestop.See The Python Language Reference:
This is how numpy defines arange:
(see https://github.com/numpy/numpy/blob/b3ddf2fd33232b8939f48c7c68a61c10257cd0c5/numpy/_core/multiarray.pyi#L769-L786)
Note how
startis not optional in the second signature.Here, optional is not needed, because the first overload handles that case.
Also, it adds
/, *,in the first signature and*,in the second./forces all args before to be positional-only and*forces all arguments after to be keyword-only.In pybind this can be achieved using
py::pos_only()andpy::kw_only().Checklist:
python util/check_style.py --applyto apply Open3D code styleto my code.
updated accordingly.
results (e.g. screenshots or numbers) here.
Description
This PR changes the signatures to (similar to numpy.arange):
There is already an unittest for
o3c.Tensor.arange:test_arangeinpython/test/core/test_core.pyThe test still succeeds with this change.
However, existing code might break if it does not use
dtypeordeviceas a keyword argument, e.g., like this:o3c.Tensor.arange(2, o3c.int64)This must now be written as:
o3c.Tensor.arange(2, dtype=o3c.int64)(which the unit test already does)
This is a fix used in #6917 since
mypywould complain about a syntax error in stubs generated bypybind11-stubgen:mypy examples/python/geometry/triangle_mesh_with_numpy.py /home/timohl/projects/Open3D/.venv/lib/python3.10/site-packages/open3d/cpu/pybind/core/__init__.pyi:732: error: non-default argument follows default argument [syntax] Found 1 error in 1 file (errors prevented further checking)