Skip to content

Commit 66bee9d

Browse files
bnavigatormurrayrm
authored andcommitted
ease precision tolerenace for iosys tests (#366)
1 parent a7f5f1c commit 66bee9d

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

control/tests/iosys_test.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_linear_iosys(self):
6060
lti_t, lti_y, lti_x = ct.forced_response(linsys, T, U, X0)
6161
ios_t, ios_y = ios.input_output_response(iosys, T, U, X0)
6262
np.testing.assert_array_almost_equal(lti_t, ios_t)
63-
np.testing.assert_array_almost_equal(lti_y, ios_y, decimal=3)
63+
np.testing.assert_allclose(lti_y, ios_y,atol=0.002,rtol=0.)
6464

6565
@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
6666
"requires SciPy 1.0 or greater")
@@ -75,7 +75,7 @@ def test_tf2io(self):
7575
lti_t, lti_y, lti_x = ct.forced_response(linsys, T, U, X0)
7676
ios_t, ios_y = ios.input_output_response(iosys, T, U, X0)
7777
np.testing.assert_array_almost_equal(lti_t, ios_t)
78-
np.testing.assert_array_almost_equal(lti_y, ios_y, decimal=3)
78+
np.testing.assert_allclose(lti_y, ios_y,atol=0.002,rtol=0.)
7979

8080
def test_ss2io(self):
8181
# Create an input/output system from the linear system
@@ -161,7 +161,7 @@ def test_nonlinear_iosys(self):
161161
lti_t, lti_y, lti_x = ct.forced_response(linsys, T, U, X0)
162162
ios_t, ios_y = ios.input_output_response(nlsys, T, U, X0)
163163
np.testing.assert_array_almost_equal(lti_t, ios_t)
164-
np.testing.assert_array_almost_equal(lti_y, ios_y, decimal=3)
164+
np.testing.assert_allclose(lti_y, ios_y,atol=0.002,rtol=0.)
165165

166166
def test_linearize(self):
167167
# Create a single input/single output linear system
@@ -214,7 +214,7 @@ def test_connect(self):
214214
iosys_series, T, U, X0, return_x=True)
215215
lti_t, lti_y, lti_x = ct.forced_response(linsys_series, T, U, X0)
216216
np.testing.assert_array_almost_equal(lti_t, ios_t)
217-
np.testing.assert_array_almost_equal(lti_y, ios_y, decimal=3)
217+
np.testing.assert_allclose(lti_y, ios_y,atol=0.002,rtol=0.)
218218

219219
# Connect systems with different timebases
220220
linsys2c = self.siso_linsys
@@ -231,7 +231,7 @@ def test_connect(self):
231231
iosys_series, T, U, X0, return_x=True)
232232
lti_t, lti_y, lti_x = ct.forced_response(linsys_series, T, U, X0)
233233
np.testing.assert_array_almost_equal(lti_t, ios_t)
234-
np.testing.assert_array_almost_equal(lti_y, ios_y, decimal=3)
234+
np.testing.assert_allclose(lti_y, ios_y,atol=0.002,rtol=0.)
235235

236236
# Feedback interconnection
237237
linsys_feedback = ct.feedback(linsys1, linsys2)
@@ -246,7 +246,7 @@ def test_connect(self):
246246
iosys_feedback, T, U, X0, return_x=True)
247247
lti_t, lti_y, lti_x = ct.forced_response(linsys_feedback, T, U, X0)
248248
np.testing.assert_array_almost_equal(lti_t, ios_t)
249-
np.testing.assert_array_almost_equal(lti_y, ios_y, decimal=3)
249+
np.testing.assert_allclose(lti_y, ios_y,atol=0.002,rtol=0.)
250250

251251
@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
252252
"requires SciPy 1.0 or greater")
@@ -357,7 +357,7 @@ def test_summer(self):
357357

358358
lin_t, lin_y, lin_x = ct.forced_response(linsys_parallel, T, U, X0)
359359
ios_t, ios_y = ios.input_output_response(iosys_parallel, T, U, X0)
360-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
360+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
361361

362362
@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
363363
"requires SciPy 1.0 or greater")
@@ -420,7 +420,7 @@ def test_feedback(self):
420420

421421
ios_t, ios_y = ios.input_output_response(iosys, T, U, X0)
422422
lti_t, lti_y, lti_x = ct.forced_response(linsys, T, U, X0)
423-
np.testing.assert_array_almost_equal(ios_y, lti_y, decimal=3)
423+
np.testing.assert_allclose(ios_y, lti_y,atol=0.002,rtol=0.)
424424

425425
@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
426426
"requires SciPy 1.0 or greater")
@@ -442,7 +442,7 @@ def test_bdalg_functions(self):
442442
iosys_series = ct.series(linio1, linio2)
443443
lin_t, lin_y, lin_x = ct.forced_response(linsys_series, T, U, X0)
444444
ios_t, ios_y = ios.input_output_response(iosys_series, T, U, X0)
445-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
445+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
446446

447447
# Make sure that systems don't commute
448448
linsys_series = ct.series(linsys2, linsys1)
@@ -454,21 +454,21 @@ def test_bdalg_functions(self):
454454
iosys_parallel = ct.parallel(linio1, linio2)
455455
lin_t, lin_y, lin_x = ct.forced_response(linsys_parallel, T, U, X0)
456456
ios_t, ios_y = ios.input_output_response(iosys_parallel, T, U, X0)
457-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
457+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
458458

459459
# Negation
460460
linsys_negate = ct.negate(linsys1)
461461
iosys_negate = ct.negate(linio1)
462462
lin_t, lin_y, lin_x = ct.forced_response(linsys_negate, T, U, X0)
463463
ios_t, ios_y = ios.input_output_response(iosys_negate, T, U, X0)
464-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
464+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
465465

466466
# Feedback interconnection
467467
linsys_feedback = ct.feedback(linsys1, linsys2)
468468
iosys_feedback = ct.feedback(linio1, linio2)
469469
lin_t, lin_y, lin_x = ct.forced_response(linsys_feedback, T, U, X0)
470470
ios_t, ios_y = ios.input_output_response(iosys_feedback, T, U, X0)
471-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
471+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
472472

473473
@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
474474
"requires SciPy 1.0 or greater")
@@ -496,26 +496,26 @@ def test_nonsquare_bdalg(self):
496496
iosys_multiply = iosys_3i2o * iosys_2i3o
497497
lin_t, lin_y, lin_x = ct.forced_response(linsys_multiply, T, U2, X0)
498498
ios_t, ios_y = ios.input_output_response(iosys_multiply, T, U2, X0)
499-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
499+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
500500

501501
linsys_multiply = linsys_2i3o * linsys_3i2o
502502
iosys_multiply = iosys_2i3o * iosys_3i2o
503503
lin_t, lin_y, lin_x = ct.forced_response(linsys_multiply, T, U3, X0)
504504
ios_t, ios_y = ios.input_output_response(iosys_multiply, T, U3, X0)
505-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
505+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
506506

507507
# Right multiplication
508508
# TODO: add real tests once conversion from other types is supported
509509
iosys_multiply = ios.InputOutputSystem.__rmul__(iosys_3i2o, iosys_2i3o)
510510
ios_t, ios_y = ios.input_output_response(iosys_multiply, T, U3, X0)
511-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
511+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
512512

513513
# Feedback
514514
linsys_multiply = ct.feedback(linsys_3i2o, linsys_2i3o)
515515
iosys_multiply = iosys_3i2o.feedback(iosys_2i3o)
516516
lin_t, lin_y, lin_x = ct.forced_response(linsys_multiply, T, U3, X0)
517517
ios_t, ios_y = ios.input_output_response(iosys_multiply, T, U3, X0)
518-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
518+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
519519

520520
# Mismatch should generate exception
521521
args = (iosys_3i2o, iosys_3i2o)
@@ -536,8 +536,8 @@ def test_discrete(self):
536536
# Simulate and compare to LTI output
537537
ios_t, ios_y = ios.input_output_response(lnios, T, U, X0)
538538
lin_t, lin_y, lin_x = ct.forced_response(linsys, T, U, X0)
539-
np.testing.assert_array_almost_equal(ios_t, lin_t, decimal=3)
540-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
539+
np.testing.assert_allclose(ios_t, lin_t,atol=0.002,rtol=0.)
540+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
541541

542542
# Test MIMO system, converted to discrete time
543543
linsys = ct.StateSpace(self.mimo_linsys1)
@@ -552,8 +552,8 @@ def test_discrete(self):
552552
# Simulate and compare to LTI output
553553
ios_t, ios_y = ios.input_output_response(lnios, T, U, X0)
554554
lin_t, lin_y, lin_x = ct.forced_response(linsys, T, U, X0)
555-
np.testing.assert_array_almost_equal(ios_t, lin_t, decimal=3)
556-
np.testing.assert_array_almost_equal(ios_y, lin_y, decimal=3)
555+
np.testing.assert_allclose(ios_t, lin_t,atol=0.002,rtol=0.)
556+
np.testing.assert_allclose(ios_y, lin_y,atol=0.002,rtol=0.)
557557

558558
def test_find_eqpts(self):
559559
"""Test find_eqpt function"""
@@ -738,7 +738,7 @@ def test_params(self):
738738

739739
# Check to make sure results are OK
740740
np.testing.assert_array_almost_equal(lti_t, ios_t)
741-
np.testing.assert_array_almost_equal(lti_y, ios_y, decimal=3)
741+
np.testing.assert_allclose(lti_y, ios_y,atol=0.002,rtol=0.)
742742

743743
def test_named_signals(self):
744744
sys1 = ios.NonlinearIOSystem(

0 commit comments

Comments
 (0)