|
10 | 10 |
|
11 | 11 | # Python 3 compatibility (needs to go here)
|
12 | 12 | from __future__importprint_function
|
| 13 | +from __future__importdivision# 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 .xferfcnimportTransferFunction
|
| 651 | +importitertools |
650 | 652 | ifisinstance(sys,StateSpace):
|
651 | 653 | iflen(kw):
|
652 | 654 | raiseTypeError("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 | exceptImportError:
|
682 |
| -# If slycot is not available, use signal.lti (SISO only) |
683 |
| -if (sys.inputs!=1orsys.outputs!=1): |
684 |
| -raiseTypeError("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 |
| -returnStateSpace(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)forninnrow) |
| 686 | +fornrowinsys.num) |
| 687 | +maxd=max(max(len(d)fordindrow) |
| 688 | +fordrowinsys.den) |
| 689 | +if1==maxnand1==maxd: |
| 690 | +D=empty((sys.outputs,sys.inputs),dtype=float) |
| 691 | +fori,jinitertools.product(range(sys.outputs),range(sys.inputs)): |
| 692 | +D[i,j]=sys.num[i][j][0]/sys.den[i][j][0] |
| 693 | +returnStateSpace([], [], [],D,sys.dt) |
| 694 | +else: |
| 695 | +if (sys.inputs!=1orsys.outputs!=1): |
| 696 | +raiseTypeError("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 | +returnStateSpace(lti_sys.A,lti_sys.B,lti_sys.C,lti_sys.D, |
| 703 | +sys.dt) |
692 | 704 |
|
693 | 705 | elifisinstance(sys, (int,float,complex)):
|
694 | 706 | if"inputs"inkw:
|
|