MCPcopy Create free account
hub / github.com/dask/dask / Elemwise

Class Elemwise

dask/array/_array_expr/_blockwise.py:215–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213
214
215class Elemwise(Blockwise):
216 _parameters = ["op", "dtype", "name", "where"]
217 _defaults = {
218 "dtype": None,
219 "name": None,
220 "where": True,
221 }
222 align_arrays = True
223 new_axes: dict = {}
224 adjust_chunks = None
225 concatenate = None
226
227 @cached_property
228 def _meta(self):
229 return compute_meta(
230 self._info[0], self.dtype, *self.elemwise_args, **self.kwargs
231 )
232
233 @property
234 def elemwise_args(self):
235 return self.operands[len(self._parameters) :]
236
237 @property
238 def out_ind(self):
239 shapes = []
240 for arg in self.elemwise_args:
241 shape = getattr(arg, "shape", ())
242 if any(is_dask_collection(x) for x in shape):
243 # Want to exclude Delayed shapes and dd.Scalar
244 shape = ()
245 shapes.append(shape)
246 if isinstance(self.where, ArrayExpr):
247 shapes.append(self.where.shape)
248
249 shapes = [s if isinstance(s, Iterable) else () for s in shapes]
250 out_ndim = len(
251 broadcast_shapes(*shapes)
252 ) # Raises ValueError if dimensions mismatch
253 return tuple(range(out_ndim))[::-1]
254
255 @cached_property
256 def _info(self):
257 if self.operand("dtype") is not None:
258 need_enforce_dtype = True
259 dtype = self.operand("dtype")
260 else:
261 # We follow NumPy's rules for dtype promotion, which special cases
262 # scalars and 0d ndarrays (which it considers equivalent) by using
263 # their values to compute the result dtype:
264 # https://github.com/numpy/numpy/issues/6240
265 # We don't inspect the values of 0d dask arrays, because these could
266 # hold potentially very expensive calculations. Instead, we treat
267 # them just like other arrays, and if necessary cast the result of op
268 # to match.
269 vals = [
270 (
271 np.empty((1,) * max(1, a.ndim), dtype=a.dtype)
272 if not is_scalar_for_elemwise(a)

Callers 1

elemwiseFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected