Skip to content

Commit d9affba

Browse files
committed
add error checks, unit tests, documentation for real-valued systems
1 parent 394e1c2 commit d9affba

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

control/tests/statesp_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def test_constructor(self, sys322ABCD, dt, argfun):
136136
((np.ones((3, 3)), np.ones((3, 2)),
137137
np.ones((2, 3)), np.ones((2, 3))), ValueError,
138138
r"Incompatible dimensions of D matrix; expected \(2, 2\)"),
139+
(([1j], 2, 3, 0), TypeError, "real number, not 'complex'"),
139140
])
140141
def test_constructor_invalid(self, args, exc, errmsg):
141142
"""Test invalid input to StateSpace() constructor"""

control/tests/xferfcn_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def test_constructor_bad_input_type(self):
4949
[[4, 5], [6, 7]]],
5050
[[[6, 7], [4, 5]],
5151
[[2, 3]]])
52+
53+
with pytest.raises(TypeError, match="unsupported data type"):
54+
ct.tf([1j], [1, 2, 3])
55+
5256
# good input
5357
TransferFunction([[[0, 1], [2, 3]],
5458
[[4, 5], [6, 7]]],

control/xferfcn.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,7 @@ def _clean_part(data, name="<unknown>"):
19541954
19551955
"""
19561956
valid_types = (int, float, complex, np.number)
1957+
unsupported_types = (complex, np.complexfloating)
19571958
valid_collection = (list, tuple, ndarray)
19581959

19591960
if isinstance(data, np.ndarray) and data.ndim == 2 and \
@@ -1998,8 +1999,11 @@ def _clean_part(data, name="<unknown>"):
19981999
for i in range(out.shape[0]):
19992000
for j in range(out.shape[1]):
20002001
for k in range(len(out[i, j])):
2001-
if isinstance(out[i, j][k], (int, np.int32, np.int64)):
2002+
if isinstance(out[i, j][k], (int, np.integer)):
20022003
out[i, j][k] = float(out[i, j][k])
2004+
elif isinstance(out[i, j][k], unsupported_types):
2005+
raise TypeError(
2006+
f"unsupported data type: {type(out[i, j][k])}")
20032007
return out
20042008

20052009

doc/linear.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ of linear time-invariant (LTI) systems:
3939
y &= C x + D u
4040
4141
where :math:`u` is the input, :math:`y` is the output, and :math:`x`
42-
is the state.
42+
is the state. All vectors and matrices must be real-valued.
4343

4444
To create a state space system, use the :func:`ss` function:
4545

@@ -94,7 +94,8 @@ transfer functions
9494
{b_0 s^n + b_1 s^{n-1} + \cdots + b_n},
9595
9696
where :math:`n` is greater than or equal to :math:`m` for a proper
97-
transfer function. Improper transfer functions are also allowed.
97+
transfer function. Improper transfer functions are also allowed. All
98+
coefficients must be real-valued.
9899

99100
To create a transfer function, use the :func:`tf` function::
100101

0 commit comments

Comments
 (0)