Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions control/statesp.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,15 @@ def _remove_useless_states(self):

"""

# Indices of useless states.
useless = []

# Search for useless states.
for i in range(self.states):
if (all(self.A[i, :] == zeros((1, self.states))) and
all(self.B[i, :] == zeros((1, self.inputs)))):
useless.append(i)
# To avoid duplicate indices in useless, jump to the next
# iteration.
continue
if (all(self.A[:, i] == zeros((self.states, 1))) and
all(self.C[:, i] == zeros((self.outputs, 1)))):
useless.append(i)
# Search for useless states and get the indices of these states
# as an array.
ax1_A = np.where(~self.A.any(axis=1))[0]
ax1_B = np.where(~self.B.any(axis=1))[0]
ax0_A = np.where(~self.A.any(axis=0))[1]
ax0_C = np.where(~self.C.any(axis=0))[1]
useless_1 = np.intersect1d(ax1_A, ax1_B, assume_unique=True)
useless_2 = np.intersect1d(ax0_A, ax0_C, assume_unique=True)
useless = np.union1d(useless_1, useless_2)

# Remove the useless states.
self.A = delete(self.A, useless, 0)
Expand Down