MCPcopy
hub / github.com/pydata/xarray / get_array_namespace

Function get_array_namespace

xarray/compat/array_api_compat.py:49–73  ·  view source on GitHub ↗
(*values)

Source from the content-addressed store, hash-verified

47
48
49def get_array_namespace(*values):
50 def _get_single_namespace(x):
51 if hasattr(x, "__array_namespace__"):
52 return x.__array_namespace__()
53 elif isinstance(x, array_type("cupy")):
54 # cupy is fully compliant from xarray's perspective, but will not expose
55 # __array_namespace__ until at least v14. Special case it for now
56 import cupy as cp
57
58 return cp
59 else:
60 return np
61
62 namespaces = {_get_single_namespace(t) for t in values}
63 non_numpy = namespaces - {np}
64
65 if len(non_numpy) > 1:
66 names = [module.__name__ for module in non_numpy]
67 raise TypeError(f"Mixed array types {names} are not supported.")
68 elif non_numpy:
69 [xp] = non_numpy
70 else:
71 xp = np
72
73 return xp
74
75
76def to_like_array(array, like):

Callers 15

fFunction · 0.90
einsumFunction · 0.90
tensordotFunction · 0.90
crossFunction · 0.90
gradientFunction · 0.90
sliding_window_viewFunction · 0.90
roundFunction · 0.90
isnullFunction · 0.90
cumulative_trapezoidFunction · 0.90
full_likeFunction · 0.90
empty_likeFunction · 0.90
astypeFunction · 0.90

Calls 1

_get_single_namespaceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…