Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summing Complex Measurements #99

Closed
JonasIsensee opened this issue Mar 23, 2021 · 1 comment
Closed

Summing Complex Measurements #99

JonasIsensee opened this issue Mar 23, 2021 · 1 comment

Comments

@JonasIsensee
Copy link

Hi,
the following caught me by surprise...
Is there any good reason that the "true" sum function is so much more expensive?

julia> using Measurements
[ Info: Precompiling Measurements [eff96d63-e80a-5855-80a2-b1b0885c5ab7]

julia> x = rand(1000) .± rand(1000);

julia> z = complex.(x,x);

julia> @time sum(x)
  0.124190 seconds (351.04 k allocations: 18.032 MiB)
496.0 ± 18.0

julia> @time sum(z)
  2.022132 seconds (1.20 M allocations: 56.428 MiB, 1.64% gc time)
(496.0 ± 18.0) + (496.0 ± 18.0)im

julia> Base.sum(z::Array{Complex{Measurement{T}}}) where T= sum(real.(z)) .+ im*sum(imag.(z))

julia> @time sum(z)
  0.126569 seconds (321.87 k allocations: 16.926 MiB)
(496.0 ± 18.0) + (496.0 ± 18.0)im
@giordano
Copy link
Member

Yes, this is a duplicate of #25. In particular see #25 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants