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

Function sum

monai/transforms/utils_pytorch_numpy_unification.py:572–591  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

570
571
572def sum(x: NdarrayTensor, dim: int | tuple | None = None, **kwargs) -> NdarrayTensor:
573 """`torch.sum` with equivalent implementation for numpy
574
575 Args:
576 x: array/tensor.
577
578 Returns:
579 the sum of x.
580 """
581
582 ret: NdarrayTensor
583 if dim is None:
584 ret = np.sum(x, **kwargs) if isinstance(x, (np.ndarray, list)) else torch.sum(x, **kwargs) # type: ignore
585 else:
586 if isinstance(x, (np.ndarray, list)):
587 ret = np.sum(x, axis=dim, **kwargs)
588 else:
589 ret = torch.sum(x, int(dim), **kwargs) # type: ignore
590
591 return ret

Callers 15

__call__Method · 0.90
__call__Method · 0.90
wrapperFunction · 0.85
get_times_summaryMethod · 0.85
pixelunshuffleFunction · 0.85
__init__Method · 0.85
_make_same_padderFunction · 0.85
compute_roc_aucFunction · 0.85
convert_box_to_maskFunction · 0.85
partition_datasetFunction · 0.85

Calls

no outgoing calls

Tested by 11

get_net_parametersFunction · 0.68
test_block1Method · 0.68
test_block2Method · 0.68
test_block1Method · 0.68
test_block2Method · 0.68
count_sablock_paramsMethod · 0.68
testMethod · 0.68
test_valueMethod · 0.68
test_coco_runMethod · 0.68
sum_listMethod · 0.68