cummax

paddle. cummax ( x: Tensor, axis: int | None = None, dtype: DTypeLike = 'int64', name: str | None = None, *, out: tuple[Tensor, Tensor] | None = None ) → CummaxRetType [source]

The cumulative max of the elements along a given axis.

This API has two signatures:

  1. paddle.cummax(x, axis=None, dtype='int64', name=None) (Paddle-style): Compute cumulative max with optional axis parameter.

  2. paddle.cummax(input, dim, *, out=None) (PyTorch-style): Compute cumulative max with required dim parameter. The parameter name input is an alias for x, dim is an alias for axis.

Note

The first element of the result is the same as the first element of the input.

Parameters
  • x (Tensor) – The input tensor needed to be cummaxed. Alias: input.

  • axis (int, optional) – The dimension to accumulate along. -1 means the last dimension. The default (None) is to compute the cummax over the flattened array. Alias: dim.

  • dtype (str|paddle.dtype|np.dtype, optional) – The data type of the indices tensor, can be int32, int64. The default value is int64.

  • name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to api_guide_Name.

Keyword Arguments

out (tuple[Tensor, Tensor]|None, optional) – The output tuple of two tensors (values, indices). Default: None.

Returns

values (Tensor), The result of cummax operation. The dtype of cummax result is same with input x.

indices (Tensor), The corresponding index results of cummax operation.

Examples

>>> import paddle

>>> data = paddle.to_tensor([-1, 5, 0, -2, -3, 2])
>>> data = paddle.reshape(data, (2, 3))

>>> value, indices = paddle.cummax(data)
>>> value
Tensor(shape=[6], dtype=int64, place=Place(cpu), stop_gradient=True,
[-1,  5,  5,  5,  5,  5])
>>> indices
Tensor(shape=[6], dtype=int64, place=Place(cpu), stop_gradient=True,
[0, 1, 1, 1, 1, 1])

>>> value, indices = paddle.cummax(data, axis=0)
>>> value
Tensor(shape=[2, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
[[-1,  5,  0],
 [-1,  5,  2]])
>>> indices
Tensor(shape=[2, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
[[0, 0, 0],
 [0, 0, 1]])

>>> value, indices = paddle.cummax(data, axis=-1)
>>> value
Tensor(shape=[2, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
[[-1,  5,  5],
 [-2, -2,  2]])
>>> indices
Tensor(shape=[2, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
[[0, 1, 1],
 [0, 0, 2]])

>>> value, indices = paddle.cummax(data, dtype='int64')
>>> assert indices.dtype == paddle.int64