Skip to content

Commit 8793d78

Browse files
committed
set array_priority=11 for TransferFunction, to match StateSpace
1 parent 85c9e7f commit 8793d78

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

control/tests/xferfcn_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
import numpy as np
77
import pytest
8+
import operator
89

10+
import control as ct
911
from control.statesp import StateSpace, _convertToStateSpace, rss
1012
from control.xferfcn import TransferFunction, _convert_to_transfer_function, \
1113
ss2tf
@@ -1022,3 +1024,20 @@ def test_returnScipySignalLTI_error(self, mimotf):
10221024
mimotf.returnScipySignalLTI()
10231025
with pytest.raises(ValueError):
10241026
mimotf.returnScipySignalLTI(strict=True)
1027+
1028+
@pytest.mark.parametrize(
1029+
"op",
1030+
[pytest.param(getattr(operator, s), id=s) for s in ('add', 'sub', 'mul')])
1031+
@pytest.mark.parametrize(
1032+
"tf, arr",
1033+
[# pytest.param(ct.tf([1], [0.5, 1]), np.array(2.), id="0D scalar"),
1034+
# pytest.param(ct.tf([1], [0.5, 1]), np.array([2.]), id="1D scalar"),
1035+
pytest.param(ct.tf([1], [0.5, 1]), np.array([[2.]]), id="2D scalar")])
1036+
def test_xferfcn_ndarray_precedence(op, tf, arr):
1037+
# Apply the operator to the transfer function and array
1038+
result = op(tf, arr)
1039+
assert isinstance(result, ct.TransferFunction)
1040+
1041+
# Apply the operator to the array and transfer function
1042+
result = op(arr, tf)
1043+
assert isinstance(result, ct.TransferFunction)

control/xferfcn.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class TransferFunction(LTI):
114114
>>> G = (s + 1)/(s**2 + 2*s + 1)
115115
"""
116116

117+
# Give TransferFunction._rmul_() priority for ndarray * TransferFunction
118+
__array_priority__ = 11 # override ndarray and matrix types
119+
117120
def __init__(self, *args, **kwargs):
118121
"""TransferFunction(num, den[, dt])
119122

0 commit comments

Comments
 (0)