From 63bb7c2946ab83aa648d6a5cb19d4afc18028f36 Mon Sep 17 00:00:00 2001 From: MegChai Date: Wed, 3 Nov 2021 16:59:47 +0800 Subject: [PATCH] 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 --- .../python/megengine/functional/tensor.py | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/imperative/python/megengine/functional/tensor.py b/imperative/python/megengine/functional/tensor.py index 0d17a6f3a..a0a08db36 100755 --- a/imperative/python/megengine/functional/tensor.py +++ b/imperative/python/megengine/functional/tensor.py @@ -1069,32 +1069,36 @@ def arange( dtype="float32", device: Optional[CompNode] = None, ) -> 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: - start: starting value of the squence, shoule be scalar. - stop: ending value of the squence, shoule be scalar. - step: gap between each pair of adjacent values. Default: 1 - dtype: result data type. + Note: + This function cannot guarantee that the interval does not include the stop value in those cases + where step is not an integer and floating-point rounding errors affect the length of the output tensor. - Returns: - generated tensor. + Args: + 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:: - - import numpy as np - import megengine.functional as F + Returns: + A one-dimensional tensor containing evenly spaced values. - a = F.arange(5) - print(a.numpy()) + The length of the output tensor must be ``ceil((stop-start)/step)`` + 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: start, stop = 0, start -- GitLab