cKDTree_MP.py 文件源码

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

项目:osm_rg 作者: Scitator 项目源码 文件源码
def pquery(self, x_list, k=1, eps=0, p=2,
               distance_upper_bound=np.inf):
        x = np.array(x_list)
        nx, mx = x.shape
        shmem_x = mp.Array(ctypes.c_double, nx * mx)
        shmem_d = mp.Array(ctypes.c_double, nx * k)
        shmem_i = mp.Array(ctypes.c_double, nx * k)

        _x = shmem_as_nparray(shmem_x).reshape((nx, mx))
        _d = shmem_as_nparray(shmem_d).reshape((nx, k))

        _i = shmem_as_nparray(shmem_i)
        if k != 1:
            _i = _i.reshape((nx, k))

        _x[:, :] = x

        nprocs = num_cpus()
        scheduler = Scheduler(nx, nprocs)

        ierr = mp.Value(ctypes.c_int, 0)

        query_args = (scheduler,
                      self.shmem_data, self.n, self.m, self.leafsize,
                      shmem_x, nx, shmem_d, shmem_i,
                      k, eps, p, distance_upper_bound,
                      ierr
                      )
        pool = [mp.Process(target=_pquery, args=query_args) for n in
                range(nprocs)]
        for p in pool: p.start()
        for p in pool: p.join()
        if ierr.value != 0:
            raise RuntimeError('%d errors in worker processes' % (ierr.value))

        return _d.copy(), _i.astype(int).copy()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号