| 254 | |
| 255 | @pytest.mark.parametrize("ufunc", ["isreal", "iscomplex", "real", "imag"]) |
| 256 | def test_complex(ufunc): |
| 257 | dafunc = getattr(da, ufunc) |
| 258 | # Note that these functions are not NumPy ufuncs |
| 259 | npfunc = getattr(np, ufunc) |
| 260 | |
| 261 | real = np.random.randint(1, 100, size=(20, 20)) |
| 262 | imag = np.random.randint(1, 100, size=(20, 20)) * 1j |
| 263 | comp = real + imag |
| 264 | |
| 265 | dareal = da.from_array(real, 3) |
| 266 | daimag = da.from_array(imag, 3) |
| 267 | dacomp = da.from_array(comp, 3) |
| 268 | |
| 269 | assert_eq(dacomp.real, comp.real) |
| 270 | assert_eq(dacomp.imag, comp.imag) |
| 271 | assert_eq(dacomp.conj(), comp.conj()) |
| 272 | |
| 273 | for darr, arr in [(dacomp, comp), (dareal, real), (daimag, imag)]: |
| 274 | # applying Dask ufunc doesn't trigger computation |
| 275 | assert isinstance(dafunc(darr), da.Array) |
| 276 | assert_eq(dafunc(darr), npfunc(arr)) |
| 277 | assert_eq(npfunc(darr), npfunc(arr)) |
| 278 | |
| 279 | # applying Dask ufunc to normal ndarray triggers computation |
| 280 | assert isinstance(dafunc(arr), np.ndarray) |
| 281 | assert_eq(dafunc(arr), npfunc(arr)) |
| 282 | |
| 283 | |
| 284 | @pytest.mark.parametrize("ufunc", ["frexp", "modf"]) |