fix(xferfcn): normalize real zpk coefficients#1226
Open
marko1olo wants to merge 1 commit into
Open
Conversation
Normalize floating coefficient arrays after zpk2tf so complex dtype zero/pole inputs that produce real polynomial coefficients do not leave float32 or tiny imaginary residue in TransferFunction internals. Continue rejecting actual complex transfer function coefficients. Co-authored-by: OpenAI Codex <codex@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1188.
This does not add support for complex transfer-function coefficients. Instead, it keeps that boundary explicit while normalizing the cases that should remain real:
zpk()with complex dtype zero/pole arrays can produce real polynomial coefficients with eitherfloat32dtype or tiny imaginary roundoff fromzpk2tf().float32coefficients later madestr(sys)fail because the polynomial printer evals the array repr and does not havefloat32in scope.unsupported data type: numpy.complex128.The fix validates coefficient arrays in
_clean_part(), accepts complex arrays only when their imaginary parts are numerical zero at coefficient scale, normalizes accepted floating arrays to default float dtype, and continues rejecting actual complex coefficients.Verification:
complex64zpk systems created successfully butstr(sys)failed withNameError: name 'float32' is not defined;complex128intermittently raisedTypeErrordepending on random roots.complex64andcomplex128zpk systems both created and printed successfully for all seeds.python -m pytest control\tests\xferfcn_test.py::TestXferFcn::test_constructor_bad_input_type control\tests\xferfcn_test.py::test_zpk_complex_dtype_real_coefficients -qpython -m pytest control\tests\xferfcn_test.py -qpython -m ruff check --no-cache control\xferfcn.py control\tests\xferfcn_test.pyPYTHONPYCACHEPREFIX=C:\tmp\pycache-python-control-1188 python -m compileall -q control\xferfcn.py control\tests\xferfcn_test.pygit diff --checkAI-assisted contribution: implemented with OpenAI Codex and manually verified with the commands above.