Skip to content

Update math.py #72090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
38 changes: 38 additions & 0 deletions python/paddle/tensor/math.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. cauchy_python/paddle/tensor/creation.py 而不是这里
  2. PR 描述说是更新中文文档,但中文文档在 docs repo 而不是这里
  3. 动机是什么?修复了什么?如果最初动机是 【Docathon】补充缺失的中文 API 文档(Inplace 类) docs#7090,请在 PR 描述里说清楚,并链接过去,同时要说明具体修改了什么,为什么要修改

Original file line number Diff line number Diff line change
Expand Up @@ -8932,3 +8932,41 @@ def cartesian_prod(x: Sequence[Tensor], name: str | None = None) -> Tensor:

coordinates = paddle.stack(paddle.meshgrid(x), axis=-1)
return paddle.reshape(coordinates, [-1, len(x)])


def cauchy_(
x: paddle.Tensor,
loc: Numeric = 0,
scale: Numeric = 1,
name: str | None = None,
) -> paddle.Tensor:
"""Fills the tensor with numbers drawn from the Cauchy distribution.

Args:
x (Tensor): the tensor will be filled, The data type is float32 or float64.
loc (scalar, optional): Location of the peak of the distribution. The data type is float32 or float64.
scale (scalar, optional): The half-width at half-maximum (HWHM). The data type is float32 or float64. Must be positive values.
name(str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
Tensor: input tensor with numbers drawn from the Cauchy distribution.

Examples:
.. code-block:: python

>>> import paddle
>>> x = paddle.randn([3, 4])
>>> x.cauchy_(1, 2)
>>> # doctest: +SKIP('random check')
>>> print(x)
Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
[[ 3.80087137, 2.25415039, 2.77960515, 7.64125967],
[ 0.76541221, 2.74023032, 1.99383152, -0.12685823],
[ 1.45228469, 1.76275957, -4.30458832, 34.74880219]])

"""
x.normal_()
loc = paddle.to_tensor(loc).astype(x.dtype)
half = paddle.to_tensor(0.5).astype(x.dtype)
x.subtract_(half).scale_(np.pi).tan_().scale_(scale).add_(loc)
return x
Loading