cache_mc_shared.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:bmlingam 作者: taku-y 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号