[WIP] override XERBLA to raise exception#127
[WIP] override XERBLA to raise exception#127bnavigator wants to merge 1 commit intopython-control:masterfrom
Conversation
|
OK, is this anyhow possible? How does the exception propagate back through the Fortran calls? AFAIK Fortran has no exception handling. After some searching, I see that the original LAPACK routine calls STOP on purpose. MKL does not do this. XERBLA seems to be called from just about every SLICOT function, and in MKL it only prints a message then returns, and in the LAPACK implementation it stops. It seems safer to me to just provide a neutralize Fortran XERBLA implementation for Slycot that behaves in an MKL way. |
|
The idea is to use F2PY callback arguments. The Fortran routine The simpler solution would be to just make |
|
I don't have the insight in Python's exception mechanism to determine if it is even possible and safe to pass an exception with Fortran routines on the F2PY call stack. If you have the experience for that, by all means, but I would take the safe route. |
I don't ;) You have a point here: I tested by executing >>> import slycot
>>> import numpy as np
>>> n=1000; m=3; p=2
>>> A = np.random.randn(n,n); B = np.random.randn(n,m)
>>> C = np.random.randn(p,n); D=np.random.randn(p,m)
>>> for i in range(500):
... try:
... slycot.sb10fd(n,m,p,0,1,1,A,B,C,D,1e-3,1)
... except TypeError:
... pass
... For this test, it doesn't matter if the exception currently raised is the desired SlycotError or the TypeError from my initial post above. This allocates a lot of memory during the loop and never frees it until the python process is ended. So you are probably right: Raising exceptions in a callback and thus never returning to the Fortran call stack is possible, but maybe not a good idea. I wonder if there will be any comments by F2PY people, reacting to my question in numpy/numpy#16277 |
Fixes #126 (eventually)
Trying to wrap the Fortran
XERBLAcall. Still having some issues with the parameter list.But: