Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Performance improvements to _remove_useless_states routine in statesp.py #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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