Skip to content

Commit da3bb13

Browse files
authored
Merge pull request #1221 from marko1olo/fix-zero-input-interconnect-dmatrix
Fix zero-input interconnect D matrix shape
2 parents 146ccee + 320d01a commit da3bb13

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

control/statesp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,7 @@ def _ssmatrix(data, axis=1, square=None, rows=None, cols=None, name=None):
22952295
22962296
Returns
22972297
-------
2298-
arr : 2D array, with shape (0, 0) if a is empty
2298+
arr : 2D array, with shape (0, 0) for empty vectors or matrices
22992299
23002300
"""
23012301
# Process the name of the object, if available
@@ -2310,9 +2310,9 @@ def _ssmatrix(data, axis=1, square=None, rows=None, cols=None, name=None):
23102310
if (ndim > 2):
23112311
raise ValueError(f"state-space matrix{name} must be 2-dimensional")
23122312

2313-
elif (ndim == 2 and shape == (1, 0)) or \
2314-
(ndim == 1 and shape == (0, )):
2315-
# Passed an empty matrix or empty vector; change shape to (0, 0)
2313+
elif (ndim == 2 and shape == (0, 0)) or \
2314+
(ndim == 1 and shape == (0, )):
2315+
# Passed a 0-by-0 matrix or empty vector; change shape to (0, 0)
23162316
shape = (0, 0)
23172317

23182318
elif ndim == 1:

control/tests/interconnect_test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,36 @@ def test_linear_interconnect():
432432
outlist=['plant.y'], outputs='y')
433433
assert clsys.syslist[0].name == 'ctrl'
434434

435+
436+
def test_interconnect_zero_input_one_output():
437+
plant = ct.ss(
438+
[[1, 1], [0, -2]],
439+
[[0], [1]],
440+
[[1, 0]],
441+
[[0]],
442+
inputs=['u'],
443+
outputs=['y'],
444+
name='plant',
445+
dt=True,
446+
)
447+
controller = ct.ss(
448+
[[2.25, 1], [-5, -0.5]],
449+
[[-1.25], [4.5]],
450+
[[-0.5, 1.5]],
451+
[[0]],
452+
inputs=['y'],
453+
outputs=['u'],
454+
name='controller',
455+
dt=True,
456+
)
457+
458+
sys = ct.interconnect([plant, controller], inplist=None, outlist=['y'])
459+
460+
assert sys.ninputs == 0
461+
assert sys.noutputs == 1
462+
assert sys.D.shape == (1, 0)
463+
464+
435465
@pytest.mark.parametrize(
436466
"connections, inplist, outlist, inputs, outputs", [
437467
pytest.param(

0 commit comments

Comments
 (0)