Skip to content

Commit df2436f

Browse files
committed
fix nlsys conversion of float, array to dt=None
1 parent ff2fe8d commit df2436f

2 files changed

Lines changed: 40 additions & 9 deletions

File tree

control/nlsys.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,13 +2574,14 @@ def _convert_static_iosystem(sys):
25742574
# Convert sys1 to an I/O system if needed
25752575
if isinstance(sys, (int, float, np.number)):
25762576
return NonlinearIOSystem(
2577-
None, lambda t, x, u, params: sys * u, inputs=1, outputs=1)
2577+
None, lambda t, x, u, params: sys * u,
2578+
outputs=1, inputs=1, dt=None)
25782579

25792580
elif isinstance(sys, np.ndarray):
25802581
sys = np.atleast_2d(sys)
25812582
return NonlinearIOSystem(
25822583
None, lambda t, x, u, params: sys @ u,
2583-
outputs=sys.shape[0], inputs=sys.shape[1])
2584+
outputs=sys.shape[0], inputs=sys.shape[1], dt=None)
25842585

25852586
def connection_table(sys, show_names=False, column_width=32):
25862587
"""Print table of connections inside an interconnected system model.

control/tests/timebase_test.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,36 @@
33
import numpy as np
44
import control as ct
55

6+
# Utility function to convert state space system to nlsys
7+
def ss2io(sys):
8+
return ct.nlsys(
9+
sys.updfcn, sys.outfcn, states=sys.nstates,
10+
inputs=sys.ninputs, outputs=sys.noutputs, dt=sys.dt)
11+
612
@pytest.mark.parametrize(
713
"dt1, dt2, dt3", [
814
(0, 0, 0),
915
(0, 0.1, ValueError),
1016
(0, None, 0),
17+
(0, 'float', 0),
18+
(0, 'array', 0),
19+
(None, 'array', None),
20+
(None, 'array', None),
1121
(0, True, ValueError),
1222
(0.1, 0, ValueError),
1323
(0.1, 0.1, 0.1),
1424
(0.1, None, 0.1),
1525
(0.1, True, 0.1),
26+
(0.1, 'array', 0.1),
27+
(0.1, 'float', 0.1),
1628
(None, 0, 0),
29+
('float', 0, 0),
30+
('array', 0, 0),
31+
('float', None, None),
32+
('array', None, None),
1733
(None, 0.1, 0.1),
34+
('array', 0.1, 0.1),
35+
('float', 0.1, 0.1),
1836
(None, None, None),
1937
(None, True, True),
2038
(True, 0, ValueError),
@@ -25,16 +43,28 @@
2543
(0.2, 0.1, ValueError),
2644
])
2745
@pytest.mark.parametrize("op", [ct.series, ct.parallel, ct.feedback])
28-
@pytest.mark.parametrize("type", [ct.StateSpace, ct.ss, ct.tf])
46+
@pytest.mark.parametrize("type", [ct.StateSpace, ct.ss, ct.tf, ss2io])
2947
def test_composition(dt1, dt2, dt3, op, type):
30-
# Define the system
3148
A, B, C, D = [[1, 1], [0, 1]], [[0], [1]], [[1, 0]], 0
32-
sys1 = ct.StateSpace(A, B, C, D, dt1)
33-
sys2 = ct.StateSpace(A, B, C, D, dt2)
49+
Karray = np.array([[1]])
50+
kfloat = 1
3451

35-
# Convert to the desired form
36-
sys1 = type(sys1)
37-
sys2 = type(sys2)
52+
# Define the system
53+
if isinstance(dt1, (int, float)) or dt1 is None:
54+
sys1 = ct.StateSpace(A, B, C, D, dt1)
55+
sys1 = type(sys1)
56+
elif dt1 == 'array':
57+
sys1 = Karray
58+
elif dt1 == 'float':
59+
sys1 = kfloat
60+
61+
if isinstance(dt2, (int, float)) or dt2 is None:
62+
sys2 = ct.StateSpace(A, B, C, D, dt2)
63+
sys2 = type(sys2)
64+
elif dt2 == 'array':
65+
sys2 = Karray
66+
elif dt2 == 'float':
67+
sys2 = kfloat
3868

3969
if inspect.isclass(dt3) and issubclass(dt3, Exception):
4070
with pytest.raises(dt3, match="incompatible timebases"):

0 commit comments

Comments
 (0)