|
10 | 10 |
|
11 | 11 | # Python 3 compatibility (needs to go here)
|
12 | 12 | from __future__ import print_function
|
| 13 | +from __future__ import division # for _convertToStateSpace |
13 | 14 |
|
14 | 15 | """Copyright (c) 2010 by California Institute of Technology
|
15 | 16 | All rights reserved.
|
@@ -647,6 +648,7 @@ def _convertToStateSpace(sys, **kw):
|
647 | 648 | """
|
648 | 649 |
|
649 | 650 | from .xferfcn import TransferFunction
|
| 651 | + import itertools |
650 | 652 | if isinstance(sys, StateSpace):
|
651 | 653 | if len(kw):
|
652 | 654 | raise TypeError("If sys is a StateSpace, _convertToStateSpace \
|
@@ -679,16 +681,26 @@ def _convertToStateSpace(sys, **kw):
|
679 | 681 | ssout[3][:sys.outputs, :states],
|
680 | 682 | ssout[4], sys.dt)
|
681 | 683 | except ImportError:
|
682 |
| - # If slycot is not available, use signal.lti (SISO only) |
683 |
| - if (sys.inputs != 1 or sys.outputs != 1): |
684 |
| - raise TypeError("No support for MIMO without slycot") |
685 |
| - |
686 |
| - # TODO: do we want to squeeze first and check dimenations? |
687 |
| - # I think this will fail if num and den aren't 1-D after |
688 |
| - # the squeeze |
689 |
| - lti_sys = lti(squeeze(sys.num), squeeze(sys.den)) |
690 |
| - return StateSpace(lti_sys.A, lti_sys.B, lti_sys.C, lti_sys.D, |
691 |
| - sys.dt) |
| 684 | + # No Slycot. Scipy tf->ss can't handle MIMO, but static MIMO is an easy special case we can check for here |
| 685 | + maxn = max(max(len(n) for n in nrow) |
| 686 | + for nrow in sys.num) |
| 687 | + maxd = max(max(len(d) for d in drow) |
| 688 | + for drow in sys.den) |
| 689 | + if 1==maxn and 1==maxd: |
| 690 | + D = empty((sys.outputs,sys.inputs),dtype=float) |
| 691 | + for i,j in itertools.product(range(sys.outputs),range(sys.inputs)): |
| 692 | + D[i,j] = sys.num[i][j][0] / sys.den[i][j][0] |
| 693 | + return StateSpace([], [], [], D, sys.dt) |
| 694 | + else: |
| 695 | + if (sys.inputs != 1 or sys.outputs != 1): |
| 696 | + raise TypeError("No support for MIMO without slycot") |
| 697 | + |
| 698 | + # TODO: do we want to squeeze first and check dimenations? |
| 699 | + # I think this will fail if num and den aren't 1-D after |
| 700 | + # the squeeze |
| 701 | + lti_sys = lti(squeeze(sys.num), squeeze(sys.den)) |
| 702 | + return StateSpace(lti_sys.A, lti_sys.B, lti_sys.C, lti_sys.D, |
| 703 | + sys.dt) |
692 | 704 |
|
693 | 705 | elif isinstance(sys, (int, float, complex)):
|
694 | 706 | if "inputs" in kw:
|
|
0 commit comments