You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a bug in the connect function in the bdalg.py:
335: elif outp < 0 and -outp >= -sys.outputs:
if outp < 0, the index meant is -outp because the negative sign is to tell it is negative feedback.
(-outp) must be in the range [1, sys.outputs]. As outp < 0, -outp > 0 already. Hence, the remaining thing is that -outp <= sys.outputs. The code must be corrected like this:
It looks to me that the intention of the current code is to neglect interconnections out of range .
Hence, the result will be the same as that only with valid interconnections.
Volumes/ssd1/Applications/anaconda3/lib/python3.7/site-packages/control/bdalg.py in connect(sys, Q, inputv, outputv)
334 K[inp,outp-1] = 1.
335 elif outp < 0 and -outp >= -sys.outputs:
--> 336 K[inp,-outp-1] = -1.
337 sys = sys.feedback(np.array(K), sign=1)
338
IndexError: index 2 is out of bounds for axis 1 with size 2
I guess the code needs a range check of the variable inp also.
~/Documents/src/python-control-dev/python-control/control/bdalg.py in connect(sys, Q, inputv, outputv)
332 for outp in r[1:]:
333 if outp > 0 and outp <= sys.outputs:
--> 334 K[inp,outp-1] = 1.
335 elif outp < 0 and -outp >= -sys.outputs:
336 K[inp,-outp-1] = -1.
IndexError: index 6 is out of bounds for axis 0 with size 6
Do we want to ignore out-of-range input and output indices here, or raise an error? I'd lean towards reporting an error. This applies to Q, inputv, and outputv.
Agree, it should raise an error. I'm bogged down in a bunch of other things right now, but hope to have some time first week of September. If someone else wants to take a look between now and then, that would be great.
Activity
murrayrm commentedon Jun 20, 2020
If you can generate a simple example that illustrates the bug, this would help us create a unit test to go along with the fix.
SeungKil-Paek commentedon Jun 21, 2020
It looks to me that the intention of the current code is to neglect interconnections out of range .
Hence, the result will be the same as that only with valid interconnections.
I made test code like this:
However, the test ends with IndexError.
I guess the code needs a range check of the variable
inpalso.sawyerbfuller commentedon Jun 22, 2020
I encountered a similar issue, but I'm not sure if it's the same:
gives
roryyorke commentedon Aug 22, 2020
Do we want to ignore out-of-range input and output indices here, or raise an error? I'd lean towards reporting an error. This applies to Q, inputv, and outputv.
murrayrm commentedon Aug 22, 2020
Agree, it should raise an error. I'm bogged down in a bunch of other things right now, but hope to have some time first week of September. If someone else wants to take a look between now and then, that would be great.
sawyerbfuller commentedon Aug 22, 2020
I second Richard’s sentiment - should raise an error.
bdalg.connect: added and fixed index checks to fix python-control#421;…
sawyerbfuller commentedon Dec 19, 2020
Ok I think I fixed it in #474. The error that I found above that I thought was related was actually in other code.