On Thursday, August 28, 2014 6:36:16 AM UTC-4, Andrei Berceanu wrote:
>
> Steven, could you detail your macro proposal please? What exactly do you
> have in mind?
>
e.g. you could have a macro like (caution: untested):
macro M(m,n, ε1, ε2, ε3, X1,X2,X3, A1,A2,A3)
ε = [ε1, ε2, ε3]
X = [X1,X2,X3]
A = [A1,A2,A3]
Asum = {:+}
for q=1:3, t=1:3
if m+q == n+t
push!(Asum, :($(A[q])' * $(A[t])))
end
end
if m == n
:($(ε[m]) + 2*abs2($(X[m])) * $(Expr(:call, Asum)))
else
:(2 * $(X[m])' $(X[n]) * $(Expr(:call, Asum)))
end
end
Then calling e.g. @M(1,2,ε1, ε2, ε3, X1,X2,X3, A1,A2,A3) would insert a
hard-coded
expression for M[1,2] according to your formula, with only the nonzero
delta terms. Here εm denotes the m'th case of your expression [ε(k_m+k)
.... ] in brackets, Xm denotes X(k_m+k), and Am denotes Ã_m.
Macros are essentially functions evaluated at parse-time, not at runtime,
so they are exactly what you want in order to auto-generate fast inlined
code resulting from some complicated symbolic expression that is known in
advance, with whatever simplifications you can devise.
You could write another macro for the entries of Q, and another macro to
put it all together and evaluate the whole matrix if you want.