Skip to content

Commit cdba09a

Browse files
committed
test ndarray and python native omegas for test_squeeze
1 parent efb79a7 commit cdba09a

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

control/tests/lti_test.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,20 @@ def test_isdtime(self, objfun, arg, dt, ref, strictref):
179179
[1, 1, 2, [0.1, 1, 10], None, (1, 2, 3)], # MISO
180180
[2, 1, 2, [0.1, 1, 10], True, (2, 3)],
181181
[3, 1, 2, [0.1, 1, 10], False, (1, 2, 3)],
182+
[1, 1, 2, 0.1, None, (1, 2)],
183+
[1, 1, 2, 0.1, True, (2,)],
184+
[1, 1, 2, 0.1, False, (1, 2)],
182185
[1, 2, 2, [0.1, 1, 10], None, (2, 2, 3)], # MIMO
183186
[2, 2, 2, [0.1, 1, 10], True, (2, 2, 3)],
184-
[3, 2, 2, [0.1, 1, 10], False, (2, 2, 3)]
187+
[3, 2, 2, [0.1, 1, 10], False, (2, 2, 3)],
188+
[1, 2, 2, 0.1, None, (2, 2)],
189+
[2, 2, 2, 0.1, True, (2, 2)],
190+
[3, 2, 2, 0.1, False, (2, 2)],
185191
])
186-
def test_squeeze(self, fcn, nstate, nout, ninp, omega, squeeze, shape):
192+
@pytest.mark.parametrize("omega_type", ["numpy", "native"])
193+
def test_squeeze(self, fcn, nstate, nout, ninp, omega, squeeze, shape,
194+
omega_type):
195+
"""Test correct behavior of frequencey response squeeze parameter."""
187196
# Create the system to be tested
188197
if fcn == ct.frd:
189198
sys = fcn(ct.rss(nstate, nout, ninp), [1e-2, 1e-1, 1, 1e1, 1e2])
@@ -193,15 +202,23 @@ def test_squeeze(self, fcn, nstate, nout, ninp, omega, squeeze, shape):
193202
else:
194203
sys = fcn(ct.rss(nstate, nout, ninp))
195204

196-
# Convert the frequency list to an array for easy of use
197-
isscalar = not hasattr(omega, '__len__')
198-
omega = np.array(omega)
205+
if omega_type == "numpy":
206+
omega = np.asarray(omega)
207+
isscalar = omega.ndim == 0
208+
# keep the ndarray type even for scalars
209+
s = np.asarray(omega * 1j)
210+
else:
211+
isscalar = not hasattr(omega, '__len__')
212+
if isscalar:
213+
s = omega*1J
214+
else:
215+
s = [w*1J for w in omega]
199216

200217
# Call the transfer function directly and make sure shape is correct
201-
assert sys(omega * 1j, squeeze=squeeze).shape == shape
218+
assert sys(s, squeeze=squeeze).shape == shape
202219

203220
# Make sure that evalfr also works as expected
204-
assert ct.evalfr(sys, omega * 1j, squeeze=squeeze).shape == shape
221+
assert ct.evalfr(sys, s, squeeze=squeeze).shape == shape
205222

206223
# Check frequency response
207224
mag, phase, _ = sys.frequency_response(omega, squeeze=squeeze)
@@ -216,22 +233,22 @@ def test_squeeze(self, fcn, nstate, nout, ninp, omega, squeeze, shape):
216233

217234
# Make sure the default shape lines up with squeeze=None case
218235
if squeeze is None:
219-
assert sys(omega * 1j).shape == shape
236+
assert sys(s).shape == shape
220237

221238
# Changing config.default to False should return 3D frequency response
222239
ct.config.set_defaults('control', squeeze_frequency_response=False)
223240
mag, phase, _ = sys.frequency_response(omega)
224241
if isscalar:
225242
assert mag.shape == (sys.noutputs, sys.ninputs, 1)
226243
assert phase.shape == (sys.noutputs, sys.ninputs, 1)
227-
assert sys(omega * 1j).shape == (sys.noutputs, sys.ninputs)
228-
assert ct.evalfr(sys, omega * 1j).shape == (sys.noutputs, sys.ninputs)
244+
assert sys(s).shape == (sys.noutputs, sys.ninputs)
245+
assert ct.evalfr(sys, s).shape == (sys.noutputs, sys.ninputs)
229246
else:
230247
assert mag.shape == (sys.noutputs, sys.ninputs, len(omega))
231248
assert phase.shape == (sys.noutputs, sys.ninputs, len(omega))
232-
assert sys(omega * 1j).shape == \
249+
assert sys(s).shape == \
233250
(sys.noutputs, sys.ninputs, len(omega))
234-
assert ct.evalfr(sys, omega * 1j).shape == \
251+
assert ct.evalfr(sys, s).shape == \
235252
(sys.noutputs, sys.ninputs, len(omega))
236253

237254
@pytest.mark.parametrize("fcn", [ct.ss, ct.tf, ct.frd, ct.ss2io])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy