@@ -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