def test_threads(name, types, initialize_pnumpy, rng): """ Test that enabling the threading does not change the results """ ufunc = getattr(np, name) for in_dtypes, out_dtypes in types: # Skip object dtypes if any([o == 'object' for o in out_dtypes]): continue if any([o == 'object' for o in in_dtypes]): continue in_data, out_data = data(in_dtypes, out_dtypes, [1024, 1024], rng) if (name in ('power',) and issubclass(in_data[1].dtype.type, np.integer)): in_data[1] = np.abs(in_data[1]) in_data[1][in_data[1] < 0] = 0 if len(out_data) == 1: out_data = out_data[0] out1 = ufunc(*in_data, out=out_data) pnumpy.thread_enable() assert pnumpy.thread_isenabled() out2 = ufunc(*in_data, out=out_data) pnumpy.thread_disable() # may not work on datetime if not any([o == 'datetime64' for o in out_dtypes]): np.testing.assert_allclose(out1, out2, equal_nan=True)
def set_pnumpy_thread_count(num_threads: Optional[int]) -> None: """ Set the number of worker threads used by pnumpy; if set to zero/None, disables threading. """ if num_threads is not None and num_threads > 0: pnumpy.thread_enable() pnumpy.thread_setworkers(num_threads) else: pnumpy.thread_disable()
def setup(self, nthreads): np.seterr(all='ignore') if nthreads > 0: pnumpy.thread_enable() pnumpy.thread_setworkers(nthreads) else: pnumpy.thread_disable() try: self.f = getattr(np, ufunc) except AttributeError: raise NotImplementedError() self.args = [] for t, a in get_squares().items(): arg = (a, ) * self.f.nin try: self.f(*arg) except TypeError: continue self.args.append(arg)