Hi guys!
After my last post related to optimization (Help to reduce number of allocations - #23 by baggepinnen) I realized how much I can gain if I use mul!
to avoid allocation on every loop iteration. However, the code becomes very “unreadable”. Take a look:
# Pp = Fk_1*Pu*Fk_1' + Q
mul!(aux1, Fk_1, Pu)
mul!(aux2, aux1, Fk_1')
@. Pp = aux2 + Q
# K = Pp*Hk'*pinv(R + Hk*Pp*Hk')
mul!(aux3, Pp, Hk')
mul!(aux4, Hk, aux3)
mul!(K, aux3, pinv(R + aux4))
# Pu = (I - K*Hk)*Pp*(I - K*Hk)' + K*R*K'
mul!(aux1, K, Hk)
@. aux2 = I18 - aux1
mul!(aux5, aux2, Pp)
mul!(aux6, aux5, aux2')
mul!(aux3, K, R)
mul!(aux5, aux3, K')
@. Pu = aux6 + aux5
compared to
Pp = Fk_1*Pu*Fk_1' + Q
K = Pp*Hk'*pinv(R + Hk*Pp*Hk')
Pu = (I - K*Hk)*Pp*(I - K*Hk)' + K*R*K'
Hence, I am wondering if we could develop a new operator to replace mul!
. I thought very little about this but what about:
Fk_1*->(aux)Pp
to replace
mul!(aux, Fk_1, Pp)
aux
(or anything else that can make me write the entire expression on a single line)
Pp .= Fk_1*->(aux1)Pu*->(aux2)Fk_1' + Q