「が」 "DASKアレイは多数の小さなアレイに大きな配列を切断する、ブロックされたアルゴリズムを使用してnumpyのndarrayインターフェースのサブセットを実装しています。これは、私たちのすべてを使用してメモリより大きなアレイに計算することができコア "" "
そして
""" dask.arrayライブラリはnumpyのから次のインターフェイスをサポートしています。
...
テンソル収縮/内積/行列乗算、説明のためtensordot
「」」
実施例、DASK VS numpyの性能を確認するために異なる寸法を試みます。
import dask as dk
import tables
import numpy as np
from time import time
outpath = "/tmp/"
lenx = 300
leny = 100000
fname = "t{0:03d}_{1:03d}.h5".format(int(lenx/100),int(leny/100))
def write_test_file():
h5file = tables.open_file(outpath+fname,"w")
pres = np.random.random((lenx,leny))
atom = tables.Float64Atom()
filters = tables.Filters(complevel=6, complib='zlib', shuffle=True)
print("Writing data")
t01 = time()
h5file.create_carray(h5file.root,'pressure',atom,(lenx,leny),filters=filters,obj=pres)
h5file.flush()
del pres
t02 = time()
lines = np.random.random((leny,lenx))
h5file.create_carray(h5file.root,"lines",atom,(leny,lenx),filters=filters,obj=lines)
t03 = time()
print("Data written",t03-t02,t02-t01)
h5file.close()
def numpy_dot_test():
print("Open data")
t1 = time()
h5open = tables.open_file(outpath+fname,mode="r")
pressureObject = h5open.get_node("/", "pressure")
print(pressureObject.shape)
linesObject=h5open.get_node("/","lines")
print(linesObject.shape)
t2 = time()
ohoo = np.array(linesObject).dot(np.array(pressureObject))
t3 = time()
print(ohoo.shape,np.mean(ohoo))
print("matmul time:",t3-t2,t2-t1)
h5open.close()
def dask_dot_test():
import h5py
import dask.array as da
h5open2 = h5py.File(outpath+fname)
t21=time()
d1=da.from_array(h5open2["/pressure"],chunks=(100,lenx))
d2=da.from_array(h5open2["/lines"],chunks=(leny,100))
t22=time()
print('d1,d2',d1.shape,d2.shape)
d1.dot(d2).to_hdf5(outpath+'output.h5','testout')
t23=time()
print('ohoo',t23-t22,t22-t21)
h5open2.close()
write_test_file()
## numpy_dot_test()
dask_dot_test()
あなたのデータがどのように大きな理解し、それは本当にメモリに収まらない場合は、それがメモリに収まるdask.pydata.org – kakk11
ような何かを試してみてください。問題はnp.dot()です。巨大な配列を扱うことはできません。 XがいくつかのGBsのサイズが非常に大きい場合、np.transpose(X)も動作しません@ kakk11 – Kavan
配列の大きさは、明らかにnp.dotが新しい行列を作成し、より多くのメモリを要求します。 – kakk11