Preserve complex StateSpace matrices#1230
Conversation
|
Local verification on The only local warning was pytest being unable to write |
|
@marko1olo thanks for this and the other recent PRs that you have opened. I have several requests that apply to all of these (including this one):
|
slivingston
left a comment
There was a problem hiding this comment.
Formally marking this as "request changes" until my comment is addressed.
@marko1olo I want to emphasize that using AI tools is OK. I just want to understand how they are being used. Many projects are now struggling from a rush of PRs and issues generated by tools like Claude, Codex, etc. While this is not a problem for us yet, I want to think how we can keep the signal-to-noise ratio high for contributions.
Fixes #1058.
StateSpace(A, B, C, D)currently coerces every state-space matrix throughnp.array(..., dtype=float), which silently discards imaginary parts from complex-valued matrices and emitsComplexWarning. State-space operations already evaluate complex frequencies and NumPy can safely keep real matrices as floats, so this changes_ssmatrix()to preserve complex dtype only when the input is complex-valued.The regression test covers complex A/B/C/D matrices and treats constructor warnings as errors, so the old
ComplexWarningpath fails directly.Validation:
mainbefore the fix: complex matrices were stored as real matrices and emitted fourComplexWarnings.python -m pytest control/tests/statesp_test.py::TestStateSpace::test_constructor_complex_matrices control/tests/statesp_test.py::TestStateSpace::test_constructor_invalid -qpython -m pytest control/tests/statesp_test.py -qpython -m pytest control/tests/convert_test.py control/tests/type_conversion_test.py control/tests/xferfcn_test.py control/tests/bdalg_test.py -qpython -m ruff check control/statesp.py control/tests/statesp_test.pypython -m compileall -q controlgit diff --checkNote: I also attempted
python -m pytest control/tests -q, but the local Windows run exceeded a 5-minute timeout before producing useful output.Assisted-by: OpenAI Codex