Skip to content

Commit 6df0919

Browse files
committed
convert internal representation of TF num/den to ndarray (vs list^2)
1 parent 6c852c3 commit 6df0919

6 files changed

Lines changed: 177 additions & 158 deletions

File tree

control/bdalg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,8 @@ def combine_tf(tf_array):
600600
f"row {row_index}."
601601
)
602602
for j_in in range(col.ninputs):
603-
num_row.append(col.num[j_out][j_in])
604-
den_row.append(col.den[j_out][j_in])
603+
num_row.append(col._num[j_out, j_in])
604+
den_row.append(col._den[j_out, j_in])
605605
num.append(num_row)
606606
den.append(den_row)
607607
for row_index, row in enumerate(num):
@@ -657,8 +657,8 @@ def split_tf(transfer_function):
657657
for i_in in range(transfer_function.ninputs):
658658
row.append(
659659
tf.TransferFunction(
660-
transfer_function.num[i_out][i_in],
661-
transfer_function.den[i_out][i_in],
660+
transfer_function._num[i_out, i_in],
661+
transfer_function._den[i_out, i_in],
662662
dt=transfer_function.dt,
663663
)
664664
)

control/statesp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2291,7 +2291,7 @@ def _convert_to_statespace(sys, use_prefix_suffix=False, method=None):
22912291
D = empty((sys.noutputs, sys.ninputs), dtype=float)
22922292
for i, j in itertools.product(range(sys.noutputs),
22932293
range(sys.ninputs)):
2294-
D[i, j] = sys.num[i][j][0] / sys.den[i][j][0]
2294+
D[i, j] = sys._num[i, j][0] / sys._den[i, j][0]
22952295
newsys = StateSpace([], [], [], D, sys.dt)
22962296
else:
22972297
if not issiso(sys):

control/tests/bdalg_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,15 +903,15 @@ def _tf_close_coeff(tf_a, tf_b, rtol=1e-5, atol=1e-8):
903903
for i in range(tf_a.noutputs):
904904
for j in range(tf_a.ninputs):
905905
if not np.allclose(
906-
tf_a.num[i][j],
907-
tf_b.num[i][j],
906+
tf_a._num[i, j],
907+
tf_b._num[i, j],
908908
rtol=rtol,
909909
atol=atol,
910910
):
911911
return False
912912
if not np.allclose(
913-
tf_a.den[i][j],
914-
tf_b.den[i][j],
913+
tf_a._den[i, j],
914+
tf_b._den[i, j],
915915
rtol=rtol,
916916
atol=atol,
917917
):

control/tests/xferfcn_input_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def test_clean_part(num, fun, dtype):
6464
num_ = _clean_part(numa)
6565
ref_ = np.array(num, dtype=float, ndmin=3)
6666

67-
assert isinstance(num_, list)
68-
assert np.all([isinstance(part, list) for part in num_])
67+
assert isinstance(num_, np.ndarray)
68+
assert num_.ndim == 2
6969
for i, numi in enumerate(num_):
7070
assert len(numi) == ref_.shape[1]
7171
for j, numj in enumerate(numi):

control/tests/xferfcn_test.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def test_reverse_sign_mimo(self):
190190

191191
for i in range(sys3.noutputs):
192192
for j in range(sys3.ninputs):
193-
np.testing.assert_allclose(sys2.num[i][j], sys3.num[i][j])
194-
np.testing.assert_allclose(sys2.den[i][j], sys3.den[i][j])
193+
np.testing.assert_allclose(sys2._num[i, j], sys3._num[i, j])
194+
np.testing.assert_allclose(sys2._den[i, j], sys3._den[i, j])
195195

196196
# Tests for TransferFunction.__add__
197197

@@ -236,8 +236,8 @@ def test_add_mimo(self):
236236

237237
for i in range(sys3.noutputs):
238238
for j in range(sys3.ninputs):
239-
np.testing.assert_allclose(sys3.num[i][j], num3[i][j])
240-
np.testing.assert_allclose(sys3.den[i][j], den3[i][j])
239+
np.testing.assert_allclose(sys3._num[i, j], num3[i][j])
240+
np.testing.assert_allclose(sys3._den[i, j], den3[i][j])
241241

242242
# Tests for TransferFunction.__sub__
243243

@@ -284,8 +284,8 @@ def test_subtract_mimo(self):
284284

285285
for i in range(sys3.noutputs):
286286
for j in range(sys3.ninputs):
287-
np.testing.assert_allclose(sys3.num[i][j], num3[i][j])
288-
np.testing.assert_allclose(sys3.den[i][j], den3[i][j])
287+
np.testing.assert_allclose(sys3._num[i, j], num3[i][j])
288+
np.testing.assert_allclose(sys3._den[i, j], den3[i][j])
289289

290290
# Tests for TransferFunction.__mul__
291291

@@ -340,8 +340,8 @@ def test_multiply_mimo(self):
340340

341341
for i in range(sys3.noutputs):
342342
for j in range(sys3.ninputs):
343-
np.testing.assert_allclose(sys3.num[i][j], num3[i][j])
344-
np.testing.assert_allclose(sys3.den[i][j], den3[i][j])
343+
np.testing.assert_allclose(sys3._num[i, j], num3[i][j])
344+
np.testing.assert_allclose(sys3._den[i, j], den3[i][j])
345345

346346
# Tests for TransferFunction.__div__
347347

@@ -662,10 +662,10 @@ def test_convert_to_transfer_function(self):
662662

663663
for i in range(sys.noutputs):
664664
for j in range(sys.ninputs):
665-
np.testing.assert_array_almost_equal(tfsys.num[i][j],
666-
num[i][j])
667-
np.testing.assert_array_almost_equal(tfsys.den[i][j],
668-
den[i][j])
665+
np.testing.assert_array_almost_equal(
666+
tfsys._num[i, j], num[i][j])
667+
np.testing.assert_array_almost_equal(
668+
tfsys._den[i, j], den[i][j])
669669

670670
def test_minreal(self):
671671
"""Try the minreal function, and also test easy entry by creation
@@ -1121,8 +1121,10 @@ def test_repr(self, Hargs, ref):
11211121
H2 = eval(H.__repr__())
11221122
for p in range(len(H.num)):
11231123
for m in range(len(H.num[0])):
1124-
np.testing.assert_array_almost_equal(H.num[p][m], H2.num[p][m])
1125-
np.testing.assert_array_almost_equal(H.den[p][m], H2.den[p][m])
1124+
np.testing.assert_array_almost_equal(
1125+
H._num[p, m], H2._num[p, m])
1126+
np.testing.assert_array_almost_equal(
1127+
H._den[p, m], H2._den[p, m])
11261128
assert H.dt == H2.dt
11271129

11281130
def test_sample_named_signals(self):
@@ -1180,8 +1182,8 @@ def test_returnScipySignalLTI(self, mimotf):
11801182
sslti = mimotf.returnScipySignalLTI(strict=False)
11811183
for i in range(2):
11821184
for j in range(3):
1183-
np.testing.assert_allclose(sslti[i][j].num, mimotf.num[i][j])
1184-
np.testing.assert_allclose(sslti[i][j].den, mimotf.den[i][j])
1185+
np.testing.assert_allclose(sslti[i][j].num, mimotf._num[i, j])
1186+
np.testing.assert_allclose(sslti[i][j].den, mimotf._den[i, j])
11851187
if mimotf.dt == 0:
11861188
assert sslti[i][j].dt is None
11871189
else:

0 commit comments

Comments
 (0)