Skip to content

Commit 758fa9d

Browse files
committed
Add test and fix for mismatched row outputs
1 parent 8ac3adc commit 758fa9d

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

control/bdalg.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,15 @@ def combine(tf_array):
580580
# Iterate over
581581
num = []
582582
den = []
583-
for row in ensured_tf_array:
583+
for row_index, row in enumerate(ensured_tf_array):
584584
for j_out in range(row[0].noutputs):
585585
num_row = []
586586
den_row = []
587587
for col in row:
588+
if col.noutputs != row[0].noutputs:
589+
raise ValueError(
590+
f"Mismatched number of transfer function outputs in row {row_index}."
591+
)
588592
for j_in in range(col.ninputs):
589593
num_row.append(col.num[j_out][j_in])
590594
den_row.append(col.den[j_out][j_in])

control/tests/bdalg_test.py

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,65 @@ def test_split(self, tf_array, tf):
756756
],
757757
ValueError,
758758
),
759+
# Incompatible dimensions
760+
(
761+
[
762+
[
763+
ctrl.TransferFunction(
764+
[
765+
[
766+
[1],
767+
]
768+
],
769+
[
770+
[
771+
[1, 1],
772+
]
773+
],
774+
),
775+
ctrl.TransferFunction(
776+
[
777+
[[2], [1]],
778+
[[1], [3]],
779+
],
780+
[
781+
[[1, 0], [1, 0]],
782+
[[1, 0], [1, 0]],
783+
],
784+
),
785+
],
786+
],
787+
ValueError,
788+
),
789+
(
790+
[
791+
[
792+
ctrl.TransferFunction(
793+
[
794+
[[2], [1]],
795+
[[1], [3]],
796+
],
797+
[
798+
[[1, 0], [1, 0]],
799+
[[1, 0], [1, 0]],
800+
],
801+
),
802+
ctrl.TransferFunction(
803+
[
804+
[
805+
[1],
806+
]
807+
],
808+
[
809+
[
810+
[1, 1],
811+
]
812+
],
813+
),
814+
],
815+
],
816+
ValueError,
817+
),
759818
],
760819
)
761820
def test_error_combine(self, tf_array, exception):
@@ -769,9 +828,9 @@ def _tf_close_coeff(tf_a, tf_b, rtol=1e-5, atol=1e-8):
769828
770829
Parameters
771830
----------
772-
tf_a : control.TransferFunction
831+
tf_a : TransferFunction
773832
First transfer function.
774-
tf_b : control.TransferFunction
833+
tf_b : TransferFunction
775834
Second transfer function.
776835
rtol : float
777836
Relative tolerance for :func:`np.allclose`.

0 commit comments

Comments
 (0)