-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
What happened:
Today I was trying to write an da.as_gufunc wrapper for np.linalg.inv, since the dask version doesn't support having loop dimensions (e.g. 2D input works, 3D input, where the first dimension should be iterated over, doesn't work.)
The following was my attempt:
import numpy as np
import dask.array as da
a = da.random.random((6,5,5))
@da.as_gufunc(signature="(n, n)->(n, n)", output_dtypes=float, vectorize=True)
def gufoo(x):
return np.linalg.inv(x)
y = gufoo(b)and for some reason I kept getting the error
ValueError: not a valid gufunc signature: (n, n)->(n, n) (click for full error)
The issue was the whitespace in my signature: "(n, n)->(n, n)" had to be "(n,n)->(n,n)". This is not mentioned in the [dask gufunc documentation](numba signature).
What you expected to happen:
Numpy gufunc documentation states that
- White spaces are ignored.
I would expect that the signature should work regardless of whitespace, since it is common to write, e.g. da.random.random((6, 5, 5)), and not be forced to random((6,5,5))`.
Including whitespace does work in Numba:
import numpy as np
from numba import guvectorize, int64
x = np.random.randint(1, 5, size=(5,5), dtype=np.int64)
y = 1
res = np.zeros((5,5), dtype=np.int64)
@guvectorize([(int64[:, :], int64, int64[:, :])], '(n, n),()->(n, n)')
def g(x, y, res):
for i in range(x.shape[0]):
res[i] = x[i] + y
g(x, y, res)Anything else we need to know?:
I will point out that this was surprisingly difficult to figure out, since I wasn't thinking about whitespace - it would suddenly work (no whitespace) and then I would try a moment later (with whitespace) and it didn't work ("Am I going crazy?").
Environment:
- Dask version:'2021.07.0'
- Python version: 3.9
- Operating System: OS X
- Install method (conda, pip, source): Conda