Closed alexeperon closed 10 months ago
Thanks for picking this error up @alexeperon! I am in favour of changing the order to fix this bug.
I just checked what enumerate actually does when you apply it to a dict and the resulting iterator just returns an integer and the corresponding key. Thus the noise input will be a string, which is an Iterable leading to infinite recursion.
[rsatoolbox 0.1.3, python 3.9.16]
When calculating crossnobis distance, it is possible to input noise via a dictionary of residuals. However, currently this results in an recursion and timeout due to the _check_noise function.
This is because the elif clause checks first to see if the input type is iterable, then if it is a dictionary. As dictionaries are iterable, this then selects the wrong if clause.
current code (lines 465 to 489):
To solve this, a simple option would be the following, which checks the input is not a dictionary. Another solution would be to simply put the dict elif clause before the Iterable elif clause.
[I'm not sure why it results in a recursion instead of a simple error - as I read it, this sends input of the form (int, n_channel) back to the _check_noise function, This should result in an ValueError, but maybe I am missing something about how embedded functions work.]
Code to reproduce the error (assuming data already calculated):
Hope this is useful!
Alex