Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
set array_priority=11 for TransferFunction, to match StateSpace
  • Loading branch information
murrayrm committed Jan 8, 2021
commit 8793d780a0ed83cc7b97e94de88a1aa72b7463f9
19 changes: 19 additions & 0 deletions control/tests/xferfcn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import numpy as np
import pytest
import operator

import control as ct
from control.statesp import StateSpace, _convertToStateSpace, rss
from control.xferfcn import TransferFunction, _convert_to_transfer_function, \
ss2tf
Expand Down Expand Up @@ -1022,3 +1024,20 @@ def test_returnScipySignalLTI_error(self, mimotf):
mimotf.returnScipySignalLTI()
with pytest.raises(ValueError):
mimotf.returnScipySignalLTI(strict=True)

@pytest.mark.parametrize(
"op",
[pytest.param(getattr(operator, s), id=s) for s in ('add', 'sub', 'mul')])
@pytest.mark.parametrize(
"tf, arr",
[# pytest.param(ct.tf([1], [0.5, 1]), np.array(2.), id="0D scalar"),
# pytest.param(ct.tf([1], [0.5, 1]), np.array([2.]), id="1D scalar"),
pytest.param(ct.tf([1], [0.5, 1]), np.array([[2.]]), id="2D scalar")])
def test_xferfcn_ndarray_precedence(op, tf, arr):
# Apply the operator to the transfer function and array
result = op(tf, arr)
assert isinstance(result, ct.TransferFunction)

# Apply the operator to the array and transfer function
result = op(arr, tf)
assert isinstance(result, ct.TransferFunction)
3 changes: 3 additions & 0 deletions control/xferfcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class TransferFunction(LTI):
>>> G = (s + 1)/(s**2 + 2*s + 1)
"""

# Give TransferFunction._rmul_() priority for ndarray * TransferFunction
__array_priority__ = 11 # override ndarray and matrix types

def __init__(self, *args, **kwargs):
"""TransferFunction(num, den[, dt])

Expand Down