MCPcopy
hub / github.com/thampiman/reverse-geocoder / pquery

Method pquery

reverse_geocoder/cKDTree_MP.py:66–102  ·  view source on GitHub ↗

Function to parallelly query the K-D Tree

(self, x_list, k=1, eps=0, p=2,
               distance_upper_bound=np.inf)

Source from the content-addressed store, hash-verified

64 super(cKDTree_MP, self).__init__(_data, leafsize=leafsize)
65
66 def pquery(self, x_list, k=1, eps=0, p=2,
67 distance_upper_bound=np.inf):
68 """
69 Function to parallelly query the K-D Tree
70 """
71 x = np.array(x_list)
72 nx, mx = x.shape
73 shmem_x = mp.Array(ctypes.c_double, nx*mx)
74 shmem_d = mp.Array(ctypes.c_double, nx*k)
75 shmem_i = mp.Array(ctypes.c_double, nx*k)
76
77 _x = shmem_as_nparray(shmem_x).reshape((nx, mx))
78 _d = shmem_as_nparray(shmem_d).reshape((nx, k))
79
80 _i = shmem_as_nparray(shmem_i)
81 if k != 1:
82 _i = _i.reshape((nx, k))
83
84 _x[:, :] = x
85
86 nprocs = num_cpus()
87 scheduler = Scheduler(nx, nprocs)
88
89 ierr = mp.Value(ctypes.c_int, 0)
90
91 query_args = (scheduler,
92 self.shmem_data, self.n, self.m, self.leafsize,
93 shmem_x, nx, shmem_d, shmem_i,
94 k, eps, p, distance_upper_bound,
95 ierr)
96 pool = [mp.Process(target=_pquery, args=query_args) for _ in range(nprocs)]
97 for p in pool: p.start()
98 for p in pool: p.join()
99 if ierr.value != 0:
100 raise RuntimeError('%d errors in worker processes' % (ierr.value))
101
102 return _d.copy(), _i.astype(int).copy()
103
104class Scheduler:
105 """

Callers 1

queryMethod · 0.80

Calls 3

shmem_as_nparrayFunction · 0.85
num_cpusFunction · 0.85
SchedulerClass · 0.85

Tested by

no test coverage detected