Checks whether or not the requested number of threads has a valid value. Parameters ---------- numThreads : int or str The requested number of threads, should either be a strictly positive integer or "max" or None Returns ------- numThreads : int Corrected n
(numThreads)
| 1457 | |
| 1458 | |
| 1459 | def check_number_threads(numThreads): |
| 1460 | """Checks whether or not the requested number of threads has a valid value. |
| 1461 | |
| 1462 | Parameters |
| 1463 | ---------- |
| 1464 | numThreads : int or str |
| 1465 | The requested number of threads, should either be a strictly positive integer or "max" or None |
| 1466 | |
| 1467 | Returns |
| 1468 | ------- |
| 1469 | numThreads : int |
| 1470 | Corrected number of threads |
| 1471 | """ |
| 1472 | if (numThreads is None) or ( |
| 1473 | isinstance(numThreads, str) and numThreads.lower() == "max" |
| 1474 | ): |
| 1475 | return -1 |
| 1476 | if (not isinstance(numThreads, int)) or numThreads < 1: |
| 1477 | raise ValueError( |
| 1478 | 'numThreads should either be "max" or a strictly positive integer' |
| 1479 | ) |
| 1480 | return numThreads |
| 1481 | |
| 1482 | |
| 1483 | def fun_to_numpy(fun, arr, nx, warn=True): |