Currently, if the reshape_vectors field of the PythonConfig is True and use_numba is False, the only way an IndexError will be raised from generated code is if an out of bounds index is used on one of the inputs.
Consequently, this means that if you pass in a vector which is large enough (say, a row vector where a column vector is needed, but only the first entry of the column vector is needed), the code will silently work.
This is probably not what the user would want, and is inconsistent with what we do when use_numba=True (where we check that the input shape is exactly something allowed).
So, I've changed the generated code use_numba=False code to be more analagous to the use_numba=True code.
Other notes:
I also moved the jinja code for checking the array size and reshaping if appropriate to a seperate macro (check_size_and_reshape). This was purely for readability.
In the unit test I added, I only test with reshape_vectors=True. As a practical matter, I didn't test with reshape_vectors=False because our test infrastructure already present checks that the input vector of a function equals the output of a function. But if reshape_vectors=False, since the input is simply too large, the code silently works, producing an output of the correct size (i.e., smaller than the input vector, meaning they're not equal). I didn't want to go through the work of changing assert_config_works because it would make the function more complicated, and it seems strange to test that the function gives a "correct" output when you give it an invalid input.
Currently, if the
reshape_vectors
field of thePythonConfig
isTrue
anduse_numba
isFalse
, the only way anIndexError
will be raised from generated code is if an out of bounds index is used on one of the inputs.Consequently, this means that if you pass in a vector which is large enough (say, a row vector where a column vector is needed, but only the first entry of the column vector is needed), the code will silently work.
This is probably not what the user would want, and is inconsistent with what we do when
use_numba=True
(where we check that the input shape is exactly something allowed).So, I've changed the generated code
use_numba=False
code to be more analagous to theuse_numba=True
code.Other notes:
check_size_and_reshape
). This was purely for readability.reshape_vectors=True
. As a practical matter, I didn't test withreshape_vectors=False
because our test infrastructure already present checks that the input vector of a function equals the output of a function. But ifreshape_vectors=False
, since the input is simply too large, the code silently works, producing an output of the correct size (i.e., smaller than the input vector, meaning they're not equal). I didn't want to go through the work of changingassert_config_works
because it would make the function more complicated, and it seems strange to test that the function gives a "correct" output when you give it an invalid input.