| 330 | |
| 331 | |
| 332 | def test_gufunc_vectorize_whitespace(): |
| 333 | # Regression test for https://github.com/dask/dask/issues/7972. |
| 334 | # NumPy versions before https://github.com/numpy/numpy/pull/19627 |
| 335 | # would not ignore whitespace characters in `signature` like they |
| 336 | # are supposed to. We remove the whitespace in Dask as a workaround. |
| 337 | |
| 338 | def foo(x, y): |
| 339 | return (x + y).sum(axis=1) |
| 340 | |
| 341 | a = da.ones((8, 3, 5), chunks=(2, 3, 5), dtype=int) |
| 342 | b = np.ones(5, dtype=int) |
| 343 | x = apply_gufunc(foo, "(m, n),(n)->(m)", a, b, vectorize=True) |
| 344 | |
| 345 | assert_eq(x, np.full((8, 3), 10, dtype=int)) |
| 346 | |
| 347 | a = da.random.default_rng().random((6, 5, 5)) |
| 348 | |
| 349 | @da.as_gufunc(signature="(n, n)->(n, n)", output_dtypes=float, vectorize=True) |
| 350 | def gufoo(x): |
| 351 | return np.linalg.inv(x) |
| 352 | |
| 353 | # Previously calling `gufoo` would raise an error due to the whitespace |
| 354 | # in its `signature`. Let's make sure it doesn't raise here. |
| 355 | gufoo(a) |
| 356 | |
| 357 | |
| 358 | def test_gufunc(): |