We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 900d56e + cc3fb2f commit 4b712a4Copy full SHA for 4b712a4
control/frdata.py
@@ -408,10 +408,6 @@ def __truediv__(self, other):
408
smooth=(self.ifunc is not None) and
409
(other.ifunc is not None))
410
411
- # TODO: Remove when transition to python3 complete
412
- def __div__(self, other):
413
- return self.__truediv__(other)
414
-
415
# TODO: Division of MIMO transfer function objects is not written yet.
416
def __rtruediv__(self, other):
417
"""Right divide two LTI objects."""
@@ -429,10 +425,6 @@ def __rtruediv__(self, other):
429
425
430
426
return other / self
431
427
432
433
- def __rdiv__(self, other):
434
- return self.__rtruediv__(other)
435
436
428
def __pow__(self, other):
437
if not type(other) == int:
438
raise ValueError("Exponent must be an integer")
control/iosys.py
@@ -346,6 +346,19 @@ def __neg__(sys):
346
# Return the newly created system
347
return newsys
348
349
+ def __truediv__(sys2, sys1):
350
+ """Division of input/output systems
351
+
352
+ Only division by scalars and arrays of scalars is supported"""
353
+ # Note: order of arguments is flipped so that self = sys2,
354
+ # corresponding to the ordering convention of sys2 * sys1
355
356
+ if not isinstance(sys1, (LTI, NamedIOSystem)):
357
+ return sys2 * (1/sys1)
358
+ else:
359
+ return NotImplemented
360
361
362
# Update parameters used for _rhs, _out (used by subclasses)
363
def _update_params(self, params, warning=False):
364
if warning:
control/statesp.py
@@ -64,7 +64,7 @@
64
from .frdata import FrequencyResponseData
65
from .lti import LTI, _process_frequency_response
66
from .namedio import common_timebase, isdtime, _process_namedio_keywords, \
67
- _process_dt_keyword
+ _process_dt_keyword, NamedIOSystem
68
from . import config
69
from copy import deepcopy
70
@@ -794,17 +794,18 @@ def __rmul__(self, other):
794
pass
795
raise TypeError("can't interconnect systems")
796
797
- # TODO: __div__ and __rdiv__ are not written yet.
798
799
- """Divide two LTI systems."""
+ # TODO: general __truediv__, and __rtruediv__; requires descriptor system support
+ def __truediv__(self, other):
+ """Division of StateSpace systems
800
801
- raise NotImplementedError("StateSpace.__div__ is not implemented yet.")
802
803
804
- """Right divide two LTI systems."""
+ Only division by TFs, FRDs, scalars, and arrays of scalars is
+ supported.
+ """
+ if not isinstance(other, (LTI, NamedIOSystem)):
805
+ return self * (1/other)
806
807
808
- raise NotImplementedError(
- "StateSpace.__rdiv__ is not implemented yet.")
809
810
def __call__(self, x, squeeze=None, warn_infinite=True):
811
"""Evaluate system's transfer function at complex frequency.
control/tests/statesp_test.py
@@ -333,6 +333,17 @@ def test_multiply_ss(self, sys222, sys322):
333
np.testing.assert_array_almost_equal(sys.C, C)
334
np.testing.assert_array_almost_equal(sys.D, D)
335
336
+ @pytest.mark.parametrize("k", [2, -3.141, np.float32(2.718), np.array([[4.321], [5.678]])])
337
+ def test_truediv_ss_scalar(self, sys322, k):
338
+ """Divide SS by scalar."""
339
+ sys = sys322 / k
340
+ syscheck = sys322 * (1/k)
341
342
+ np.testing.assert_array_almost_equal(sys.A, syscheck.A)
343
+ np.testing.assert_array_almost_equal(sys.B, syscheck.B)
344
+ np.testing.assert_array_almost_equal(sys.C, syscheck.C)
345
+ np.testing.assert_array_almost_equal(sys.D, syscheck.D)
@pytest.mark.parametrize("omega, resp",
[(1.,
np.array([[ 4.37636761e-05-0.01522976j,
control/tests/type_conversion_test.py
@@ -88,11 +88,11 @@ def sys_dict():
88
('mul', 'flt', ['ss', 'tf', 'frd', 'lio', 'ios', 'arr', 'flt']),
89
90
# op left ss tf frd lio ios arr flt
91
- ('truediv', 'ss', ['xs', 'tf', 'frd', 'xio', 'xos', 'xs', 'xs' ]),
+ ('truediv', 'ss', ['xs', 'tf', 'frd', 'xio', 'xos', 'ss', 'ss' ]),
92
('truediv', 'tf', ['tf', 'tf', 'xrd', 'tf', 'xos', 'tf', 'tf' ]),
93
('truediv', 'frd', ['frd', 'frd', 'frd', 'frd', 'E', 'frd', 'frd']),
94
- ('truediv', 'lio', ['xio', 'tf', 'frd', 'xio', 'xio', 'xio', 'xio']),
95
- ('truediv', 'ios', ['xos', 'xos', 'E', 'xos', 'xos' 'xos', 'xos']),
+ ('truediv', 'lio', ['xio', 'tf', 'frd', 'xio', 'xio', 'lio', 'lio']),
+ ('truediv', 'ios', ['xos', 'xos', 'E', 'xos', 'xos', 'ios', 'ios']),
96
('truediv', 'arr', ['xs', 'tf', 'frd', 'xio', 'xos', 'arr', 'arr']),
97
('truediv', 'flt', ['xs', 'tf', 'frd', 'xio', 'xos', 'arr', 'flt'])]
98
control/xferfcn.py
@@ -702,10 +702,6 @@ def __truediv__(self, other):
702
703
return TransferFunction(num, den, dt)
704
705
706
707
- return TransferFunction.__truediv__(self, other)
708
709
710
711
@@ -724,10 +720,6 @@ def __rtruediv__(self, other):
724
720
725
721
726
722
727
728
729
- return TransferFunction.__rtruediv__(self, other)
730
731
723
732
733
0 commit comments