Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions python/paddle/tensor/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,7 @@ def ones(
shape: ShapeLike,
dtype: DTypeLike | None = None,
*,
out: paddle.Tensor | None = None,
device: PlaceLike | None = None,
requires_grad: bool = False,
name: str | None = None,
Expand All @@ -1280,6 +1281,7 @@ def ones(
If ``shape`` is an Tensor, it should be an 1-D Tensor which represents a list.
dtype (np.dtype|str, optional): Data type of output Tensor, it should be one of
bool, float16, float32, float64, int32 and int64. If it is set to None, the data type will be float32.
out(Tensor, optional): The output tensor.
device(PlaceLike|None, optional): The desired device of returned tensor.
if None, uses the current device for the default tensor type (see paddle.device.set_device()).
device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. Default: None.
Expand Down Expand Up @@ -1321,6 +1323,7 @@ def ones(
shape,
1,
dtype,
out=out,
device=device,
requires_grad=requires_grad,
name=name,
Expand Down Expand Up @@ -1385,6 +1388,7 @@ def zeros(
shape: ShapeLike,
dtype: DTypeLike | None = None,
*,
out: paddle.Tensor | None = None,
device: PlaceLike | None = None,
requires_grad: bool = False,
name: str | None = None,
Expand All @@ -1398,12 +1402,13 @@ def zeros(
If ``shape`` is an Tensor, it should be an 1-D Tensor which represents a list.
dtype(np.dtype|str, optional): Data type of output Tensor, it supports
bool, float16, float32, float64, int32 and int64. Default: if None, the data type is float32.
name(str|None, optional): The default value is None. Normally there is no need for user to set this
property. For more information, please refer to :ref:`api_guide_Name`.
out(Tensor, optional): The output tensor.
device(PlaceLike|None, optional): The desired device of returned tensor.
if None, uses the current device for the default tensor type (see paddle.device.set_device()).
device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. Default: None.
requires_grad(bool, optional): If autograd should record operations on the returned tensor. Default: False.
name(str|None, optional): The default value is None. Normally there is no need for user to set this

Returns:
Tensor: A tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 0.
Expand Down Expand Up @@ -1440,6 +1445,7 @@ def zeros(
shape,
0,
dtype,
out=out,
device=device,
requires_grad=requires_grad,
name=name,
Expand Down Expand Up @@ -1505,6 +1511,7 @@ def eye(
num_columns: int | None = None,
dtype: DTypeLike | None = None,
*,
out: paddle.Tensor | None = None,
device: PlaceLike | None = None,
requires_grad: bool = False,
name: str | None = None,
Expand All @@ -1520,6 +1527,7 @@ def eye(
dtype(np.dtype|str, optional): The data type of the returned Tensor.
It should be int32, int64, float16, float32, float64, complex64, complex128. Default: if None, the data type
is float32.
out(Tensor, optional): The output tensor.
device(PlaceLike|None, optional): The desired device of returned tensor.
if None, uses the current device for the default tensor type (see paddle.device.set_device()).
device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. Default: None.
Expand Down Expand Up @@ -1574,6 +1582,7 @@ def _check_attr(attr, message):
if device is not None
else _current_expected_place()
),
out=out,
)
if requires_grad is True:
tensor.stop_gradient = False
Expand Down Expand Up @@ -1617,6 +1626,7 @@ def full(
fill_value: bool | float | paddle.Tensor,
dtype: DTypeLike | None = None,
*,
out: paddle.Tensor | None = None,
device: PlaceLike | None = None,
requires_grad: bool = False,
name: str | None = None,
Expand All @@ -1634,6 +1644,7 @@ def full(
dtype(np.dtype|str, optional): Data type of the output Tensor
which can be float16, float32, float64, int32, int64, if dtype is `None`, the data
type of created Tensor is `float32`.
out(Tensor, optional): The output tensor.
device(PlaceLike|None, optional): The desired device of returned tensor.
if None, uses the current device for the default tensor type (see paddle.device.set_device()).
device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. Default: None.
Expand Down Expand Up @@ -1689,7 +1700,12 @@ def full(
dtype = paddle.get_default_dtype()

tensor = fill_constant(
shape=shape, dtype=dtype, value=fill_value, place=device, name=name
shape=shape,
dtype=dtype,
value=fill_value,
out=out,
place=device,
name=name,
)
if requires_grad is True:
tensor.stop_gradient = False
Expand Down Expand Up @@ -2559,6 +2575,7 @@ def empty(
shape: ShapeLike,
dtype: DTypeLike | None = None,
*,
out: paddle.Tensor | None = None,
device: PlaceLike | None = None,
requires_grad: bool = False,
name: str | None = None,
Expand All @@ -2574,6 +2591,7 @@ def empty(
which can be bool, float16, float32, float64, int32, int64, complex64, complex128 if dtype is `None`, the data
type of created Tensor use global default dtype (see ``get_default_dtype``
for details).
out(Tensor, optional): The output tensor.
device(PlaceLike|None, optional): The desired device of returned tensor.
if None, uses the current device for the default tensor type (see paddle.device.set_device()).
device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. Default: None.
Expand Down Expand Up @@ -2663,6 +2681,7 @@ def empty(
if device is not None
else _current_expected_place()
),
out=out,
)
if requires_grad is True:
tensor.stop_gradient = False
Expand Down Expand Up @@ -3178,7 +3197,7 @@ def complex(
real (Tensor): The real component. The data type should be 'float32' or 'float64'.
imag (Tensor): The image component. The data type should be the same as ``real``.
name(str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
out (Tensor|None, optional): The output tensor. Default: None.
out(Tensor|None, optional): The output tensor. Default: None.

Returns:
Tensor, The output tensor. The data type is 'complex64' or 'complex128', with the same precision as ``real`` and ``imag``.
Expand Down
Loading