Skip to content

Commit e0f5cdf

Browse files
authored
Changed Tensor.arange signature to be like in numpy. (#7095)
1 parent 81201f9 commit e0f5cdf

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

cpp/pybind/core/tensor.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -394,22 +394,22 @@ void pybind_core_tensor_definitions(py::module& m) {
394394
},
395395
"Create a 1D tensor with evenly spaced values in the given "
396396
"interval.",
397-
"stop"_a, "dtype"_a = py::none(), "device"_a = py::none());
397+
"stop"_a, py::pos_only(), py::kw_only(), "dtype"_a = py::none(),
398+
"device"_a = py::none());
398399
tensor.def_static(
399400
"arange",
400-
[](utility::optional<int64_t> start, int64_t stop,
401-
utility::optional<int64_t> step, utility::optional<Dtype> dtype,
401+
[](int64_t start, int64_t stop, utility::optional<int64_t> step,
402+
utility::optional<Dtype> dtype,
402403
utility::optional<Device> device) {
403404
return Tensor::Arange(
404-
start.has_value() ? start.value() : 0, stop,
405-
step.has_value() ? step.value() : 1,
405+
start, stop, step.has_value() ? step.value() : 1,
406406
dtype.has_value() ? dtype.value() : core::Int64,
407407
device.has_value() ? device.value() : Device("CPU:0"));
408408
},
409409
"Create a 1D tensor with evenly spaced values in the given "
410410
"interval.",
411-
"start"_a = py::none(), "stop"_a, "step"_a = py::none(),
412-
"dtype"_a = py::none(), "device"_a = py::none());
411+
"start"_a, "stop"_a, "step"_a = py::none(), "dtype"_a = py::none(),
412+
py::kw_only(), "device"_a = py::none());
413413

414414
// Tensor creation from arange for float.
415415
tensor.def_static(
@@ -423,22 +423,22 @@ void pybind_core_tensor_definitions(py::module& m) {
423423
},
424424
"Create a 1D tensor with evenly spaced values in the given "
425425
"interval.",
426-
"stop"_a, "dtype"_a = py::none(), "device"_a = py::none());
426+
"stop"_a, py::pos_only(), py::kw_only(), "dtype"_a = py::none(),
427+
"device"_a = py::none());
427428
tensor.def_static(
428429
"arange",
429-
[](utility::optional<double> start, double stop,
430-
utility::optional<double> step, utility::optional<Dtype> dtype,
430+
[](double start, double stop, utility::optional<double> step,
431+
utility::optional<Dtype> dtype,
431432
utility::optional<Device> device) {
432433
return Tensor::Arange(
433-
start.has_value() ? start.value() : 0.0, stop,
434-
step.has_value() ? step.value() : 1.0,
434+
start, stop, step.has_value() ? step.value() : 1.0,
435435
dtype.has_value() ? dtype.value() : core::Float64,
436436
device.has_value() ? device.value() : Device("CPU:0"));
437437
},
438438
"Create a 1D tensor with evenly spaced values in the given "
439439
"interval.",
440-
"start"_a = py::none(), "stop"_a, "step"_a = py::none(),
441-
"dtype"_a = py::none(), "device"_a = py::none());
440+
"start"_a, "stop"_a, "step"_a = py::none(), "dtype"_a = py::none(),
441+
py::kw_only(), "device"_a = py::none());
442442

443443
tensor.def(
444444
"append",

0 commit comments

Comments
 (0)