MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / linspace

Function linspace

python/paddle/tensor/creation.py:334–553  ·  view source on GitHub ↗

r""" Return fixed number of evenly spaced values within a given interval. Note: no gradient calculation is performed. Args: start(int|float|Tensor): The input :attr:`start` is start of range. It is a int, float, \ or a 0-D Tensor with data type int32, int64, float32 or f

(
    start: float | paddle.Tensor,
    stop: float | paddle.Tensor,
    num: int | paddle.Tensor,
    dtype: DTypeLike | None = None,
    name: str | None = None,
    *,
    out: paddle.Tensor | None = None,
    device: PlaceLike | None = None,
    requires_grad: bool = False,
)

Source from the content-addressed store, hash-verified

332
333@param_two_alias(["stop", "end"], ["num", "steps"])
334def linspace(
335 start: float | paddle.Tensor,
336 stop: float | paddle.Tensor,
337 num: int | paddle.Tensor,
338 dtype: DTypeLike | None = None,
339 name: str | None = None,
340 *,
341 out: paddle.Tensor | None = None,
342 device: PlaceLike | None = None,
343 requires_grad: bool = False,
344) -> paddle.Tensor:
345 r"""
346 Return fixed number of evenly spaced values within a given interval. Note: no gradient calculation is performed.
347
348 Args:
349 start(int|float|Tensor): The input :attr:`start` is start of range. It is a int, float, \
350 or a 0-D Tensor with data type int32, int64, float32 or float64.
351 stop(int|float|Tensor): The input :attr:`stop` is end of range. It is a int, float, \
352 or a 0-D Tensor with data type int32, int64, float32 or float64.
353 num(int|Tensor): The input :attr:`num` is given num of the sequence. It is an int, \
354 or a 0-D Tensor with data type int32.
355 dtype(str|paddle.dtype|np.dtype|None, optional): The data type of output tensor, it could be
356 int32, int64, float32 and float64. Default: if None, the data type is float32.
357 name(str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
358 out(Tensor|None, optional): Optional output tensor. If provided, the result will be stored in this tensor. \
359 The tensor must have the correct shape and dtype. Default: None.
360 device(str|paddle.CUDAPlace|paddle.CPUPlace|None, optional): The device where the output tensor will be placed. \
361 It can be a string (e.g., 'cpu', 'gpu:0'), a paddle.CUDAPlace, or a paddle.CPUPlace object. \
362 If None, the current device context will be used. Default: None.
363 requires_grad(bool, optional): Whether the output tensor should have gradient computation enabled. \
364 If True, the output tensor's ``stop_gradient`` attribute will be set to False. Default: False.
365
366 Returns:
367 Tensor: the output data type will be float32, float64. The 1-D tensor with fixed number of evenly spaced values, \
368 the data shape of this tensor is :math:`[num]` . If the :attr:`num` is set 1, the output tensor just has \
369 the value with input :attr:`start`.
370
371 .. note::
372 **Alias Support:**
373
374 - The parameter name ``end`` can be used as an alias for ``stop``. \
375 For example, ``linspace(start=0, end=10, ...)`` is equivalent to ``linspace(start=0, stop=10, ...)``.
376 - The parameter name ``steps`` can be used as an alias for ``num``. \
377 For example, ``linspace(start=0, stop=10, steps=5)`` is equivalent to ``linspace(start=0, stop=10, num=5)``.
378
379 Examples:
380 .. code-block:: pycon
381
382 >>> import paddle
383 >>> data = paddle.linspace(0, 10, 5, 'float32')
384 >>> print(data.numpy())
385 [0. 2.5 5. 7.5 10.]
386 >>> data = paddle.linspace(0, 10, 1, 'float32')
387 >>> print(data.numpy())
388 [0.]
389
390 >>> # Using device parameter
391 >>> data = paddle.linspace(0, 10, 5, device='cpu')

Callers 3

LinspaceKernelFunction · 0.85
GetIdxMap4DFunction · 0.85
GetIdxMap5DFunction · 0.85

Calls 15

append_opMethod · 0.95
_get_paddle_placeFunction · 0.85
_current_expected_placeFunction · 0.85
in_pir_modeFunction · 0.85
LayerHelperClass · 0.85
ValueErrorClass · 0.85
get_default_dtypeMethod · 0.80
fill_constantFunction · 0.70
check_typeFunction · 0.50
device_guardFunction · 0.50

Tested by

no test coverage detected