@@ -193,20 +193,14 @@ def _remove_useless_states(self):
193193
194194 """
195195
196- # Indices of useless states.
197- useless = []
198-
199196 # Search for useless states.
200- for i in range (self .states ):
201- if (all (self .A [i , :] == zeros ((1 , self .states ))) and
202- all (self .B [i , :] == zeros ((1 , self .inputs )))):
203- useless .append (i )
204- # To avoid duplucate indices in useless, jump to the next
205- # iteration.
206- continue
207- if (all (self .A [:, i ] == zeros ((self .states , 1 ))) and
208- all (self .C [:, i ] == zeros ((self .outputs , 1 )))):
209- useless .append (i )
197+ ax1_A = np .where (~ self .A .any (axis = 1 ))[0 ]
198+ ax1_B = np .where (~ self .B .any (axis = 1 ))[0 ]
199+ ax0_A = np .where (~ self .A .any (axis = 0 ))[1 ]
200+ ax0_C = np .where (~ self .C .any (axis = 0 ))[1 ]
201+ useless_1 = np .intersect1d (ax1_A , ax1_B , assume_unique = True )
202+ useless_2 = np .intersect1d (ax0_A , ax0_C , assume_unique = True )
203+ useless = np .concatenate ((useless_1 , useless_2 ))
210204
211205 # Remove the useless states.
212206 self .A = delete (self .A , useless , 0 )
0 commit comments