It seems very reasonable to iterate over parameter arrays such as
num_threads = np.array([2, 4]) # num_threads[n] is of type numpy.int64
for n in range(2):
result[n] = svmbir.recon( ..., num_threads=num_threads[n])
However this results in the somewhat useless warning:
UserWarning: Parameter num_threads is not a valid int. Setting to default.
The warning comes from _utils.py:
if not (isinstance(num_threads, int) and (num_threads > 0)):
warnings.warn(f"Parameter num_threads is not a valid int. Setting to default.")
num_threads = None
Problems with this:
- First I thought that
UserWarning: Parameter num_threads is not a valid int. Setting to default.
will take my 2 (numpy.int64) and convert it to 2 (int). But instead it will completely disregard the 2 and set it to the number of cores!!!
In my opinion the hard setting to the defaults whenever an input is not precisely what is expected seems very strict and can lead to unexpected behavior.
-
Whenever a variable get checked it is advised to display the variable and type. Something like
warnings.warn(f"Parameter num_threads ({num_threads}, {type(num_threads)}) is not a valid int. Setting to default.")
would give UserWarning: Parameter num_threads (2, <class 'numpy.int64'>) is not a valid int. Setting to default. Now it is so much easier to understand what is wrong.
-
when num_threads=None this warning is still displayed and then num_threads is again set to None.
-
In my opinion numpy.int64 should be a perfectly reasonable input. Why not do
isinstance(num_threads, (int, np.int64, np.int32))? There may also be more elegant ways of doing this.
-
The logic in the if clause is not obvious. Can there be more parentheses?
-
In _utils.py there are more instances like this for other parameters that should be improved.
It seems very reasonable to iterate over parameter arrays such as
However this results in the somewhat useless warning:
UserWarning: Parameter num_threads is not a valid int. Setting to default.The warning comes from
_utils.py:Problems with this:
UserWarning: Parameter num_threads is not a valid int. Setting to default.will take my
2 (numpy.int64)and convert it to2 (int). But instead it will completely disregard the2and set it to the number of cores!!!In my opinion the hard setting to the defaults whenever an input is not precisely what is expected seems very strict and can lead to unexpected behavior.
Whenever a variable get checked it is advised to display the variable and type. Something like
warnings.warn(f"Parameter num_threads ({num_threads}, {type(num_threads)}) is not a valid int. Setting to default.")would give
UserWarning: Parameter num_threads (2, <class 'numpy.int64'>) is not a valid int. Setting to default.Now it is so much easier to understand what is wrong.when
num_threads=Nonethis warning is still displayed and thennum_threadsis again set toNone.In my opinion
numpy.int64should be a perfectly reasonable input. Why not doisinstance(num_threads, (int, np.int64, np.int32))? There may also be more elegant ways of doing this.The logic in the if clause is not obvious. Can there be more parentheses?
In
_utils.pythere are more instances like this for other parameters that should be improved.