def _workers_to_num_threads(w): """Handle conversion of workers to a positive number of threads in the same way as scipy.fft.helpers._workers. """ if w is None: return get_workers() _w = int(w) if (_w == 0): raise ValueError("Number of workers must be nonzero") if (_w < 0): _w += _hardware_counts.get_cpu_count() + 1 if _w <= 0: raise ValueError("workers value out of range; got {}, must not be" " less than {}".format( w, -_hardware_counts.get_cpu_count())) return _w
def _workers_to_threads(workers): """Handle conversion of workers to a positive number of threads in the same way as scipy.fft.helpers._workers. """ if workers is None: return get_workers() if workers < 0: if workers >= -_cpu_count: workers += 1 + _cpu_count else: raise ValueError("workers value out of range; got {}, must not be" " less than {}".format(workers, -_cpu_count)) elif workers == 0: raise ValueError("workers must not be zero") return workers
def test_set_get_workers(): cpus = os.cpu_count() assert fft.get_workers() == 1 with fft.set_workers(4): assert fft.get_workers() == 4 with fft.set_workers(-1): assert fft.get_workers() == cpus assert fft.get_workers() == 4 assert fft.get_workers() == 1 with fft.set_workers(-cpus): assert fft.get_workers() == 1