Skip to content

Commit b7b7f7b

Browse files
committed
fixup int for precision of 0 and freqresp for python 2
1 parent b4ebfde commit b7b7f7b

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

control/tests/freqresp_test.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,21 @@ def discrete_data():
179179
return {'argvalues': systems.values(), 'ids': systems.keys()}
180180

181181

182+
rsys = rss(3, 1, 1)
183+
184+
185+
@pytest.mark.parametrize(
186+
"sys",
187+
[sys for dt in [0.1, True] for sys in
188+
[StateSpace(rsys.A, rsys.B, rsys.C, rsys.D, dt),
189+
StateSpace([[-3., 4., 2.], [-1., -3., 0.], [2., 5., 3.]],
190+
[[1., 4.], [-3., -3.], [-2., 1.]],
191+
[[4., 2., -3.], [1., 4., 3.]],
192+
[[-2., 4.], [0., 1.]], dt),
193+
TransferFunction([1, 1], [1, 2, 1], dt)]
194+
]
195+
)
182196
@mplcleanup
183-
@pytest.mark.parametrize("sys", **discrete_data())
184197
def test_discrete(sys):
185198
"""Test discrete time frequency response"""
186199
# Set frequency range to just below Nyquist freq (for Bode)
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,57 @@
1-
# input_element_int_test.py
2-
#
3-
# Author: Kangwon Lee (kangwonlee)
4-
# Date: 22 Oct 2017
5-
#
6-
# Unit tests contributed as part of PR #158, "SISO tf() may not work
7-
# with numpy arrays with numpy.int elements"
8-
#
9-
# Modified:
10-
# * 29 Dec 2017, RMM - updated file name and added header
11-
12-
import unittest
1+
"""input_element_int_test.py
2+
3+
Author: Kangwon Lee (kangwonlee)
4+
Date: 22 Oct 2017
5+
6+
Modified:
7+
* 29 Dec 2017, RMM - updated file name and added header
8+
"""
9+
1310
import numpy as np
1411
import control as ctl
1512

16-
class TestTfInputIntElement(unittest.TestCase):
17-
# currently these do not pass
13+
class TestTfInputIntElement:
14+
"""input_element_int_test
15+
16+
Unit tests contributed as part of PR gh-158, "SISO tf() may not work
17+
with numpy arrays with numpy.int elements
18+
"""
19+
1820
def test_tf_den_with_numpy_int_element(self):
1921
num = 1
2022
den = np.convolve([1, 2, 1], [1, 1, 1])
2123

2224
sys = ctl.tf(num, den)
2325

24-
self.assertAlmostEqual(1.0, ctl.dcgain(sys))
26+
np.testing.assert_array_max_ulp(1.0, ctl.dcgain(sys))
2527

2628
def test_tf_num_with_numpy_int_element(self):
2729
num = np.convolve([1], [1, 1])
2830
den = np.convolve([1, 2, 1], [1, 1, 1])
2931

3032
sys = ctl.tf(num, den)
3133

32-
self.assertAlmostEqual(1.0, ctl.dcgain(sys))
34+
np.testing.assert_array_max_ulp(1.0, ctl.dcgain(sys))
3335

3436
# currently these pass
35-
def test_tf_input_with_int_element_works(self):
37+
def test_tf_input_with_int_element(self):
3638
num = 1
3739
den = np.convolve([1.0, 2, 1], [1, 1, 1])
3840

3941
sys = ctl.tf(num, den)
4042

41-
self.assertAlmostEqual(1.0, ctl.dcgain(sys))
43+
np.testing.assert_array_max_ulp(1.0, ctl.dcgain(sys))
4244

4345
def test_ss_input_with_int_element(self):
44-
ident = np.matrix(np.identity(2), dtype=int)
45-
a = np.matrix([[0, 1],
46-
[-1, -2]], dtype=int) * ident
47-
b = np.matrix([[0],
46+
ident = np.eye(2, dtype=int)
47+
a = np.array([[0, 1],
48+
[-1, -2]], dtype=int).dot(ident)
49+
b = np.array([[0],
4850
[1]], dtype=int)
49-
c = np.matrix([[0, 1]], dtype=int)
51+
c = np.array([[0, 1]], dtype=int)
5052
d = 0
5153

5254
sys = ctl.ss(a, b, c, d)
5355
sys2 = ctl.ss2tf(sys)
54-
self.assertAlmostEqual(ctl.dcgain(sys), ctl.dcgain(sys2))
56+
np.testing.assert_array_max_ulp(ctl.dcgain(sys), ctl.dcgain(sys2),
57+
maxulp=2)

0 commit comments

Comments
 (0)