Skip to content

vectorize FRD feedback function #680

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 2 commits into from
Dec 26, 2021
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
17 changes: 8 additions & 9 deletions control/frdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,16 +535,15 @@ def feedback(self, other=1, sign=-1):
if (self.noutputs != other.ninputs or self.ninputs != other.noutputs):
raise ValueError(
"FRD.feedback, inputs/outputs mismatch")
fresp = empty((self.noutputs, self.ninputs, len(other.omega)),
dtype=complex)
# TODO: vectorize this

# TODO: handle omega re-mapping
# TODO: is there a reason to use linalg.solve instead of linalg.inv?
# https://github.com/python-control/python-control/pull/314#discussion_r294075154
for k, w in enumerate(other.omega):
fresp[:, :, k] = self.fresp[:, :, k] @ linalg.solve(
eye(self.ninputs) + other.fresp[:, :, k] @ self.fresp[:, :, k],
eye(self.ninputs))

# reorder array axes in order to leverage numpy broadcasting
myfresp = np.moveaxis(self.fresp, 2, 0)
otherfresp = np.moveaxis(other.fresp, 2, 0)
I_AB = eye(self.ninputs)[np.newaxis, :, :] + otherfresp @ myfresp
resfresp = (myfresp @ linalg.inv(I_AB))
fresp = np.moveaxis(resfresp, 0, 2)

return FRD(fresp, other.omega, smooth=(self.ifunc is not None))

Expand Down