Skip to content

Commit b740277

Browse files
dkarraschKristofferC
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 7284072 commit b740277

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
@@ -583,8 +583,8 @@ function corm(x::AbstractVector, mx, y::AbstractVector, my)
583583

584584
@inbounds begin
585585
# Initialize the accumulators
586-
xx = zero(sqrt(abs2(x[1])))
587-
yy = zero(sqrt(abs2(y[1])))
586+
xx = zero(sqrt(abs2(one(x[1]))))
587+
yy = zero(sqrt(abs2(one(y[1]))))
588588
xy = zero(x[1] * y[1]')
589589

590590
@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
@@ -420,6 +420,8 @@ end
420420
@test cor(repeat(1:17, 1, 17))[2] <= 1.0
421421
@test cor(1:17, 1:17) <= 1.0
422422
@test cor(1:17, 18:34) <= 1.0
423+
@test cor(Any[1, 2], Any[1, 2]) == 1.0
424+
@test isnan(cor([0], Int8[81]))
423425
let tmp = range(1, stop=85, length=100)
424426
tmp2 = Vector(tmp)
425427
@test cor(tmp, tmp) <= 1.0

0 commit comments

Comments
 (0)