Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc36fcc0

Browse files
authored
Fix iosys errors for unspecified # of inputs/outputs (#355)
1 parent72262c6 commitc36fcc0

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

‎control/iosys.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ def __repr__(self):
212212

213213
def__str__(self):
214214
"""String representation of an input/output system"""
215-
str="System: "+ (self.nameifself.nameelse"(none)")+"\n"
216-
str+="Inputs (%d): "%self.ninputs
215+
str="System: "+ (self.nameifself.nameelse"(None)")+"\n"
216+
str+="Inputs (%s): "%self.ninputs
217217
forkeyinself.input_index:str+=key+", "
218-
str+="\nOutputs (%d): "%self.noutputs
218+
str+="\nOutputs (%s): "%self.noutputs
219219
forkeyinself.output_index:str+=key+", "
220-
str+="\nStates (%d): "%self.nstates
220+
str+="\nStates (%s): "%self.nstates
221221
forkeyinself.state_index:str+=key+", "
222222
returnstr
223223

@@ -317,13 +317,8 @@ def __add__(sys1, sys2):
317317
ninputs=sys1.ninputs
318318
noutputs=sys1.noutputs
319319

320-
# Make sure timebase are compatible
321-
dt=_find_timebase(sys1,sys2)
322-
ifdtisFalse:
323-
raiseValueError("System timebases are not compabile")
324-
325320
# Create a new system to handle the composition
326-
newsys=InterconnectedSystem((sys1,sys2),dt=dt)
321+
newsys=InterconnectedSystem((sys1,sys2))
327322

328323
# Set up the input map
329324
newsys.set_input_map(np.concatenate(
@@ -937,6 +932,7 @@ def __init__(self, syslist, connections=[], inplist=[], outlist=[],
937932
system_count=0
938933
forsysinsyslist:
939934
# Make sure time bases are consistent
935+
# TODO: Use lti._find_timebase() instead?
940936
ifdtisNoneandsys.dtisnotNone:
941937
# Timebase was not specified; set to match this system
942938
dt=sys.dt
@@ -948,7 +944,7 @@ def __init__(self, syslist, connections=[], inplist=[], outlist=[],
948944
sys.nstatesisNone:
949945
raiseTypeError("System '%s' must define number of inputs, "
950946
"outputs, states in order to be connected"%
951-
sys)
947+
sys.name)
952948

953949
# Keep track of the offsets into the states, inputs, outputs
954950
self.input_offset.append(ninputs)

‎control/tests/iosys_test.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# operations on input/output systems. Separate unit tests should be
99
# created for that purpose.
1010

11+
from __future__importprint_function
1112
importunittest
1213
importwarnings
1314
importnumpyasnp
@@ -100,6 +101,32 @@ def test_ss2io(self):
100101
np.testing.assert_array_equal(linsys.C,iosys_named.C)
101102
np.testing.assert_array_equal(linsys.D,iosys_named.D)
102103

104+
# Make sure unspecified inputs/outputs/states are handled properly
105+
deftest_iosys_unspecified(self):
106+
# System with unspecified inputs and outputs
107+
sys=ios.NonlinearIOSystem(secord_update,secord_output)
108+
np.testing.assert_raises(TypeError,sys.__mul__,sys)
109+
110+
# Make sure we can print various types of I/O systems
111+
deftest_iosys_print(self):
112+
# Send the output to /dev/null
113+
importos
114+
f=open(os.devnull,"w")
115+
116+
# Simple I/O system
117+
iosys=ct.ss2io(self.siso_linsys)
118+
print(iosys,file=f)
119+
120+
# I/O system without ninputs, noutputs
121+
ios_unspecified=ios.NonlinearIOSystem(secord_update,secord_output)
122+
print(ios_unspecified,file=f)
123+
124+
# I/O system with derived inputs and outputs
125+
ios_linearized=ios.linearize(ios_unspecified, [0,0], [0])
126+
print(ios_linearized,file=f)
127+
128+
f.close()
129+
103130
@unittest.skipIf(StrictVersion(sp.__version__)<"1.0",
104131
"requires SciPy 1.0 or greater")
105132
deftest_nonlinear_iosys(self):
@@ -832,7 +859,6 @@ def test_lineariosys_statespace(self):
832859
np.testing.assert_array_equal(io_feedback.C,ss_feedback.C)
833860
np.testing.assert_array_equal(io_feedback.D,ss_feedback.D)
834861

835-
836862
deftest_duplicates(self):
837863
nlios=ios.NonlinearIOSystem(None, \
838864
lambdat,x,u,params:u*u,inputs=1,outputs=1)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp