|
32 | 32 | isnan, |
33 | 33 | log, |
34 | 34 | logsumexp, |
| 35 | + maximum, |
| 36 | + minimum, |
35 | 37 | sign, |
36 | 38 | sin, |
37 | 39 | ) |
@@ -852,10 +854,10 @@ def logaddexp(x: Tensor, y: Tensor, name: str | None = None) -> Tensor: |
852 | 854 | [-0.30685282, -0.68673831, -0.87307199]) |
853 | 855 | """ |
854 | 856 | log_1p = paddle.log1p(paddle.exp(-paddle.abs(x - y))) |
855 | | - maximum = paddle.maximum(x, y) |
856 | | - if maximum.dtype == paddle.int32 or maximum.dtype == paddle.int64: |
857 | | - maximum = maximum.astype(log_1p.dtype) |
858 | | - return log_1p + maximum |
| 857 | + _maximum = paddle.maximum(x, y) |
| 858 | + if _maximum.dtype == paddle.int32 or _maximum.dtype == paddle.int64: |
| 859 | + _maximum = _maximum.astype(log_1p.dtype) |
| 860 | + return log_1p + _maximum |
859 | 861 |
|
860 | 862 |
|
861 | 863 | def subtract(x: Tensor, y: Tensor, name: str | None = None) -> Tensor: |
@@ -1448,130 +1450,6 @@ def _divide_with_axis(x, y, axis=-1, name=None): |
1448 | 1450 | return _elementwise_op(LayerHelper(op_type, **locals())) |
1449 | 1451 |
|
1450 | 1452 |
|
1451 | | -def maximum(x: Tensor, y: Tensor, name: str | None = None) -> Tensor: |
1452 | | - """ |
1453 | | - Compare two tensors and returns a new tensor containing the element-wise maxima. The equation is: |
1454 | | -
|
1455 | | - .. math:: |
1456 | | - out = max(x, y) |
1457 | | -
|
1458 | | - Note: |
1459 | | - ``paddle.maximum`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . |
1460 | | -
|
1461 | | - .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor |
1462 | | -
|
1463 | | - Args: |
1464 | | - x (Tensor): the input tensor, it's data type should be bfloat16, float16, float32, float64, int32, int64. |
1465 | | - y (Tensor): the input tensor, it's data type should be bfloat16, float16, float32, float64, int32, int64. |
1466 | | - name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. |
1467 | | -
|
1468 | | - Returns: |
1469 | | - N-D Tensor. A location into which the result is stored. If x, y have different shapes and are "broadcastable", the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y. |
1470 | | -
|
1471 | | - Examples: |
1472 | | -
|
1473 | | - .. code-block:: python |
1474 | | -
|
1475 | | - >>> import paddle |
1476 | | -
|
1477 | | - >>> x = paddle.to_tensor([[1, 2], [7, 8]]) |
1478 | | - >>> y = paddle.to_tensor([[3, 4], [5, 6]]) |
1479 | | - >>> res = paddle.maximum(x, y) |
1480 | | - >>> print(res) |
1481 | | - Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True, |
1482 | | - [[3, 4], |
1483 | | - [7, 8]]) |
1484 | | -
|
1485 | | - >>> x = paddle.to_tensor([[1, 2, 3], [1, 2, 3]]) |
1486 | | - >>> y = paddle.to_tensor([3, 0, 4]) |
1487 | | - >>> res = paddle.maximum(x, y) |
1488 | | - >>> print(res) |
1489 | | - Tensor(shape=[2, 3], dtype=int64, place=Place(cpu), stop_gradient=True, |
1490 | | - [[3, 2, 4], |
1491 | | - [3, 2, 4]]) |
1492 | | -
|
1493 | | - >>> x = paddle.to_tensor([2, 3, 5], dtype='float32') |
1494 | | - >>> y = paddle.to_tensor([1, float("nan"), float("nan")], dtype='float32') |
1495 | | - >>> res = paddle.maximum(x, y) |
1496 | | - >>> print(res) |
1497 | | - Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, |
1498 | | - [2. , nan, nan]) |
1499 | | -
|
1500 | | - >>> x = paddle.to_tensor([5, 3, float("inf")], dtype='float32') |
1501 | | - >>> y = paddle.to_tensor([1, -float("inf"), 5], dtype='float32') |
1502 | | - >>> res = paddle.maximum(x, y) |
1503 | | - >>> print(res) |
1504 | | - Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, |
1505 | | - [5. , 3. , inf.]) |
1506 | | - """ |
1507 | | - if in_dynamic_or_pir_mode(): |
1508 | | - return _C_ops.maximum(x, y) |
1509 | | - else: |
1510 | | - return _elementwise_op(LayerHelper('elementwise_max', **locals())) |
1511 | | - |
1512 | | - |
1513 | | -def minimum(x: Tensor, y: Tensor, name: str | None = None) -> Tensor: |
1514 | | - """ |
1515 | | - Compare two tensors and return a new tensor containing the element-wise minima. The equation is: |
1516 | | -
|
1517 | | - .. math:: |
1518 | | - out = min(x, y) |
1519 | | -
|
1520 | | - Note: |
1521 | | - ``paddle.minimum`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . |
1522 | | -
|
1523 | | - .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor |
1524 | | -
|
1525 | | - Args: |
1526 | | - x (Tensor): the input tensor, it's data type should be bfloat16, float16, float32, float64, int32, int64. |
1527 | | - y (Tensor): the input tensor, it's data type should be bfloat16, float16, float32, float64, int32, int64. |
1528 | | - name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. |
1529 | | -
|
1530 | | - Returns: |
1531 | | - Tensor. If x, y have different shapes and are "broadcastable", the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y. |
1532 | | -
|
1533 | | - Examples: |
1534 | | -
|
1535 | | - .. code-block:: python |
1536 | | -
|
1537 | | - >>> import paddle |
1538 | | -
|
1539 | | - >>> x = paddle.to_tensor([[1, 2], [7, 8]]) |
1540 | | - >>> y = paddle.to_tensor([[3, 4], [5, 6]]) |
1541 | | - >>> res = paddle.minimum(x, y) |
1542 | | - >>> print(res) |
1543 | | - Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True, |
1544 | | - [[1, 2], |
1545 | | - [5, 6]]) |
1546 | | -
|
1547 | | - >>> x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]]) |
1548 | | - >>> y = paddle.to_tensor([3, 0, 4]) |
1549 | | - >>> res = paddle.minimum(x, y) |
1550 | | - >>> print(res) |
1551 | | - Tensor(shape=[1, 2, 3], dtype=int64, place=Place(cpu), stop_gradient=True, |
1552 | | - [[[1, 0, 3], |
1553 | | - [1, 0, 3]]]) |
1554 | | -
|
1555 | | - >>> x = paddle.to_tensor([2, 3, 5], dtype='float32') |
1556 | | - >>> y = paddle.to_tensor([1, float("nan"), float("nan")], dtype='float32') |
1557 | | - >>> res = paddle.minimum(x, y) |
1558 | | - >>> print(res) |
1559 | | - Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, |
1560 | | - [1. , nan, nan]) |
1561 | | -
|
1562 | | - >>> x = paddle.to_tensor([5, 3, float("inf")], dtype='float64') |
1563 | | - >>> y = paddle.to_tensor([1, -float("inf"), 5], dtype='float64') |
1564 | | - >>> res = paddle.minimum(x, y) |
1565 | | - >>> print(res) |
1566 | | - Tensor(shape=[3], dtype=float64, place=Place(cpu), stop_gradient=True, |
1567 | | - [ 1. , -inf., 5. ]) |
1568 | | - """ |
1569 | | - if in_dynamic_or_pir_mode(): |
1570 | | - return _C_ops.minimum(x, y) |
1571 | | - else: |
1572 | | - return _elementwise_op(LayerHelper('elementwise_min', **locals())) |
1573 | | - |
1574 | | - |
1575 | 1453 | def fmax(x: Tensor, y: Tensor, name: str | None = None) -> Tensor: |
1576 | 1454 | """ |
1577 | 1455 | Compares the elements at the corresponding positions of the two tensors and returns a new tensor containing the maximum value of the element. |
|
0 commit comments