7777
7878# Define module default parameter values
7979_statesp_defaults = {
80- 'statesp.use_numpy_matrix' : False , # False is default in 0.9.0 and above
8180 'statesp.remove_useless_states' : False ,
8281 'statesp.latex_num_format' : '.3g' ,
8382 'statesp.latex_repr_type' : 'partitioned' ,
@@ -104,14 +103,8 @@ def _ssmatrix(data, axis=1):
104103 arr : 2D array, with shape (0, 0) if a is empty
105104
106105 """
107- # Convert the data into an array or matrix, as configured
108- # If data is passed as a string, use (deprecated?) matrix constructor
109- if config .defaults ['statesp.use_numpy_matrix' ]:
110- arr = np .matrix (data , dtype = float )
111- elif isinstance (data , str ):
112- arr = np .array (np .matrix (data , dtype = float ))
113- else :
114- arr = np .array (data , dtype = float )
106+ # Convert the data into an array
107+ arr = np .array (data , dtype = float )
115108 ndim = arr .ndim
116109 shape = arr .shape
117110
@@ -205,12 +198,7 @@ class StateSpace(LTI):
205198 -----
206199 The main data members in the ``StateSpace`` class are the A, B, C, and D
207200 matrices. The class also keeps track of the number of states (i.e.,
208- the size of A). The data format used to store state space matrices is
209- set using the value of `config.defaults['use_numpy_matrix']`. If True
210- (default), the state space elements are stored as `numpy.matrix` objects;
211- otherwise they are `numpy.ndarray` objects. The
212- :func:`~control.use_numpy_matrix` function can be used to set the storage
213- type.
201+ the size of A).
214202
215203 A discrete time system is created by specifying a nonzero 'timebase', dt
216204 when the system is constructed:
@@ -358,10 +346,8 @@ def __init__(self, *args, init_namedio=True, **kwargs):
358346 elif kwargs :
359347 raise TypeError ("unrecognized keyword(s): " , str (kwargs ))
360348
361- # Reset shapes (may not be needed once np.matrix support is removed)
349+ # Reset shape if system is static
362350 if self ._isstatic ():
363- # static gain
364- # matrix's default "empty" shape is 1x0
365351 A .shape = (0 , 0 )
366352 B .shape = (0 , self .ninputs )
367353 C .shape = (self .noutputs , 0 )
@@ -467,10 +453,6 @@ def _remove_useless_states(self):
467453 """
468454
469455 # Search for useless states and get indices of these states.
470- #
471- # Note: shape from np.where depends on whether we are storing state
472- # space objects as np.matrix or np.array. Code below will work
473- # correctly in either case.
474456 ax1_A = np .where (~ self .A .any (axis = 1 ))[0 ]
475457 ax1_B = np .where (~ self .B .any (axis = 1 ))[0 ]
476458 ax0_A = np .where (~ self .A .any (axis = 0 ))[- 1 ]
@@ -502,12 +484,11 @@ def __str__(self):
502484 return string
503485
504486 # represent to implement a re-loadable version
505- # TODO: remove the conversion to array when matrix is no longer used
506487 def __repr__ (self ):
507488 """Print state-space system in loadable form."""
508489 return "StateSpace({A}, {B}, {C}, {D}{dt})" .format (
509- A = asarray ( self .A ) .__repr__ (), B = asarray ( self .B ) .__repr__ (),
510- C = asarray ( self .C ) .__repr__ (), D = asarray ( self .D ) .__repr__ (),
490+ A = self .A .__repr__ (), B = self .B .__repr__ (),
491+ C = self .C .__repr__ (), D = self .D .__repr__ (),
511492 dt = (isdtime (self , strict = True ) and ", {}" .format (self .dt )) or '' )
512493
513494 def _latex_partitioned_stateless (self ):
@@ -930,18 +911,17 @@ def horner(self, x, warn_infinite=True):
930911 x_arr = np .atleast_1d (x ).astype (complex , copy = False )
931912
932913 # return fast on systems with 0 or 1 state
933- if not config .defaults ['statesp.use_numpy_matrix' ]:
934- if self .nstates == 0 :
935- return self .D [:, :, np .newaxis ] \
936- * np .ones_like (x_arr , dtype = complex )
937- if self .nstates == 1 :
938- with np .errstate (divide = 'ignore' , invalid = 'ignore' ):
939- out = self .C [:, :, np .newaxis ] \
940- / (x_arr - self .A [0 , 0 ]) \
941- * self .B [:, :, np .newaxis ] \
942- + self .D [:, :, np .newaxis ]
943- out [np .isnan (out )] = complex (np .inf , np .nan )
944- return out
914+ if self .nstates == 0 :
915+ return self .D [:, :, np .newaxis ] \
916+ * np .ones_like (x_arr , dtype = complex )
917+ elif self .nstates == 1 :
918+ with np .errstate (divide = 'ignore' , invalid = 'ignore' ):
919+ out = self .C [:, :, np .newaxis ] \
920+ / (x_arr - self .A [0 , 0 ]) \
921+ * self .B [:, :, np .newaxis ] \
922+ + self .D [:, :, np .newaxis ]
923+ out [np .isnan (out )] = complex (np .inf , np .nan )
924+ return out
945925
946926 try :
947927 out = self .slycot_laub (x_arr )
0 commit comments