ease precision tolerenace for iosys tests (#366) · python-control/python-control@66bee9d
@@ -60,7 +60,7 @@ def test_linear_iosys(self):
6060lti_t, lti_y, lti_x = ct.forced_response(linsys, T, U, X0)
6161ios_t, ios_y = ios.input_output_response(iosys, T, U, X0)
6262np.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.)
64646565@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
6666 "requires SciPy 1.0 or greater")
@@ -75,7 +75,7 @@ def test_tf2io(self):
7575lti_t, lti_y, lti_x = ct.forced_response(linsys, T, U, X0)
7676ios_t, ios_y = ios.input_output_response(iosys, T, U, X0)
7777np.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.)
79798080def test_ss2io(self):
8181# Create an input/output system from the linear system
@@ -161,7 +161,7 @@ def test_nonlinear_iosys(self):
161161lti_t, lti_y, lti_x = ct.forced_response(linsys, T, U, X0)
162162ios_t, ios_y = ios.input_output_response(nlsys, T, U, X0)
163163np.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.)
165165166166def test_linearize(self):
167167# Create a single input/single output linear system
@@ -214,7 +214,7 @@ def test_connect(self):
214214iosys_series, T, U, X0, return_x=True)
215215lti_t, lti_y, lti_x = ct.forced_response(linsys_series, T, U, X0)
216216np.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.)
218218219219# Connect systems with different timebases
220220linsys2c = self.siso_linsys
@@ -231,7 +231,7 @@ def test_connect(self):
231231iosys_series, T, U, X0, return_x=True)
232232lti_t, lti_y, lti_x = ct.forced_response(linsys_series, T, U, X0)
233233np.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.)
235235236236# Feedback interconnection
237237linsys_feedback = ct.feedback(linsys1, linsys2)
@@ -246,7 +246,7 @@ def test_connect(self):
246246iosys_feedback, T, U, X0, return_x=True)
247247lti_t, lti_y, lti_x = ct.forced_response(linsys_feedback, T, U, X0)
248248np.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.)
250250251251@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
252252 "requires SciPy 1.0 or greater")
@@ -357,7 +357,7 @@ def test_summer(self):
357357358358lin_t, lin_y, lin_x = ct.forced_response(linsys_parallel, T, U, X0)
359359ios_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.)
361361362362@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
363363 "requires SciPy 1.0 or greater")
@@ -420,7 +420,7 @@ def test_feedback(self):
420420421421ios_t, ios_y = ios.input_output_response(iosys, T, U, X0)
422422lti_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.)
424424425425@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
426426 "requires SciPy 1.0 or greater")
@@ -442,7 +442,7 @@ def test_bdalg_functions(self):
442442iosys_series = ct.series(linio1, linio2)
443443lin_t, lin_y, lin_x = ct.forced_response(linsys_series, T, U, X0)
444444ios_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.)
446446447447# Make sure that systems don't commute
448448linsys_series = ct.series(linsys2, linsys1)
@@ -454,21 +454,21 @@ def test_bdalg_functions(self):
454454iosys_parallel = ct.parallel(linio1, linio2)
455455lin_t, lin_y, lin_x = ct.forced_response(linsys_parallel, T, U, X0)
456456ios_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.)
458458459459# Negation
460460linsys_negate = ct.negate(linsys1)
461461iosys_negate = ct.negate(linio1)
462462lin_t, lin_y, lin_x = ct.forced_response(linsys_negate, T, U, X0)
463463ios_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.)
465465466466# Feedback interconnection
467467linsys_feedback = ct.feedback(linsys1, linsys2)
468468iosys_feedback = ct.feedback(linio1, linio2)
469469lin_t, lin_y, lin_x = ct.forced_response(linsys_feedback, T, U, X0)
470470ios_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.)
472472473473@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
474474 "requires SciPy 1.0 or greater")
@@ -496,26 +496,26 @@ def test_nonsquare_bdalg(self):
496496iosys_multiply = iosys_3i2o * iosys_2i3o
497497lin_t, lin_y, lin_x = ct.forced_response(linsys_multiply, T, U2, X0)
498498ios_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.)
500500501501linsys_multiply = linsys_2i3o * linsys_3i2o
502502iosys_multiply = iosys_2i3o * iosys_3i2o
503503lin_t, lin_y, lin_x = ct.forced_response(linsys_multiply, T, U3, X0)
504504ios_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.)
506506507507# Right multiplication
508508# TODO: add real tests once conversion from other types is supported
509509iosys_multiply = ios.InputOutputSystem.__rmul__(iosys_3i2o, iosys_2i3o)
510510ios_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.)
512512513513# Feedback
514514linsys_multiply = ct.feedback(linsys_3i2o, linsys_2i3o)
515515iosys_multiply = iosys_3i2o.feedback(iosys_2i3o)
516516lin_t, lin_y, lin_x = ct.forced_response(linsys_multiply, T, U3, X0)
517517ios_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.)
519519520520# Mismatch should generate exception
521521args = (iosys_3i2o, iosys_3i2o)
@@ -536,8 +536,8 @@ def test_discrete(self):
536536# Simulate and compare to LTI output
537537ios_t, ios_y = ios.input_output_response(lnios, T, U, X0)
538538lin_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.)
541541542542# Test MIMO system, converted to discrete time
543543linsys = ct.StateSpace(self.mimo_linsys1)
@@ -552,8 +552,8 @@ def test_discrete(self):
552552# Simulate and compare to LTI output
553553ios_t, ios_y = ios.input_output_response(lnios, T, U, X0)
554554lin_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.)
557557558558def test_find_eqpts(self):
559559"""Test find_eqpt function"""
@@ -738,7 +738,7 @@ def test_params(self):
738738739739# Check to make sure results are OK
740740np.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.)
742742743743def test_named_signals(self):
744744sys1 = ios.NonlinearIOSystem(