def get_mmap(X):
"""
converts a numpy array to
a numpy memmory mapped array
"""
#TODO: use tempfile.NamedTemporaryFile
if type(X) is np.core.memmap:
return X
fid = 0
filename = mmap_base+"data"+str(fid)+".dat"
for i in range(max_mmap_files):
if os.path.isfile(filename):
fid += 1
filename = mmap_base+"data"+str(fid)+".dat"
else:
break
_X = np.memmap(filename, dtype='float64', mode='w+', shape=X.shape)
_X[:] = X[:]
del X
import gc
gc.collect()
return _X
评论列表
文章目录