Open crusaderky opened 3 years ago
Thanks for the report.
I think that this is working in the case of provided signatures because Numba is creating a real NumPy ufunc that will work with Xarray because it provides the protocols for that to work. In the case of no signatures, Numba is doing the "dynamic ufunc" behaviour (jitting ufuncs on demand based on arg type) and this is relying on type inference to work out what the argument types are and how to handle them. I think for now a workaround is going to be needed.
Reworking Numba's ufunc
behaviour is something that's been discussed quite a bit recently, having this use case as another concrete example of something that could potentially "just work" is really helpful, thanks!
My guess is that Numba needs some form of support for "duck typing" in order for dynamic ufuncs to work on xarray.DataArray
objects. Assuming that dynamic ufuncs only need dtype
and shape
information matching the NumPy convention, this is something you can pull out from the corresponding attributes on xarray.DataArray
objects.
numpy 1.20.0 numba 0.52.0 xarray 0.16.2 python 3.8
If I don't produce a list of signatures and rely on
@vectorize
'd functions to be compiled upon first call, they crash if the first call is a xarray.DataArray.FYI @shoyer
Workarounds
a.copy(data=double(a.data))