我有一个迭代构建的数组,如下所示:
step1.shape = (200,200)
step2.shape = (200,200,200)
step3.shape = (200,200,200,200)
然后重塑为:
step4.shape = (200,200**3)
我这样做是因为 dask.array.atop 似乎不允许你从这样的形状开始:(200,200) -> (200,200**2)。我认为这与分块和惰性评估有关。
当我执行第 4 步并尝试重塑它时,dask 似乎想要在重塑之前计算矩阵,这会导致大量的计算时间和内存使用。
有没有办法避免这种情况?
根据要求,这是一些虚拟代码:
def prod_mat(matrix_a,matrix_b):
#mat_a.shape = (300,...,300,200)
#mat_b.shape = (300, 200)
mat_a = matrix_a.reshape(-1,matrix_a.shape[-1])
#mat_a = (300**n,200)
mat_b = matrix_b.reshape(-1,matrix_b.shape[-1])
#mat_b = (300,200)
mat_temp = np.repeat(mat_a,matrix_b.shape[0],axis=0)*np.tile(mat_b.T,mat_a.shape[0]).T
new_dim = int(math.log(mat_temp.shape[0])/math.log(matrix_a.shape[0]))
new_shape = [matrix_a.shape[0] for n in range(new_dim)]
new_shape.append(-1)
result = mat_temp.reshape(tuple(new_shape))
#result.shape = (300,...,300,300,200)
return result
b = np.random.rand(300,200)
b = da.from_array(b,chunks=100)
c=da.atop(prod_mat,'ijk',b,'ik',b,'jk')
d=da.atop(prod_mat,'ijkl',c,'ijl',b,'kl')
e=da.atop(prod_mat,'ijklm',d,'ijkm',b,'lm')
f = e.sum(axis=-1)
f.reshape(300,300**3) ----> This is slow, as if it is using compute()