提交 63bb7c29 编写于 作者: M MegChai 提交者: Megvii Engine Team

docs(mge/functional): update functional.arange docstring

From GITHUB 386

COPYBARA_INTEGRATE_REVIEW=https://github.com/MegEngine/MegEngine/pull/386 from MegChai:docstring-arange 6702c6a5cd11d780f3f75e6cdbe481b05ff30e95
Closes #386
GitOrigin-RevId: e27cdaefe8571e611133c911865f3b06fdc2702a
上级 89ed7ab2
...@@ -1069,32 +1069,36 @@ def arange( ...@@ -1069,32 +1069,36 @@ def arange(
dtype="float32", dtype="float32",
device: Optional[CompNode] = None, device: Optional[CompNode] = None,
) -> Tensor: ) -> Tensor:
r"""Returns a tensor with values from start to stop with adjacent interval step. r"""Returns evenly spaced values within the half-open interval ``[start, stop)`` as a one-dimensional tensor.
Args: Note:
start: starting value of the squence, shoule be scalar. This function cannot guarantee that the interval does not include the stop value in those cases
stop: ending value of the squence, shoule be scalar. where step is not an integer and floating-point rounding errors affect the length of the output tensor.
step: gap between each pair of adjacent values. Default: 1
dtype: result data type.
Returns: Args:
generated tensor. start: if ``stop`` is specified, the start of interval (inclusive); otherwise,
the end of the interval (exclusive). If ``stop`` is not specified, the default starting value is ``0``.
stop: the end of the interval. Default: ``None``.
step: the distance between two adjacent elements ( ``out[i+1] - out[i]`` ). Must not be 0 ;
may be negative, this results i an empty tensor if stop >= start . Default: 1 .
Examples: Keyword args:
dtype( :attr:`.Tensor.dtype` ): output tensor data type. Default: ``float32``.
device( :attr:`.Tensor.device` ): device on which to place the created tensor. Default: ``None``.
.. testcode:: Returns:
A one-dimensional tensor containing evenly spaced values.
import numpy as np
import megengine.functional as F
a = F.arange(5) The length of the output tensor must be ``ceil((stop-start)/step)``
print(a.numpy()) if ``stop - start`` and ``step`` have the same sign, and length 0 otherwise.
Outputs: Examples:
.. testoutput:: >>> F.arange(5)
Tensor([0. 1. 2. 3. 4.], device=xpux:0)
>>> F.arange(1, 4)
Tensor([1. 2. 3.], device=xpux:0)
[0. 1. 2. 3. 4.]
""" """
if stop is None: if stop is None:
start, stop = 0, start start, stop = 0, start
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册