Skip to content

Commit b70c7fc

Browse files
committed
add iosys.repr_show_count and defualt to True
1 parent 0698afc commit b70c7fc

File tree

10 files changed

+138
-81
lines changed

10 files changed

+138
-81
lines changed

control/frdata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def _repr_eval_(self):
425425
smooth=(self._ifunc and ", smooth=True") or "")
426426

427427
out += self._dt_repr()
428-
if len(labels := self._label_repr(show_count=False)) > 0:
428+
if len(labels := self._label_repr()) > 0:
429429
out += ",\n" + labels
430430

431431
out += ")"

control/iosys.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
'iosys.converted_system_name_prefix': '',
3333
'iosys.converted_system_name_suffix': '$converted',
3434
'iosys.repr_format': 'eval',
35+
'iosys.repr_show_count': True,
3536
}
3637

3738

@@ -313,7 +314,9 @@ def repr_format(self):
313314
def repr_format(self, value):
314315
self._repr_format = value
315316

316-
def _label_repr(self, show_count=True):
317+
def _label_repr(self, show_count=None):
318+
show_count = config._get_param(
319+
'iosys', 'repr_show_count', show_count, True)
317320
out, count = "", 0
318321

319322
# Include the system name if not generic

control/statesp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def _repr_eval_(self):
394394
C=self.C.__repr__(), D=self.D.__repr__())
395395

396396
out += super()._dt_repr(separator=",\n", space="")
397-
if len(labels := super()._label_repr(show_count=False)) > 0:
397+
if len(labels := super()._label_repr()) > 0:
398398
out += ",\n" + labels
399399

400400
out += ")"

control/tests/frd_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,9 @@ def test_repr_str(self):
468468
ref_common = "FrequencyResponseData(\n" \
469469
"array([[[1. +0.j , 0.9 +0.1j, 0.1 +2.j , 0.05+3.j ]]]),\n" \
470470
"array([ 0.1, 1. , 10. , 100. ]),"
471-
ref0 = ref_common + "\nname='sys0')"
472-
ref1 = ref_common + " smooth=True," + "\nname='sys1')"
471+
ref0 = ref_common + "\nname='sys0', outputs=1, inputs=1)"
472+
ref1 = ref_common + " smooth=True," + \
473+
"\nname='sys1', outputs=1, inputs=1)"
473474
sysm = ct.frd(
474475
np.matmul(array([[1], [2]]), sys0.fresp), sys0.omega, name='sysm')
475476

control/tests/iosys_test.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,32 +2290,31 @@ def test_signal_indexing():
22902290

22912291
@slycotonly
22922292
@pytest.mark.parametrize("fcn, spec, expected, missing", [
2293-
(ct.ss, {}, "", r"states|inputs|outputs|dt|name"),
2294-
(ct.tf, {}, "", r"states|inputs|outputs|dt|name"),
2295-
(ct.frd, {}, "", r"states|inputs|outputs|dt|name"),
2296-
(ct.ss, {'dt': 0.1}, ".*\ndt=0.1", r"states|inputs|outputs|name"),
2297-
(ct.tf, {'dt': 0.1}, ".*\ndt=0.1", r"states|inputs|outputs|name"),
2298-
(ct.frd, {'dt': 0.1},
2299-
".*\ndt=0.1", r"states|inputs|outputs|name"),
2300-
(ct.ss, {'dt': True}, "\ndt=True", r"states|inputs|outputs|name"),
2301-
(ct.ss, {'dt': None}, "\ndt=None", r"states|inputs|outputs|name"),
2302-
(ct.ss, {'dt': 0}, "", r"states|inputs|outputs|dt|name"),
2293+
(ct.ss, {}, "states=4, outputs=3, inputs=2", r"dt|name"),
2294+
(ct.tf, {}, "outputs=3, inputs=2", r"dt|states|name"),
2295+
(ct.frd, {}, "outputs=3, inputs=2", r"dt|states|name"),
2296+
(ct.ss, {'dt': 0.1}, ".*\ndt=0.1,\nstates=4, outputs=3, inputs=2", r"name"),
2297+
(ct.tf, {'dt': 0.1}, ".*\ndt=0.1,\noutputs=3, inputs=2", r"states|name"),
2298+
(ct.frd, {'dt': 0.1}, ".*\ndt=0.1,\noutputs=3, inputs=2", r"states|name"),
2299+
(ct.ss, {'dt': True}, "\ndt=True,\nstates=4, outputs=3, inputs=2", r"name"),
2300+
(ct.ss, {'dt': None}, "\ndt=None,\nstates=4, outputs=3, inputs=2", r"name"),
2301+
(ct.ss, {'dt': 0}, "states=4, outputs=3, inputs=2", r"dt|name"),
23032302
(ct.ss, {'name': 'mysys'}, "\nname='mysys'", r"dt"),
23042303
(ct.tf, {'name': 'mysys'}, "\nname='mysys'", r"dt|states"),
23052304
(ct.frd, {'name': 'mysys'}, "\nname='mysys'", r"dt|states"),
23062305
(ct.ss, {'inputs': ['u1']},
2307-
r"[\n]inputs=\['u1'\]", r"states|outputs|dt|name"),
2306+
r"[\n]states=4, outputs=3, inputs=\['u1'\]", r"dt|name"),
23082307
(ct.tf, {'inputs': ['u1']},
2309-
r"[\n]inputs=\['u1'\]", r"outputs|dt|name"),
2308+
r"[\n]outputs=3, inputs=\['u1'\]", r"dt|name"),
23102309
(ct.frd, {'inputs': ['u1'], 'name': 'sampled'},
2311-
r"[\n]name='sampled', inputs=\['u1'\]", r"outputs|dt"),
2310+
r"[\n]name='sampled', outputs=3, inputs=\['u1'\]", r"dt"),
23122311
(ct.ss, {'outputs': ['y1']},
2313-
r"[\n]outputs=\['y1'\]", r"states|inputs|dt|name"),
2312+
r"[\n]states=4, outputs=\['y1'\], inputs=2", r"dt|name"),
23142313
(ct.ss, {'name': 'mysys', 'inputs': ['u1']},
2315-
r"[\n]name='mysys', inputs=\['u1'\]", r"states|outputs|dt"),
2314+
r"[\n]name='mysys', states=4, outputs=3, inputs=\['u1'\]", r"dt"),
23162315
(ct.ss, {'name': 'mysys', 'states': [
23172316
'long_state_1', 'long_state_2', 'long_state_3']},
2318-
r"[\n]name='.*', states=\[.*\]\)", r"inputs|outputs|dt"),
2317+
r"[\n]name='.*', states=\[.*\],\noutputs=3, inputs=2\)", r"dt"),
23192318
])
23202319
@pytest.mark.parametrize("format", ['info', 'eval'])
23212320
def test_iosys_repr(fcn, spec, expected, missing, format):

control/tests/statesp_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def test_repr(self, sys322):
746746
[ 1., 4., 3.]]),
747747
array([[-2., 4.],
748748
[ 0., 1.]]),
749-
name='sys322'{dt})"""
749+
name='sys322'{dt}, states=3, outputs=2, inputs=2)"""
750750
assert ct.iosys_repr(sys322, format='eval') == ref322.format(dt='')
751751
sysd = StateSpace(sys322.A, sys322.B,
752752
sys322.C, sys322.D, 0.4)

control/tests/xferfcn_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,19 +1087,22 @@ def test_html_repr(self):
10871087
[(([-1., 4.], [1., 3., 5.]),
10881088
"TransferFunction(\n"
10891089
"array([-1., 4.]),\n"
1090-
"array([1., 3., 5.]))"),
1090+
"array([1., 3., 5.]),\n"
1091+
"outputs=1, inputs=1)"),
10911092
(([2., 3., 0.], [1., -3., 4., 0], 2.0),
10921093
"TransferFunction(\n"
10931094
"array([2., 3., 0.]),\n"
10941095
"array([ 1., -3., 4., 0.]),\n"
1095-
"dt=2.0)"),
1096+
"dt=2.0,\n"
1097+
"outputs=1, inputs=1)"),
10961098
(([[[0, 1], [2, 3]], [[4, 5], [6, 7]]],
10971099
[[[6, 7], [4, 5]], [[2, 3], [0, 1]]]),
10981100
"TransferFunction(\n"
10991101
"[[array([1]), array([2, 3])],\n"
11001102
" [array([4, 5]), array([6, 7])]],\n"
11011103
"[[array([6, 7]), array([4, 5])],\n"
1102-
" [array([2, 3]), array([1])]])"),
1104+
" [array([2, 3]), array([1])]],\n"
1105+
"outputs=2, inputs=2)"),
11031106
(([[[0, 1], [2, 3]], [[4, 5], [6, 7]]],
11041107
[[[6, 7], [4, 5]], [[2, 3], [0, 1]]],
11051108
0.5),
@@ -1108,7 +1111,8 @@ def test_html_repr(self):
11081111
" [array([4, 5]), array([6, 7])]],\n"
11091112
"[[array([6, 7]), array([4, 5])],\n"
11101113
" [array([2, 3]), array([1])]],\n"
1111-
"dt=0.5)"),
1114+
"dt=0.5,\n"
1115+
"outputs=2, inputs=2)"),
11121116
])
11131117
def test_loadable_repr(self, Hargs, ref):
11141118
"""Test __repr__ printout."""

control/xferfcn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def _repr_eval_(self):
509509
out += "],\n[" if entry is self.num_array else "]"
510510

511511
out += super()._dt_repr(separator=",\n", space="")
512-
if len(labels := self._label_repr(show_count=False)) > 0:
512+
if len(labels := self._label_repr()) > 0:
513513
out += ",\n" + labels
514514

515515
out += ")"

0 commit comments

Comments
 (0)