-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: linalg.expm: converting NaN to int #21618
Comments
where does it do that? |
|
Test case from python-control: from numpy import array, zeros, linspace |
Is this zero order hold discretized? What is the array that goes into expm? Because this is an overflow issue and should be handled first, not a NaN conversion problem. |
normA is 0 and log2 is called with NaN |
The array is nonzero so that should not happen and if it is 0, that should return -inf. Let me check control library first how this model is discretized. We are treating the symptom we need the array that goes into expm. |
This model does go into the expm route because U is nonzero . What do you get out of this example? Could you please give a full account of what the issue is? So something is happening here |
(Pdb) p A |
If that is the array then on main branch I get >>> la.expm(np.array([[-9.09111111e+03, -5.05000000e+03, 1.01000000e+03,0.00000000e+00],
[ 1.11111111e+03, -1.11111111e+02, 0.00000000e+00,0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,1.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,0.00000000e+00]])
array([[0. , 0. , 0.01694884, 0.01707782],
[0. , 0. , 0.16948837, 0.16925281],
[0. , 0. , 1. , 1. ],
[0. , 0. , 0. , 1. ]]) |
pick_pade_structure(Am) is returning 13, -2147483638 |
This is what I get on main In [8]: from scipy.linalg._matfuncs_expm import pick_pade_structure
In [9]: Am = np.empty((5, 4, 4), dtype=float)
In [10]: Am[0] = np.array([[-9.09111111e+03, -5.05000000e+03, 1.01000000e+03,
...: ...: 0.00000000e+00],
...: ...: [ 1.11111111e+03, -1.11111111e+02, 0.00000000e+00,
...: ...: 0.00000000e+00],
...: ...: [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
...: ...: 1.00000000e+00],
...: ...: [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
...: ...: 0.00000000e+00]])
In [11]: pick_pade_structure(Am)
Out[11]: (13, 11) Could you please check if you are on latest commit on |
11 is the result of UNDEFINED BEHAVIOUR. You cannot trust it. |
Again, we are trying to find the root cause not the solution, I know where to put the guards if there is an overflow/undeflow. That is not the issue. We need to find where things go wrong. You are still fixing the resulting issue. Something is causing an overflow/underflow. So let's stop discussing about undefined behavior and find why it is causing a norm 0 on your machine. And it should return |
temp/normA is 0/0 is NaN |
You array is nonzero so normA can't be 0 because if these lines scipy/scipy/linalg/_matfuncs_expm.c Lines 616 to 618 in 860a46b
Next time it is modified is here scipy/scipy/linalg/_matfuncs_expm.c Line 753 in 860a46b
pow result should be 0 I don't see how. |
The debugger is always right. |
Then please use it properly and check the value of |
11 is the result of UNDEFINED BEHAVIOUR. This the ULTIMATE SIN in programming! |
pick_pade_structure tries to convert NaN to int which is a big no-no and
results in undefined behaviour
The text was updated successfully, but these errors were encountered: