Skip to content

Commit 323ae3d

Browse files
committed
vectorize FRD feedback function
1 parent 81a4f38 commit 323ae3d

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

control/frdata.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -536,20 +536,14 @@ def feedback(self, other=1, sign=-1):
536536
if (self.noutputs != other.ninputs or self.ninputs != other.noutputs):
537537
raise ValueError(
538538
"FRD.feedback, inputs/outputs mismatch")
539-
fresp = empty((self.noutputs, self.ninputs, len(other.omega)),
540-
dtype=complex)
541-
# TODO: vectorize this
539+
542540
# TODO: handle omega re-mapping
543-
# TODO: is there a reason to use linalg.solve instead of linalg.inv?
544-
# https://github.com/python-control/python-control/pull/314#discussion_r294075154
545-
for k, w in enumerate(other.omega):
546-
fresp[:, :, k] = np.dot(
547-
self.fresp[:, :, k],
548-
linalg.solve(
549-
eye(self.ninputs)
550-
+ np.dot(other.fresp[:, :, k], self.fresp[:, :, k]),
551-
eye(self.ninputs))
552-
)
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)
553547

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

0 commit comments

Comments
 (0)