Skip to content

Commit f05906a

Browse files
dkarraschJeffBezanson
authored andcommitted
[Statistics] fix type determination in corm (#32271)
* [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)
1 parent c9dd565 commit f05906a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

stdlib/Statistics/src/Statistics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ function corm(x::AbstractVector, mx, y::AbstractVector, my)
620620

621621
@inbounds begin
622622
# Initialize the accumulators
623-
xx = zero(sqrt(abs2(x[1])))
624-
yy = zero(sqrt(abs2(y[1])))
623+
xx = zero(sqrt(abs2(one(x[1]))))
624+
yy = zero(sqrt(abs2(one(y[1]))))
625625
xy = zero(x[1] * y[1]')
626626

627627
@simd for i in eachindex(x, y)

stdlib/Statistics/test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ end
455455
@test cor(repeat(1:17, 1, 17))[2] <= 1.0
456456
@test cor(1:17, 1:17) <= 1.0
457457
@test cor(1:17, 18:34) <= 1.0
458+
@test cor(Any[1, 2], Any[1, 2]) == 1.0
459+
@test isnan(cor([0], Int8[81]))
458460
let tmp = range(1, stop=85, length=100)
459461
tmp2 = Vector(tmp)
460462
@test cor(tmp, tmp) <= 1.0

0 commit comments

Comments
 (0)