MCPcopy
hub / github.com/dask/dask / safe_sqrt

Function safe_sqrt

dask/array/reductions.py:699–710  ·  view source on GitHub ↗

A version of sqrt that properly handles scalar masked arrays. To mimic ``np.ma`` reductions, we need to convert scalar masked arrays that have an active mask to the ``np.ma.masked`` singleton. This is properly handled automatically for reduction code, but not for ufuncs. We implement

(a)

Source from the content-addressed store, hash-verified

697
698
699def safe_sqrt(a):
700 """A version of sqrt that properly handles scalar masked arrays.
701
702 To mimic ``np.ma`` reductions, we need to convert scalar masked arrays that
703 have an active mask to the ``np.ma.masked`` singleton. This is properly
704 handled automatically for reduction code, but not for ufuncs. We implement
705 a simple version here, since calling `np.ma.sqrt` everywhere is
706 significantly more expensive.
707 """
708 if hasattr(a, "_elemwise"):
709 return a._elemwise(_sqrt, a)
710 return _sqrt(a)
711
712
713@derived_from(np)

Callers 2

stdFunction · 0.85
nanstdFunction · 0.85

Calls 2

_sqrtFunction · 0.85
_elemwiseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…