MCPcopy Index your code
hub / github.com/dask/dask / ufunc

Class ufunc

dask/array/_array_expr/_ufunc.py:75–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73
74
75class ufunc:
76 _forward_attrs = {
77 "nin",
78 "nargs",
79 "nout",
80 "ntypes",
81 "identity",
82 "signature",
83 "types",
84 }
85
86 def __init__(self, ufunc):
87 if not isinstance(ufunc, (np.ufunc, da_frompyfunc)):
88 raise TypeError(
89 "must be an instance of `ufunc` or "
90 f"`da_frompyfunc`, got `{type(ufunc).__name__}"
91 )
92 self._ufunc = ufunc
93 self.__name__ = ufunc.__name__
94 if isinstance(ufunc, np.ufunc):
95 derived_from(np)(self)
96
97 def __dask_tokenize__(self):
98 return self.__name__, normalize_token(self._ufunc)
99
100 def __getattr__(self, key):
101 if key in self._forward_attrs:
102 return getattr(self._ufunc, key)
103 raise AttributeError(f"{type(self).__name__!r} object has no attribute {key!r}")
104
105 def __dir__(self):
106 return list(self._forward_attrs.union(dir(type(self)), self.__dict__))
107
108 def __repr__(self):
109 return repr(self._ufunc)
110
111 def __call__(self, *args, **kwargs):
112 dsks = [arg for arg in args if hasattr(arg, "_elemwise")]
113 if len(dsks) > 0:
114 for dsk in dsks:
115 result = dsk._elemwise(self._ufunc, *args, **kwargs)
116 if type(result) != type(NotImplemented):
117 return result
118 raise TypeError(
119 f"Parameters of such types are not supported by {self.__name__}"
120 )
121 else:
122 return self._ufunc(*args, **kwargs)
123
124 @derived_from(np.ufunc)
125 def outer(self, A, B, **kwargs):
126 if self.nin != 2:
127 raise ValueError("outer product only supported for binary functions")
128 if "out" in kwargs:
129 raise ValueError("`out` kwarg not supported")
130
131 A_is_dask = is_dask_collection(A)
132 B_is_dask = is_dask_collection(B)

Callers 2

frompyfuncFunction · 0.70
_ufunc.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…