| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,21 @@ class TestXferFcn: | |||
| 28 | 28 | ||
| 29 | 29 | # Tests for raising exceptions. | |
| 30 | 30 | ||
| 31 | + def test_zpk_complex_dtypes(self): | ||
| 32 | + """Test zpk with complex64 and complex128 zeros/poles (Issue #1188).""" | ||
| 33 | + P = ct.rss(5) | ||
| 34 | + q1 = ct.zpk(zeros=P.zeros().astype(np.complex64), | ||
| 35 | + poles=P.poles().astype(np.complex64), | ||
| 36 | + gain=1, dt=0) | ||
| 37 | + assert isinstance(q1, ct.TransferFunction) | ||
| 38 | + assert "s^5" in str(q1) | ||
| 39 | + | ||
| 40 | + q2 = ct.zpk(zeros=P.zeros().astype(np.complex128), | ||
| 41 | + poles=P.poles().astype(np.complex128), | ||
| 42 | + gain=1, dt=0) | ||
| 43 | + assert isinstance(q2, ct.TransferFunction) | ||
| 44 | + assert "s^5" in str(q2) | ||
| 45 | + | ||
| 31 | 46 | def test_constructor_bad_input_type(self): | |
| 32 | 47 | """Give the constructor invalid input types.""" | |
| 33 | 48 | # Single argument of the wrong type | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1378,9 +1378,8 @@ def _tf_polynomial_to_string(coeffs, var='s'): | |||
| 1378 | 1378 | """Convert a transfer function polynomial to a string.""" | |
| 1379 | 1379 | thestr = "0" | |
| 1380 | 1380 | ||
| 1381 | - # Apply NumPy formatting | ||
| 1382 | - with np.printoptions(threshold=sys.maxsize): | ||
| 1383 | - coeffs = eval(repr(coeffs)) | ||
| 1381 | + # Convert coefficients to Python list of floats/numbers | ||
| 1382 | + coeffs = np.asarray(coeffs).tolist() | ||
| 1384 | 1383 | ||
| 1385 | 1384 | # Compute the number of coefficients | |
| 1386 | 1385 | N = len(coeffs) - 1 | |
@@ -2015,6 +2014,12 @@ def _clean_part(data, name="<unknown>"): | |||
| 2015 | 2014 | # Check for coefficients that are ints and convert to floats | |
| 2016 | 2015 | for i in range(out.shape[0]): | |
| 2017 | 2016 | for j in range(out.shape[1]): | |
| 2017 | + if np.iscomplexobj(out[i, j]): | ||
| 2018 | + if np.allclose(np.imag(out[i, j]), 0.0, atol=1e-10): | ||
| 2019 | + out[i, j] = np.real(out[i, j]).astype(float) | ||
| 2020 | + else: | ||
| 2021 | + raise TypeError( | ||
| 2022 | + f"unsupported data type: {type(out[i, j][0])}") | ||
| 2018 | 2023 | for k in range(len(out[i, j])): | |
| 2019 | 2024 | if isinstance(out[i, j][k], (int, np.integer)): | |
| 2020 | 2025 | out[i, j][k] = float(out[i, j][k]) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments