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

mean! may return incorrect results #71

Closed
yurivish opened this issue Jan 24, 2021 · 3 comments
Closed

mean! may return incorrect results #71

yurivish opened this issue Jan 24, 2021 · 3 comments

Comments

@yurivish
Copy link

yurivish commented Jan 24, 2021

I noticed that the mean! function does not properly consider that its arguments may alias each other. In some such cases the result from mean! is not correct:

julia> let a = [1 2 3]
           mean!(a, a)
       end
1×3 Array{Int64,2}:
 0  0  0

julia> let a = [1 2 3]
           mean!(copy(a), a)
       end
1×3 Array{Int64,2}:
 1  2  3

julia> versioninfo()
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
@josemanuel22
Copy link
Contributor

josemanuel22 commented Nov 1, 2021

Viewing the definition of mean!. The result of the operation mean!(r, v) is written in r. Therefore it seems logical to me that if you use the same object as variable r and as variable v, the result is unpredictable.

I have seen that this also happens with the sum! function.

https://stackoverflow.com/questions/69963082/mean-may-return-incorrect-results

@nalimilan
Copy link
Member

Could you file the equivalent PR for sum against Julia Base? Then once a decision is made there we can apply the same change here. See JuliaLang/julia#39385.

@andreasnoack
Copy link
Member

Closed by #96

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

4 participants