Changed o3c.Tensor.arange signature to be like np.arange. #7095
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.arange
are not valid:in the second signature,
start
has 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
start
is 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 --apply
to 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_arange
inpython/test/core/test_core.py
The test still succeeds with this change.
However, existing code might break if it does not use
dtype
ordevice
as 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
mypy
would 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)