MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / max

Function max

monai/transforms/utils_pytorch_numpy_unification.py:461–481  ·  view source on GitHub ↗

`torch.max` with equivalent implementation for numpy Args: x: array/tensor. Returns: the maximum of x.

(x: NdarrayTensor, dim: int | tuple | None = None, **kwargs)

Source from the content-addressed store, hash-verified

459
460
461def max(x: NdarrayTensor, dim: int | tuple | None = None, **kwargs) -> NdarrayTensor:
462 """`torch.max` with equivalent implementation for numpy
463
464 Args:
465 x: array/tensor.
466
467 Returns:
468 the maximum of x.
469
470 """
471
472 ret: NdarrayTensor
473 if dim is None:
474 ret = np.max(x, **kwargs) if isinstance(x, (np.ndarray, list)) else torch.max(x, **kwargs) # type: ignore
475 else:
476 if isinstance(x, (np.ndarray, list)):
477 ret = np.max(x, axis=dim, **kwargs)
478 else:
479 ret = torch.max(x, int(dim), **kwargs) # type: ignore
480
481 return ret[0] if isinstance(ret, tuple) else ret
482
483
484def mean(x: NdarrayTensor, dim: int | tuple | None = None, **kwargs) -> NdarrayTensor:

Callers 15

__call__Method · 0.90
convert_points_to_boxFunction · 0.90
get_times_summaryMethod · 0.85
pprint_edgesFunction · 0.85
plot_metric_imagesFunction · 0.85
_torch_all_gatherFunction · 0.85
_ignite_all_gatherFunction · 0.85
trt_compileFunction · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
scales_for_resolutionFunction · 0.85

Calls

no outgoing calls

Tested by 3

test_shape_generatorFunction · 0.68