将参数转发到python中右侧的嵌套函数



daskapply_along_axis函数具有以下签名:

dask.array.apply_along_axis(func1d, axis, arr, *args, dtype=None, shape=None, **kwargs)

在我的情况下,func1d具有以下签名:

my_fun(arr, x, xp, propagate=True)

我需要指定dtype和shape参数(它们默认为None不适合我的情况(。我不熟悉*args和**kwargs语法(我来自C++,使用模板参数包语法(,即使我尝试过数字呼叫形式,我也总能得到my_fun() got an unexpected keyword argument 'shape'

如何调用此函数以将正确的参数传递给正确的函数?

可还原示例:

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()

退货:

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'

编辑:我认为这个问题已经很接近了,但我不知道如何解决这个问题。

更新Dask版本修复了此问题。我们已经用Dask2022.3.0验证了这一点——在回答时的最新Dask版本。:(