MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / max

Function max

imperative/python/megengine/functional/math.py:440–477  ·  view source on GitHub ↗

r"""Calculates the maximum of tensor elements over a given axis (or axes). Args: inp: input tensor. Should have a numeric data type. axis: axis or axes along which maximums must be computed. By default, the maximum must be computed over the entire tensor.

(
    inp: Tensor,
    axis: Optional[Union[int, Sequence[int]]] = None,
    keepdims: bool = False,
)

Source from the content-addressed store, hash-verified

438
439
440def max(
441 inp: Tensor,
442 axis: Optional[Union[int, Sequence[int]]] = None,
443 keepdims: bool = False,
444) -> Tensor:
445 r"""Calculates the maximum of tensor elements over a given axis (or axes).
446
447 Args:
448 inp: input tensor. Should have a numeric data type.
449 axis: axis or axes along which maximums must be computed.
450 By default, the maximum must be computed over the entire tensor.
451 If a sequence of integers, maximums must be computed over multiple axes.
452 keepdims: if ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions,
453 and, accordingly, the result must be compatible with the input tensor (see :ref:`broadcasting-rule`).
454 Otherwise, if ``False``, the reduced axes (dimensions) must not be included in the result.
455
456 Returns:
457 if the maximum was computed over the entire tensor, a zero-dimensional tensor containing the maximum;
458 otherwise, a non-zero-dimensional tensor containing the maximums.
459
460 .. admonition:: Special Cases
461
462 If :math:`x_i` is ``NaN``, the maximum is ``NaN`` (i.e., ``NaN`` values propagate).
463
464 Examples:
465
466 >>> x = Tensor([[1, 2], [3, 4]])
467 >>> F.max(x)
468 Tensor(4, dtype=int32, device=xpux:0)
469
470 Along an axis:
471
472 >>> F.max(x, axis=0)
473 Tensor([3 4], dtype=int32, device=xpux:0)
474 >>> F.max(x, axis=1)
475 Tensor([2 4], dtype=int32, device=xpux:0)
476 """
477 return inp.max(axis=axis, keepdims=keepdims)
478
479
480# searching functions

Callers 15

_load_dataMethod · 0.85
_add_oprMethod · 0.85
_tabulate_mlFunction · 0.85
prof_detailsFunction · 0.85
_infer_broadcasted_shapeFunction · 0.85
sum_op_statsFunction · 0.85
sum_param_statsFunction · 0.85
sum_activations_statsFunction · 0.85
__exit__Method · 0.85
sideeffect_forwardMethod · 0.85

Calls 1

maxMethod · 0.45

Tested by 15

_check_idFunction · 0.68
_check_idFunction · 0.68
maxMethod · 0.68
allocMethod · 0.68
addMethod · 0.68
TESTFunction · 0.68
TEST_PFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68