Skip to content

Commit 996211c

Browse files
committed
address @murrayrm and preliminary @slivingston review comments
1 parent c0f5b17 commit 996211c

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

control/config.py

-4
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,6 @@ def use_legacy_defaults(version):
333333
#
334334
reset_defaults() # start from a clean slate
335335

336-
# Verions 0.10.2
337-
if major == 0 and minor <= 10 and patch < 2:
338-
set_defaults('iosys', repr_format='eval')
339-
340336
# Version 0.9.2:
341337
if major == 0 and minor < 9 or (minor == 9 and patch < 2):
342338
from math import inf

control/iosys.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ def _repr_info_(self, html=False):
267267

268268
if html:
269269
# Replace symbols that might be interpreted by HTML processing
270+
# TODO: replace -> with right arrow (later)
270271
escape_chars = {
271272
'$': r'\$',
272273
'<': '&lt;',
@@ -820,7 +821,7 @@ def iosys_repr(sys, format=None):
820821
821822
Notes
822823
-----
823-
By default, the representation for an input/output is set to 'info'.
824+
By default, the representation for an input/output is set to 'eval'.
824825
Set config.defaults['iosys.repr_format'] to change for all I/O systems
825826
or use the `repr_format` parameter for a single system.
826827

control/nlsys.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __init__(self, updfcn, outfcn=None, params=None, **kwargs):
155155

156156
def __str__(self):
157157
out = f"{InputOutputSystem.__str__(self)}"
158-
if len(self.params) > 1:
158+
if len(self.params) > 0:
159159
out += f"\nParameters: {[p for p in self.params.keys()]}"
160160
out += "\n\n" + \
161161
f"Update: {self.updfcn}\n" + \

control/tests/nlsys_test.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Basic test of nlsys()
2020
def test_nlsys_basic():
2121
def kincar_update(t, x, u, params):
22-
l = params['l'] # wheelbase
22+
l = params['l'] # wheelbase
2323
return np.array([
2424
np.cos(x[2]) * u[0], # x velocity
2525
np.sin(x[2]) * u[0], # y velocity
@@ -248,3 +248,20 @@ def test_ICsystem_str():
248248
r"D = \[\[.*\]\]"
249249

250250
assert re.match(ref, str(sys), re.DOTALL)
251+
252+
253+
# Make sure nlsys str() works as expected
254+
@pytest.mark.parametrize("params, expected", [
255+
({}, r"States \(1\): \['x\[0\]'\]" + "\n\n"),
256+
({'a': 1}, r"States \(1\): \['x\[0\]'\]" + "\n" +
257+
r"Parameters: \['a'\]" + "\n\n"),
258+
({'a': 1, 'b': 1}, r"States \(1\): \['x\[0\]'\]" + "\n" +
259+
r"Parameters: \['a', 'b'\]" + "\n\n"),
260+
])
261+
def test_nlsys_params_str(params, expected):
262+
sys = ct.nlsys(
263+
lambda t, x, u, params: -x, inputs=1, outputs=1, states=1,
264+
params=params)
265+
out = str(sys)
266+
267+
assert re.search(expected, out) is not None

control/tests/statesp_test.py

+15
Original file line numberDiff line numberDiff line change
@@ -1286,3 +1286,18 @@ def test_tf2ss_mimo():
12861286
else:
12871287
with pytest.raises(ct.ControlMIMONotImplemented):
12881288
sys_ss = ct.ss(sys_tf)
1289+
1290+
1291+
# Test LinearICSystem __call__
1292+
def test_linearic_call():
1293+
import cmath
1294+
1295+
sys1 = ct.rss(2, 1, 1, strictly_proper=True, name='sys1')
1296+
sys2 = ct.rss(2, 1, 1, strictly_proper=True, name='sys2')
1297+
1298+
sys_ic = ct.interconnect(
1299+
[sys1, sys2], connections=['sys1.u', 'sys2.y'],
1300+
inplist='sys2.u', outlist='sys1.y')
1301+
1302+
for s in [0, 1, 1j]:
1303+
assert cmath.isclose(sys_ic(s), (sys1 * sys2)(s))

examples/repr_gallery.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# of representations (__repr__, __str__) for those systems that can be
66
# used to compare different versions of python-control. It is mainly
77
# intended for uses by developers to make sure there are no unexpected
8-
# changes in representation formats, but also has some interest
8+
# changes in representation formats, but also has some interesting
99
# examples of different choices in system representation.
1010

1111
import numpy as np
@@ -30,14 +30,14 @@
3030
sys_gtf = ct.tf([1], [1, 0])
3131
syslist += [sys_tf, sys_dtf, sys_gtf]
3232

33-
# MIMO transfer function (continous time only)
33+
# MIMO transfer function (continuous time only)
3434
sys_mtf = ct.tf(
3535
[[sys_tf.num[0][0].tolist(), [0]], [[1, 0], [1, 0] ]],
3636
[[sys_tf.den[0][0].tolist(), [1]], [[1], [1, 2, 1]]],
3737
name='sys_mtf_zpk', display_format='zpk')
3838
syslist += [sys_mtf]
3939

40-
# Frequency response data (FRD) system (continous and discrete time)
40+
# Frequency response data (FRD) system (continuous and discrete time)
4141
sys_frd = ct.frd(sys_tf, np.logspace(-1, 1, 5))
4242
sys_dfrd = ct.frd(sys_dtf, np.logspace(-1, 1, 5))
4343
sys_mfrd = ct.frd(sys_mtf, np.logspace(-1, 1, 5))

0 commit comments

Comments
 (0)