Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
10 changes: 8 additions & 2 deletions src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,15 @@ function quantile!(v::AbstractVector, p::Union{AbstractArray, Tuple{Vararg{Real}
end
return map(x->_quantile(v, x, alpha=alpha, beta=beta), p)
end
quantile!(arr::AbstractArray, p::Union{AbstractArray,Tuple{Vararg{Real}}};
sorted::Bool=false, alpha::Real=1.0, beta::Real=alpha) =
quantile!(vec(arr), p, sorted=sorted, alpha=alpha, beta=alpha)

quantile!(v::AbstractVector, p::Real; sorted::Bool=false, alpha::Real=1., beta::Real=alpha) =
quantile!(q::AbstractArray, arr::AbstractArray, p::Union{AbstractArray,Tuple{Vararg{Real}}};
sorted::Bool=false, alpha::Real=1.0, beta::Real=alpha) =
quantile!(q, vec(arr), p, sorted=sorted, alpha=alpha, beta=alpha)

quantile!(v::AbstractVector, p::Real; sorted::Bool=false, alpha::Real=1.0, beta::Real=alpha) =
_quantile(_quantilesort!(v, sorted, p, p), p, alpha=alpha, beta=beta)

# Function to perform partial sort of v for quantiles in given range
Expand Down Expand Up @@ -1073,7 +1080,6 @@ quantile(itr, p; sorted::Bool=false, alpha::Real=1.0, beta::Real=alpha) =
quantile(v::AbstractVector, p; sorted::Bool=false, alpha::Real=1.0, beta::Real=alpha) =
quantile!(sorted ? v : Base.copymutable(v), p; sorted=sorted, alpha=alpha, beta=beta)


##### SparseArrays optimizations #####

function cov(X::SparseMatrixCSC; dims::Int=1, corrected::Bool=true)
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ end
@test quantile(Any[1, 2, 3], Float16(0.5)) isa Float16
@test quantile(Any[1, Float16(2), 3], Float16(0.5)) isa Float16
@test quantile(Any[1, big(2), 3], Float16(0.5)) isa BigFloat
@test quantile(reshape(collect(1:100), (10, 10)), [0.00, 0.25, 0.50, 0.75, 1.00]) == [1.0, 25.75, 50.5, 75.25, 100.0]

# Need a large vector to actually check consequences of partial sorting
x = rand(50)
Expand Down Expand Up @@ -639,6 +640,11 @@ end
@test quantile!(y, x, [0.1, 0.5, 0.9]) === y
@test y ≈ [1.2, 2.0, 2.8]

x = reshape(collect(1:100), (10, 10))
y = zeros(5)
@test quantile!(y, x, [0.00, 0.25, 0.50, 0.75, 1.00]) === y
@test y ≈ [1.0, 25.75, 50.5, 75.25, 100.0]

#tests for quantile calculation with configurable alpha and beta parameters
v = [2, 3, 4, 6, 9, 2, 6, 2, 21, 17]

Expand Down