Skip to content

Commit

Permalink
[Statistics] fix type determination in corm (#32271)
Browse files Browse the repository at this point in the history
* [Statistics] fix type determination in corm

* remove obsolete typeof

* use first element(s) for type initialization

* add test for inhomogeneous data and for overflow

* fix test with NaN

(cherry picked from commit a8a567e)
  • Loading branch information
dkarrasch authored and KristofferC committed Aug 26, 2019
1 parent 7284072 commit b740277
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stdlib/Statistics/src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ function corm(x::AbstractVector, mx, y::AbstractVector, my)

@inbounds begin
# Initialize the accumulators
xx = zero(sqrt(abs2(x[1])))
yy = zero(sqrt(abs2(y[1])))
xx = zero(sqrt(abs2(one(x[1]))))
yy = zero(sqrt(abs2(one(y[1]))))
xy = zero(x[1] * y[1]')

@simd for i in eachindex(x, y)
Expand Down
2 changes: 2 additions & 0 deletions stdlib/Statistics/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ end
@test cor(repeat(1:17, 1, 17))[2] <= 1.0
@test cor(1:17, 1:17) <= 1.0
@test cor(1:17, 18:34) <= 1.0
@test cor(Any[1, 2], Any[1, 2]) == 1.0
@test isnan(cor([0], Int8[81]))
let tmp = range(1, stop=85, length=100)
tmp2 = Vector(tmp)
@test cor(tmp, tmp) <= 1.0
Expand Down

0 comments on commit b740277

Please sign in to comment.