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

Method __array_function__

monai/data/meta_tensor.py:313–322  ·  view source on GitHub ↗

for numpy Interoperability, so that we can compute ``np.sum(MetaTensor([1.0]))``.

(self, func, types, args, kwargs)

Source from the content-addressed store, hash-verified

311 return x
312
313 def __array_function__(self, func, types, args, kwargs):
314 """for numpy Interoperability, so that we can compute ``np.sum(MetaTensor([1.0]))``."""
315 try:
316 if not func.__module__.startswith("numpy"):
317 return NotImplemented
318 except AttributeError:
319 return NotImplemented
320 _args = list(map(MetaTensor._convert, args))
321 _kwargs = {k: MetaTensor._convert(v) for k, v in kwargs.items()}
322 return func(*_args, **_kwargs)
323
324 def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
325 """

Callers

nothing calls this directly

Calls 1

_convertMethod · 0.80

Tested by

no test coverage detected