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

Commit9c5b5e4

Browse files
committed
bdalg.connect: new tests that should pass, stylistic changes
1 parent85cc6ca commit9c5b5e4

File tree

2 files changed

+58
-48
lines changed

2 files changed

+58
-48
lines changed

‎control/bdalg.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ def connect(sys, Q, inputv, outputv):
303303
System to be connected
304304
Q : 2D array
305305
Interconnection matrix. First column gives the input to be connected.
306-
The second column gives the index of an output that is to be fed into
307-
that input. Each additional column gives the index of an additional
306+
The second column gives the index of an output that is to be fed into
307+
that input. Each additional column gives the index of an additional
308308
input that may be optionally added to that input. Negative
309-
values mean the feedback is negative. A zero value is ignored. Inputs
309+
values mean the feedback is negative. A zero value is ignored. Inputs
310310
and outputs are indexed starting at 1 to communicate sign information.
311311
inputv : 1D array
312312
list of final external inputs, indexed starting at 1
@@ -330,22 +330,22 @@ def connect(sys, Q, inputv, outputv):
330330
inputv,outputv,Q=np.asarray(inputv),np.asarray(outputv),np.asarray(Q)
331331
# check indices
332332
index_errors= (inputv-1>sys.inputs)| (inputv<1)
333-
ifnp.any(index_errors):
334-
raiseIndexError(
335-
"inputv index %s out of bounds"%inputv[np.where(index_errors)])
333+
ifnp.any(index_errors):
334+
raiseIndexError(
335+
"inputv index %s out of bounds"%inputv[np.where(index_errors)])
336336
index_errors= (outputv-1>sys.outputs)| (outputv<1)
337-
ifnp.any(index_errors):
338-
raiseIndexError(
339-
"outputv index %s out of bounds"%outputv[np.where(index_errors)])
337+
ifnp.any(index_errors):
338+
raiseIndexError(
339+
"outputv index %s out of bounds"%outputv[np.where(index_errors)])
340340
index_errors= (Q[:,0:1]-1>sys.inputs)| (Q[:,0:1]<1)
341-
ifnp.any(index_errors):
342-
raiseIndexError(
343-
"Q input index %s out of bounds"%Q[np.where(index_errors)])
341+
ifnp.any(index_errors):
342+
raiseIndexError(
343+
"Q input index %s out of bounds"%Q[np.where(index_errors)])
344344
index_errors= (np.abs(Q[:,1:])-1>sys.outputs)
345-
ifnp.any(index_errors):
346-
raiseIndexError(
347-
"Q output index %s out of bounds"%Q[np.where(index_errors)])
348-
345+
ifnp.any(index_errors):
346+
raiseIndexError(
347+
"Q output index %s out of bounds"%Q[np.where(index_errors)])
348+
349349
# first connect
350350
K=np.zeros((sys.inputs,sys.outputs))
351351
forrinnp.array(Q).astype(int):

‎control/tests/bdalg_test.py

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -194,50 +194,50 @@ def testLists(self):
194194
sys1_2=ctrl.series(sys1,sys2)
195195
np.testing.assert_array_almost_equal(sort(pole(sys1_2)), [-4.,-2.])
196196
np.testing.assert_array_almost_equal(sort(zero(sys1_2)), [-3.,-1.])
197-
197+
198198
sys1_3=ctrl.series(sys1,sys2,sys3);
199199
np.testing.assert_array_almost_equal(sort(pole(sys1_3)),
200200
[-6.,-4.,-2.])
201-
np.testing.assert_array_almost_equal(sort(zero(sys1_3)),
201+
np.testing.assert_array_almost_equal(sort(zero(sys1_3)),
202202
[-5.,-3.,-1.])
203-
203+
204204
sys1_4=ctrl.series(sys1,sys2,sys3,sys4);
205205
np.testing.assert_array_almost_equal(sort(pole(sys1_4)),
206206
[-8.,-6.,-4.,-2.])
207207
np.testing.assert_array_almost_equal(sort(zero(sys1_4)),
208208
[-7.,-5.,-3.,-1.])
209-
209+
210210
sys1_5=ctrl.series(sys1,sys2,sys3,sys4,sys5);
211211
np.testing.assert_array_almost_equal(sort(pole(sys1_5)),
212212
[-8.,-6.,-4.,-2.,-0.])
213-
np.testing.assert_array_almost_equal(sort(zero(sys1_5)),
213+
np.testing.assert_array_almost_equal(sort(zero(sys1_5)),
214214
[-9.,-7.,-5.,-3.,-1.])
215215

216-
# Parallel
216+
# Parallel
217217
sys1_2=ctrl.parallel(sys1,sys2)
218218
np.testing.assert_array_almost_equal(sort(pole(sys1_2)), [-4.,-2.])
219219
np.testing.assert_array_almost_equal(sort(zero(sys1_2)),
220220
sort(zero(sys1+sys2)))
221-
221+
222222
sys1_3=ctrl.parallel(sys1,sys2,sys3);
223223
np.testing.assert_array_almost_equal(sort(pole(sys1_3)),
224224
[-6.,-4.,-2.])
225-
np.testing.assert_array_almost_equal(sort(zero(sys1_3)),
225+
np.testing.assert_array_almost_equal(sort(zero(sys1_3)),
226226
sort(zero(sys1+sys2+sys3)))
227-
227+
228228
sys1_4=ctrl.parallel(sys1,sys2,sys3,sys4);
229229
np.testing.assert_array_almost_equal(sort(pole(sys1_4)),
230230
[-8.,-6.,-4.,-2.])
231-
np.testing.assert_array_almost_equal(sort(zero(sys1_4)),
232-
sort(zero(sys1+sys2+
231+
np.testing.assert_array_almost_equal(sort(zero(sys1_4)),
232+
sort(zero(sys1+sys2+
233233
sys3+sys4)))
234234

235-
235+
236236
sys1_5=ctrl.parallel(sys1,sys2,sys3,sys4,sys5);
237237
np.testing.assert_array_almost_equal(sort(pole(sys1_5)),
238238
[-8.,-6.,-4.,-2.,-0.])
239-
np.testing.assert_array_almost_equal(sort(zero(sys1_5)),
240-
sort(zero(sys1+sys2+
239+
np.testing.assert_array_almost_equal(sort(zero(sys1_5)),
240+
sort(zero(sys1+sys2+
241241
sys3+sys4+sys5)))
242242
deftestMimoSeries(self):
243243
"""regression: bdalg.series reverses order of arguments"""
@@ -274,44 +274,54 @@ def test_feedback_args(self):
274274

275275
deftestConnect(self):
276276
sys=append(self.sys2,self.sys3)# two siso systems
277-
277+
278+
# should not raise error
279+
connect(sys, [[1,2], [2,-2]], [2], [1,2])
280+
connect(sys, [[1,2], [2,0]], [2], [1,2])
281+
connect(sys, [[1,2,0], [2,-2,1]], [2], [1,2])
282+
connect(sys, [[1,2], [2,-2]], [2,1], [1])
283+
sys3x3=append(sys,self.sys3)# 3x3 mimo
284+
connect(sys3x3, [[1,2,0], [2,-2,1], [3,-3,0]], [2], [1,2])
285+
connect(sys3x3, [[1,2,0], [2,-2,1], [3,-3,0]], [1,2,3], [3])
286+
connect(sys3x3, [[1,2,0], [2,-2,1], [3,-3,0]], [2,3], [2,1])
287+
278288
# feedback interconnection out of bounds: input too high
279-
Q= [[1,3], [2,-2]]
280-
withself.assertRaises(IndexError)ascontext:
289+
Q= [[1,3], [2,-2]]
290+
withself.assertRaises(IndexError):
281291
connect(sys,Q, [2], [1,2])
282292
# feedback interconnection out of bounds: input too low
283-
Q= [[0,2], [2,-2]]
284-
withself.assertRaises(IndexError)ascontext:
293+
Q= [[0,2], [2,-2]]
294+
withself.assertRaises(IndexError):
285295
connect(sys,Q, [2], [1,2])
286296

287297
# feedback interconnection out of bounds: output too high
288-
Q= [[1,2], [2,-3]]
289-
withself.assertRaises(IndexError)ascontext:
298+
Q= [[1,2], [2,-3]]
299+
withself.assertRaises(IndexError):
290300
connect(sys,Q, [2], [1,2])
291-
Q= [[1,2], [2,4]]
292-
withself.assertRaises(IndexError)ascontext:
301+
Q= [[1,2], [2,4]]
302+
withself.assertRaises(IndexError):
293303
connect(sys,Q, [2], [1,2])
294-
304+
295305
# input/output index testing
296306
Q= [[1,2], [2,-2]]# OK interconnection
297-
307+
298308
# input index is out of bounds: too high
299-
withself.assertRaises(IndexError)ascontext:
309+
withself.assertRaises(IndexError):
300310
connect(sys,Q, [3], [1,2])
301311
# input index is out of bounds: too low
302-
withself.assertRaises(IndexError)ascontext:
312+
withself.assertRaises(IndexError):
303313
connect(sys,Q, [0], [1,2])
304-
withself.assertRaises(IndexError)ascontext:
314+
withself.assertRaises(IndexError):
305315
connect(sys,Q, [-2], [1,2])
306316
# output index is out of bounds: too high
307-
withself.assertRaises(IndexError)ascontext:
317+
withself.assertRaises(IndexError):
308318
connect(sys,Q, [2], [1,3])
309319
# output index is out of bounds: too low
310-
withself.assertRaises(IndexError)ascontext:
320+
withself.assertRaises(IndexError):
311321
connect(sys,Q, [2], [1,0])
312-
withself.assertRaises(IndexError)ascontext:
322+
withself.assertRaises(IndexError):
313323
connect(sys,Q, [2], [1,-1])
314-
324+
315325

316326
if__name__=="__main__":
317327
unittest.main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp