def _create_cache_shared(xs, hparamss):
"""Create shared cache.
"""
cache_source = create_cache_source(xs, hparamss)
cache_shared = {}
# for k, v in cache_source.iteritems():
for k, v in six.iteritems(cache_source):
assert(v.dtype == np.float32 or v.dtype == np.float64 or
v.dtype == float)
n = len(v.reshape(-1))
shared_array_base = multiprocessing.Array(ctypes.c_double, n)
shape = v.shape
view = np.ctypeslib.as_array(shared_array_base.get_obj())
view = view.reshape(shape)
view[:] = v[:]
del view
cache_shared.update({k: (shared_array_base, shape)})
return cache_shared
评论列表
文章目录