Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions control/tests/xferfcn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ class TestXferFcn:

# Tests for raising exceptions.

def test_zpk_complex_dtypes(self):
"""Test zpk with complex64 and complex128 zeros/poles (Issue #1188)."""
P = ct.rss(5)
q1 = ct.zpk(zeros=P.zeros().astype(np.complex64),
poles=P.poles().astype(np.complex64),
gain=1, dt=0)
assert isinstance(q1, ct.TransferFunction)
assert "s^5" in str(q1)

q2 = ct.zpk(zeros=P.zeros().astype(np.complex128),
poles=P.poles().astype(np.complex128),
gain=1, dt=0)
assert isinstance(q2, ct.TransferFunction)
assert "s^5" in str(q2)

def test_constructor_bad_input_type(self):
"""Give the constructor invalid input types."""
# Single argument of the wrong type
Expand Down
7 changes: 7 additions & 0 deletions control/xferfcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,7 @@ def _tf_polynomial_to_string(coeffs, var='s'):
thestr = "0"

# Apply NumPy formatting
coeffs = np.asarray(coeffs, dtype=float)
with np.printoptions(threshold=sys.maxsize):
coeffs = eval(repr(coeffs))

Expand Down Expand Up @@ -2015,6 +2016,12 @@ def _clean_part(data, name="<unknown>"):
# Check for coefficients that are ints and convert to floats
for i in range(out.shape[0]):
for j in range(out.shape[1]):
if np.iscomplexobj(out[i, j]):
if np.allclose(np.imag(out[i, j]), 0.0, atol=1e-10):
out[i, j] = np.real(out[i, j]).astype(float)
else:
raise TypeError(
f"unsupported data type: {type(out[i, j][0])}")
for k in range(len(out[i, j])):
if isinstance(out[i, j][k], (int, np.integer)):
out[i, j][k] = float(out[i, j][k])
Expand Down
Loading