Skip to content

Commit 73cead9

Browse files
committed
Improve performance of unweighted ecdf
1 parent 92d1674 commit 73cead9

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StatsBase"
22
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
33
authors = ["JuliaStats"]
4-
version = "0.34.6"
4+
version = "0.34.7"
55

66
[deps]
77
AliasTables = "66dad0bd-aa9a-41b7-9441-69ab47430ed8"

src/empirical.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ function is inside the interval ``(0,1)``; the function is defined for the whole
5555
"""
5656
function ecdf(X::AbstractVector{<:Real}; weights::AbstractVector{<:Real}=Weights(Float64[]))
5757
any(isnan, X) && throw(ArgumentError("ecdf can not include NaN values"))
58-
isempty(weights) || length(X) == length(weights) || throw(ArgumentError("data and weight vectors must be the same size," *
59-
"got $(length(X)) and $(length(weights))"))
60-
ord = sortperm(X)
61-
ECDF(X[ord], isempty(weights) ? weights : Weights(weights[ord]))
58+
if isempty(weights)
59+
return ECDF(sort(X), weights)
60+
else
61+
length(X) == length(weights) || throw(ArgumentError("data and weight vectors must be the same size," *
62+
"got $(length(X)) and $(length(weights))"))
63+
ord = sortperm(X)
64+
ECDF(X[ord], weights[ord])
65+
end
6266
end
6367

6468
minimum(ecdf::ECDF) = first(ecdf.sorted_values)

0 commit comments

Comments
 (0)