Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ end

# corzm (non-exported, with centered data)

corzm(x::AbstractVector{T}) where {T} = one(real(T))
corzm(x::AbstractVector{T}) where {T} = one(float(T))
function corzm(x::AbstractMatrix, vardim::Int=1)
c = unscaled_covzm(x, vardim)
return cov2cor!(c, collect(sqrt(c[i,i]) for i in 1:min(size(c)...)))
Expand All @@ -671,7 +671,7 @@ corzm(x::AbstractMatrix, y::AbstractMatrix, vardim::Int=1) =

# corm

corm(x::AbstractVector{T}, xmean) where {T} = one(real(T))
corm(x::AbstractVector{T}, xmean) where {T} = one(float(T))
corm(x::AbstractMatrix, xmean, vardim::Int=1) = corzm(x .- xmean, vardim)
function corm(x::AbstractVector, mx, y::AbstractVector, my)
require_one_based_indexing(x, y)
Expand Down Expand Up @@ -705,7 +705,7 @@ corm(x::AbstractVecOrMat, xmean, y::AbstractVecOrMat, ymean, vardim::Int=1) =

Return the number one.
"""
cor(x::AbstractVector) = one(real(eltype(x)))
cor(x::AbstractVector) = one(float(eltype(x)))

"""
cor(X::AbstractMatrix; dims::Int=1)
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,20 @@ end
@test cor(tmp, tmp) <= 1.0
@test cor(tmp, tmp2) <= 1.0
end

@test cor(Int[]) === 1.0
@test cor([im]) === 1.0 + 0.0im
@test_throws MethodError cor([])
@test_throws MethodError cor(Any[1.0])

@test cor([1, missing]) === 1.0
@test ismissing(cor([missing]))
@test_throws MethodError cor(Any[1.0, missing])

@test Statistics.corm([true], 1.0) === 1.0
@test_throws MethodError Statistics.corm(Any[0.0, 1.0], 0.5)
@test Statistics.corzm([true]) === 1.0
@test_throws MethodError Statistics.corzm(Any[0.0, 1.0])
end

@testset "quantile" begin
Expand Down