diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2017-06-27 00:25:57 -0400 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2017-08-26 03:52:52 -0400 |
commit | 1f1e8265af27e7f602a0428acf06c8201ebef915 (patch) | |
tree | 2c2f3bee1a52e41b1da3d7a68f813837e63dbdad /numpy/lib/arraypad.py | |
parent | 0725fff599e78fd2438b603a341f122e81a908fa (diff) | |
download | numpy-1f1e8265af27e7f602a0428acf06c8201ebef915.tar.gz |
BUG: f2py: Convert some error messages printed to stderr to exceptions.
In f2py/src/fortranobject.c, the function `check_and_fix_dimensions` does
pretty much what it says on the tin:
/*
This function fills in blanks (that are -1\'s) in dims list using
the dimensions from arr. It also checks that non-blank dims will
match with the corresponding values in arr dimensions.
*/
There are several error conditions detected by the function. In the code
before this change, when the function detected such an error, it would
print a message to stderr and return 1.
In this change, when an error is detected in `check_and_fix_dimensions`,
an exception is set.
This new feature of `check_and_fix_dimensions` is used in three places
in the function `array_from_pyobj()`.
In each case, there was an old comment of the form:
/* XXX: set exception */
In this change, the exception is now set in `check_and_fix_dimensions()`,
so those comments have been removed.
For some error conditions, the new code changes the exception that is
raised. For example, here's a scipy test before this change:
```
In [5]: from scipy.linalg import _fblas as fblas
In [6]: a = np.array([[1., 0.], [0., -2.], [2., 3.]])
In [7]: b = np.array([[0., 1.], [1., 0.], [0, 1.]])
In [8]: fblas.dsyr2k(a=a, b=b, alpha=1.0, c=np.zeros((15, 8)))
0-th dimension must be fixed to 3 but got 15
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-8-bc4d51f8d016> in <module>()
----> 1 f(a=a, b=b, alpha=1.0, c=np.zeros((15, 8)))
error: failed in converting 2nd keyword `c' of _fblas.dsyr2k to C/Fortran array
```
After this change, we get:
```
In [2]: from scipy.linalg import _fblas as fblas
In [3]: a = np.array([[1., 0.], [0., -2.], [2., 3.]])
In [4]: b = np.array([[0., 1.], [1., 0.], [0, 1.]])
In [5]: fblas.dsyr2k(a=a, b=b, alpha=1.0, c=np.zeros((15, 8)))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-bc4d51f8d016> in <module>()
----> 1 f(a=a, b=b, alpha=1.0, c=np.zeros((15, 8)))
ValueError: 0-th dimension must be fixed to 3 but got 15
```
The spurious print has been changed to the exception message, but some
potentially useful information in the old exception message has been
lost.
Diffstat (limited to 'numpy/lib/arraypad.py')
0 files changed, 0 insertions, 0 deletions