Skip to content

Commit

Permalink
Allow passing 0-length vectors to cor
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins committed Jan 23, 2021
1 parent 7b56a27 commit 146bde2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,14 @@ function corm(x::AbstractVector, mx, y::AbstractVector, my)
require_one_based_indexing(x, y)
n = length(x)
length(y) == n || throw(DimensionMismatch("inconsistent lengths"))
n > 0 || throw(ArgumentError("correlation only defined for non-empty vectors"))
if n == 0
T = promote_type(typeof(mx), typeof(my))
if T <: AbstractFloat
return T(NaN)
else
return NaN
end
end

@inbounds begin
# Initialize the accumulators
Expand Down

0 comments on commit 146bde2

Please sign in to comment.