Skip to content
Open
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
3 changes: 2 additions & 1 deletion control/statesp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,8 @@ def _ssmatrix(data, axis=1, square=None, rows=None, cols=None, name=None):
name = "" if name is None else " " + name

# Convert the data into an array (always making a copy)
arr = np.array(data, dtype=float)
dtype = complex if np.iscomplexobj(data) else float
arr = np.array(data, dtype=dtype)
ndim = arr.ndim
shape = arr.shape

Expand Down
18 changes: 17 additions & 1 deletion control/tests/statesp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import operator
import warnings

import numpy as np
import pytest
Expand Down Expand Up @@ -136,7 +137,6 @@ def test_constructor(self, sys322ABCD, dt, argfun):
((np.ones((3, 3)), np.ones((3, 2)),
np.ones((2, 3)), np.ones((2, 3))), ValueError,
r"Incompatible dimensions of D matrix; expected \(2, 2\)"),
(([1j], 2, 3, 0), TypeError, "real number, not 'complex'"),
])
def test_constructor_invalid(self, args, exc, errmsg):
"""Test invalid input to StateSpace() constructor"""
Expand All @@ -146,6 +146,22 @@ def test_constructor_invalid(self, args, exc, errmsg):
with pytest.raises(exc, match=errmsg):
ss(*args)

def test_constructor_complex_matrices(self):
"""Test complex-valued matrices in StateSpace() constructor"""
A = np.array([[1 + 1j, 2 - 3j], [3 + 2j, 4 - 1j]])
B = np.array([[1 - 2j], [3 + 4j]])
C = np.array([[5 + 6j, 7 - 8j]])
D = np.array([[9 + 10j]])

with warnings.catch_warnings():
warnings.simplefilter("error")
sys = StateSpace(A, B, C, D)

np.testing.assert_allclose(sys.A, A)
np.testing.assert_allclose(sys.B, B)
np.testing.assert_allclose(sys.C, C)
np.testing.assert_allclose(sys.D, D)

def test_constructor_warns(self, sys322ABCD):
"""Test ambiguos input to StateSpace() constructor"""
with pytest.warns(UserWarning, match="received multiple dt"):
Expand Down