Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions paddle/phi/ops/yaml/python_api_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
args_alias:
use_default_mapping : True

- op : cosh
name: [paddle.cosh, paddle.Tensor.cosh]
args_alias:
use_default_mapping : True

- op : floor
name: [paddle.floor, paddle.Tensor.floor]
args_alias:
Expand Down
34 changes: 34 additions & 0 deletions python/paddle/_paddle_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,40 @@ def cos(
""",
)

add_doc_and_signature(
"cosh",
"""
Cosh Activation Operator.

Input range `(-inf, inf)`, output range `(1, inf)`.

.. math::
out = \\frac{exp(x)+exp(-x)}{2}

Args:
x (Tensor): Input of Cosh operator, an N-D Tensor, with data type float32, float64, float16, bfloat16,
uint8, int8, int16, int32, int64, complex64 or complex128.
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
out (Tensor, optional): The output Tensor. If set, the result will be stored in this Tensor. Default: None.

Returns:
Tensor. Output of Cosh operator, a Tensor with shape same as input
(integer types are autocasted into float32).

Examples:
.. code-block:: python

>>> import paddle

>>> x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
>>> out = paddle.cosh(x)
>>> print(out)
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[1.08107233, 1.02006674, 1.00500417, 1.04533851])
""",
"def cosh(x: Tensor, name: str | None = None, *, out: Tensor | None = None) -> Tensor",
)

add_doc_and_signature(
"floor",
"""
Expand Down
57 changes: 1 addition & 56 deletions python/paddle/tensor/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
abs,
ceil,
cos,
cosh,
exp,
expm1,
floor,
Expand Down Expand Up @@ -404,62 +405,6 @@ def atanh(x: Tensor, name: str | None = None) -> Tensor:
return out


def cosh(x: Tensor, name: str | None = None) -> Tensor:
"""
Cosh Activation Operator.

Input range `(-inf, inf)`, output range `(1, inf)`.

.. math::
out = \\frac{exp(x)+exp(-x)}{2}

Args:
x (Tensor): Input of Cosh operator, an N-D Tensor, with data type float32, float64, float16, bfloat16,
uint8, int8, int16, int32, int64, complex64 or complex128.
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Returns:
Tensor. Output of Cosh operator, a Tensor with shape same as input
(integer types are autocasted into float32).

Examples:
.. code-block:: python

>>> import paddle

>>> x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
>>> out = paddle.cosh(x)
>>> print(out)
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[1.08107233, 1.02006674, 1.00500417, 1.04533851])
"""
if in_dynamic_or_pir_mode():
return _C_ops.cosh(x)
else:
check_variable_and_dtype(
x,
'x',
[
'float16',
'uint16',
'float32',
'float64',
'uint8',
'int8',
'int16',
'int32',
'int64',
'complex64',
'complex128',
],
'cosh',
)
helper = LayerHelper('cosh', **locals())
out = helper.create_variable_for_type_inference(dtype=x.dtype)
helper.append_op(type='cosh', inputs={"X": x}, outputs={"Out": out})
return out


def reciprocal(x: Tensor, name: str | None = None) -> Tensor:
"""

Expand Down
1 change: 1 addition & 0 deletions test/legacy_test/test_activation_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -6231,6 +6231,7 @@ class TestActivationAPI_Compatibility(unittest.TestCase):
("paddle.expm1", np.expm1, {'min_val': -1.0, 'max_val': 1.0}),
("paddle.round", np.round, {'min_val': -5.0, 'max_val': 5.0}),
("paddle.tanh", np.tanh, {'min_val': -1.0, 'max_val': 1.0}),
("paddle.cosh", np.cosh, {'min_val': -1.0, 'max_val': 1.0}),
]
ACTIVATION_NOT_METHOD_CONFIGS = [
(
Expand Down
Loading