Skip to content

Commit b6b032f

Browse files
committed
Move tf_close_coeff to xferfcn
1 parent 053c3c6 commit b6b032f

2 files changed

Lines changed: 48 additions & 48 deletions

File tree

control/tests/bdalg_test.py

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99

1010
import control as ctrl
11-
from control.xferfcn import TransferFunction
11+
from control.xferfcn import TransferFunction, _tf_close_coeff
1212
from control.statesp import StateSpace
1313
from control.bdalg import feedback, append, connect
1414
from control.lti import zeros, poles
@@ -870,50 +870,3 @@ def test_error_combine_tf(self, tf_array, exception):
870870
"""Test error cases."""
871871
with pytest.raises(exception):
872872
ctrl.combine_tf(tf_array)
873-
874-
875-
def _tf_close_coeff(tf_a, tf_b, rtol=1e-5, atol=1e-8):
876-
"""Check if two transfer functions have close coefficients.
877-
878-
Parameters
879-
----------
880-
tf_a : TransferFunction
881-
First transfer function.
882-
tf_b : TransferFunction
883-
Second transfer function.
884-
rtol : float
885-
Relative tolerance for ``np.allclose``.
886-
atol : float
887-
Absolute tolerance for ``np.allclose``.
888-
889-
Returns
890-
-------
891-
bool
892-
True if transfer function cofficients are all close.
893-
"""
894-
# Check number of outputs and inputs
895-
if tf_a.noutputs != tf_b.noutputs:
896-
return False
897-
if tf_a.ninputs != tf_b.ninputs:
898-
return False
899-
# Check timestep
900-
if tf_a.dt != tf_b.dt:
901-
return False
902-
# Check coefficient arrays
903-
for i in range(tf_a.noutputs):
904-
for j in range(tf_a.ninputs):
905-
if not np.allclose(
906-
tf_a.num[i][j],
907-
tf_b.num[i][j],
908-
rtol=rtol,
909-
atol=atol,
910-
):
911-
return False
912-
if not np.allclose(
913-
tf_a.den[i][j],
914-
tf_b.den[i][j],
915-
rtol=rtol,
916-
atol=atol,
917-
):
918-
return False
919-
return True

control/xferfcn.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,3 +1924,50 @@ def _clean_part(data):
19241924
def _float2str(value):
19251925
_num_format = config.defaults.get('xferfcn.floating_point_format', ':.4g')
19261926
return f"{value:{_num_format}}"
1927+
1928+
1929+
def _tf_close_coeff(tf_a, tf_b, rtol=1e-5, atol=1e-8):
1930+
"""Check if two transfer functions have close coefficients.
1931+
1932+
Parameters
1933+
----------
1934+
tf_a : TransferFunction
1935+
First transfer function.
1936+
tf_b : TransferFunction
1937+
Second transfer function.
1938+
rtol : float
1939+
Relative tolerance for ``np.allclose``.
1940+
atol : float
1941+
Absolute tolerance for ``np.allclose``.
1942+
1943+
Returns
1944+
-------
1945+
bool
1946+
True if transfer function cofficients are all close.
1947+
"""
1948+
# Check number of outputs and inputs
1949+
if tf_a.noutputs != tf_b.noutputs:
1950+
return False
1951+
if tf_a.ninputs != tf_b.ninputs:
1952+
return False
1953+
# Check timestep
1954+
if tf_a.dt != tf_b.dt:
1955+
return False
1956+
# Check coefficient arrays
1957+
for i in range(tf_a.noutputs):
1958+
for j in range(tf_a.ninputs):
1959+
if not np.allclose(
1960+
tf_a.num[i][j],
1961+
tf_b.num[i][j],
1962+
rtol=rtol,
1963+
atol=atol,
1964+
):
1965+
return False
1966+
if not np.allclose(
1967+
tf_a.den[i][j],
1968+
tf_b.den[i][j],
1969+
rtol=rtol,
1970+
atol=atol,
1971+
):
1972+
return False
1973+
return True

0 commit comments

Comments
 (0)