As a first exercise, I wanted to code magnitude squared of a complex 1-d array. Here is what I did:
mag_sqr{T} (x::Array{Complex{T},1}) = sum(real(x).*real(x)+imag(x).*imag(x))
Is this a "good" approach? I'm wondering if it's not very efficient, since I
expect it would compute matrixes of element-wise products first, rather than
doing the sum as a running summation (like a loop in c++).
Can you suggest something "better"?
