The dask apply_along_axis function has the following signature:
dask.array.apply_along_axis(func1d, axis, arr, *args, dtype=None, shape=None, **kwargs)
In my case, func1d has the following signature:
my_fun(arr, x, xp, propagate=True)
I need to specify dtype and shape arguments (their default to None does not fit my case). I'm not familiar with *args and **kwargs syntaxes (I come from C++ with template parameter packs syntaxes), and even if I've tried a number call forms, I always get something along my_fun() got an unexpected keyword argument 'shape'.
How do I call this function to pass the right arguments to the right functions?
Repoducible example:
import dask
import dask.array as da
import numpy as np
def my_fun(data, x, xp):
return data
new_array = np.zeros((100,100,100))
big_array=da.from_array(new_array, chunks=(100,100,100))
x="foo"
xp="fee"
interpolated = da.apply_along_axis(func1d=my_fun, axis=0, arr=big_array, shape=big_array.shape, dtype=big_array.dtype, x=x, xp=xp).compute()
Returns:
Traceback (most recent call last):
File "parallelDask.py", line 28, in <module>
interpolated = da.apply_along_axis(func1d=my_fun, axis=0, arr=big_array, shape=big_array.shape, dtype=big_array.dtype, x=x, xp=xp).compute()
File "/home/becheler/dev/virtual_environments/crumbs-env/lib/python3.8/site-packages/dask/array/routines.py", line 304, in apply_along_axis
test_result = np.array(func1d(test_data, *args, **kwargs))
TypeError: my_fun() got an unexpected keyword argument 'shape'
EDIT: I think it comes pretty close to this issue but I could not figure out how to solve the problem.
my_funactuallymasked_interpolation? can you show us the full traceback and ideally create a minimal reproducible example so we can fully understand/debug the issue? at minimum it would be really helpful if you could provide one of the calls that produced the error. thanks!my_funfunctor has to end with(*args, **kwargs), so the test inapply_along_axiscan pass to it theshapeanddtypewithout complaining (even if they are not used in the body ofmy_fun). If what I say holds, then it's quite a weird behavior I would never have expected. I guess it works for most of the use cases because usual functions like np.sum define args and kwargs in their signature. May be worth to add to the doc for those who want to write new functors?