29
29
import numpy as np
30
30
import scipy as sp
31
31
import copy
32
- import itertools
33
32
from warnings import warn
34
33
35
34
from .lti import LTI
@@ -1011,7 +1010,7 @@ def __init__(self, syslist, connections=None, inplist=None, outlist=None,
1011
1010
output_indices , gain = self ._parse_output_spec (output_spec )
1012
1011
if len (output_indices ) != len (input_indices ):
1013
1012
raise ValueError (
1014
- f"inconsistent number signals in connecting"
1013
+ f"inconsistent number of signals in connecting"
1015
1014
f" '{ output_spec } ' to '{ connection [0 ]} '" )
1016
1015
1017
1016
for input_index , output_index in zip (
@@ -2541,7 +2540,8 @@ def interconnect(
2541
2540
signals are given names, then the forms 'sys.sig' or ('sys', 'sig')
2542
2541
are also recognized. Finally, for multivariable systems the signal
2543
2542
index can be given as a list, for example '(subsys_i, [inp_j1, ...,
2544
- inp_jn])' or as as a slice, for example, 'sys.sig[i:j]'.
2543
+ inp_jn])', as as a slice, for example, 'sys.sig[i:j]', or as a base
2544
+ name `sys.sig` (which matches `sys.sig[i]`).
2545
2545
2546
2546
Similarly, each output-spec should describe an output signal from
2547
2547
one of the subsystems. The lowest level representation is a tuple
@@ -2552,9 +2552,9 @@ def interconnect(
2552
2552
subsystem are used. If systems and signals are given names, then
2553
2553
the form 'sys.sig', ('sys', 'sig') or ('sys', 'sig', gain) are also
2554
2554
recognized, and the special form '-sys.sig' can be used to specify
2555
- a signal with gain -1. Lists and slices can also be used, as long
2556
- as the number of elements for each output spec mataches the input
2557
- spec.
2555
+ a signal with gain -1. Lists, slices, and base names can also be
2556
+ used, as long as the number of elements for each output spec
2557
+ mataches the input spec.
2558
2558
2559
2559
If omitted, the `interconnect` function will attempt to create the
2560
2560
interconnection map by connecting all signals with the same base names
@@ -2685,11 +2685,12 @@ def interconnect(
2685
2685
... outlist=['P.y[0]', 'P.y[1]'],
2686
2686
... )
2687
2687
2688
- This expression can be simplified using slice notation:
2688
+ This expression can be simplified using either slice notation or
2689
+ just signal basenames:
2689
2690
2690
2691
>>> T = ct.interconnect(
2691
- ... [P, C], connections=[['P.u[:]', 'C.y[:]'], ['C.u[:] ', '-P.y[:] ']],
2692
- ... inplist='C.u[:] ', outlist='P.y[:]')
2692
+ ... [P, C], connections=[['P.u[:]', 'C.y[:]'], ['C.u', '-P.y']],
2693
+ ... inplist='C.u', outlist='P.y[:]')
2693
2694
2694
2695
or further simplified by omitting the input and output signal
2695
2696
specifications (since all inputs and outputs are used):
@@ -2775,6 +2776,11 @@ def interconnect(
2775
2776
# Use an empty connections list
2776
2777
connections = []
2777
2778
2779
+ elif isinstance (connections , list ) and \
2780
+ all ([isinstance (cnxn , (str , tuple )) for cnxn in connections ]):
2781
+ # Special case where there is a single connection
2782
+ connections = [connections ]
2783
+
2778
2784
# If inplist/outlist is not present, try using inputs/outputs instead
2779
2785
if inplist is None :
2780
2786
inplist = list (inputs or [])
0 commit comments