Skip to content

Commit 2ce4bbd

Browse files
authored
Merge pull request #680 from bnavigator/vector-frd-feedback
vectorize FRD feedback function
2 parents 4f681ab + 37c95b6 commit 2ce4bbd

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

control/frdata.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -535,16 +535,15 @@ def feedback(self, other=1, sign=-1):
535535
if (self.noutputs != other.ninputs or self.ninputs != other.noutputs):
536536
raise ValueError(
537537
"FRD.feedback, inputs/outputs mismatch")
538-
fresp = empty((self.noutputs, self.ninputs, len(other.omega)),
539-
dtype=complex)
540-
# TODO: vectorize this
538+
541539
# TODO: handle omega re-mapping
542-
# TODO: is there a reason to use linalg.solve instead of linalg.inv?
543-
# https://github.com/python-control/python-control/pull/314#discussion_r294075154
544-
for k, w in enumerate(other.omega):
545-
fresp[:, :, k] = self.fresp[:, :, k] @ linalg.solve(
546-
eye(self.ninputs) + other.fresp[:, :, k] @ self.fresp[:, :, k],
547-
eye(self.ninputs))
540+
541+
# reorder array axes in order to leverage numpy broadcasting
542+
myfresp = np.moveaxis(self.fresp, 2, 0)
543+
otherfresp = np.moveaxis(other.fresp, 2, 0)
544+
I_AB = eye(self.ninputs)[np.newaxis, :, :] + otherfresp @ myfresp
545+
resfresp = (myfresp @ linalg.inv(I_AB))
546+
fresp = np.moveaxis(resfresp, 0, 2)
548547

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy