Skip to content

Commit

Permalink
Merge pull request #29 from JuliaSIMD/check-empty
Browse files Browse the repository at this point in the history
`@turbo check_empty=true` in most all cases
  • Loading branch information
brenhinkeller committed May 13, 2023
2 parents 3f20444 + a8817aa commit 6d8fc6d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "VectorizedStatistics"
uuid = "3b853605-1c98-4422-8364-4bd93ee0529e"
authors = ["C. Brenhin Keller", "Chris Elrod"]
version = "0.5.4"
version = "0.5.5"

[deps]
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
Expand Down
2 changes: 1 addition & 1 deletion src/argsort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
function sortnans!(I::AbstractArray, A::AbstractArray, iₗ::Int=firstindex(A), iᵤ::Int=lastindex(A))
# Count up NaNs
Nₙₐₙ = 0
@turbo for i = iₗ:iᵤ
@turbo check_empty=true for i = iₗ:iᵤ
Nₙₐₙ += A[i] != A[i]
end
# If none, return early
Expand Down
16 changes: 11 additions & 5 deletions src/quicksort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end
function sortnans!(A::AbstractArray, iₗ::Int=firstindex(A), iᵤ::Int=lastindex(A))
# Count up NaNs
Nₙₐₙ = 0
@turbo for i = iₗ:iᵤ
@turbo check_empty=true for i = iₗ:iᵤ
Nₙₐₙ += A[i] != A[i]
end
# If none, return early
Expand Down Expand Up @@ -80,7 +80,7 @@ function quickselect!(A::AbstractArray, iₗ::Int=firstindex(A), iᵤ::Int=lasti

# Count up elements that must be moved to upper partition
Nᵤ = 0
@turbo for i = (iₗ+1):iᵤ
@turbo check_empty=true for i = (iₗ+1):iᵤ
Nᵤ += A[i] >= pivot
end
Nₗ = N - Nᵤ
Expand All @@ -103,9 +103,15 @@ function quickselect!(A::AbstractArray, iₗ::Int=firstindex(A), iᵤ::Int=lasti
iₚ = iₗ + Nₗ - 1
A[iₗ], A[iₚ] = A[iₚ], A[iₗ]
# Recurse: select from partition containing k
(iₗ <= k < iₚ) && quickselect!(A, iₗ, iₚ, k)
(iₚ < k <= iᵤ) && quickselect!(A, iₚ+1, iᵤ, k)
return A[k]
if iₚ==k
return A[k]
elseif k < iₚ
Nₗ == 2 && return A[iₗ]
quickselect!(A, iₗ, iₚ, k)
else
Nᵤ == 2 && return A[iᵤ]
quickselect!(A, iₚ+1, iᵤ, k)
end
end


Expand Down
4 changes: 2 additions & 2 deletions src/vcov.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function _vcov(x::AbstractVector, y::AbstractVector, corrected::Bool, μᵪ::Number, μᵧ::Number, multithreaded::False)
# Calculate covariance
σᵪᵧ = zero(promote_type(typeof(μᵪ), typeof(μᵧ), Int))
@turbo for i indices((x,y))
@turbo check_empty=true for i indices((x,y))
δᵪ = x[i] - μᵪ
δᵧ = y[i] - μᵧ
σᵪᵧ += δᵪ * δᵧ
Expand All @@ -13,7 +13,7 @@ end
function _vcov(x::AbstractVector, y::AbstractVector, corrected::Bool, μᵪ::Number, μᵧ::Number, multithreaded::True)
# Calculate covariance
σᵪᵧ = zero(promote_type(typeof(μᵪ), typeof(μᵧ), Int))
@tturbo for i indices((x,y))
@tturbo check_empty=true for i indices((x,y))
δᵪ = x[i] - μᵪ
δᵧ = y[i] - μᵧ
σᵪᵧ += δᵪ * δᵧ
Expand Down
4 changes: 2 additions & 2 deletions src/vmean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function _vmean(A, ::Colon, multithreaded::False)
# Promote type of accumulator to avoid overflow
Tₒ = Base.promote_op(/, eltype(A), Int)
Σ = zero(Tₒ)
@turbo for i eachindex(A)
@turbo check_empty=true for i eachindex(A)
Σ += A[i]
end
return Σ / length(A)
Expand Down Expand Up @@ -155,7 +155,7 @@ function _vmean(A, ::Colon, multithreaded::True)
# Promote type of accumulator to avoid overflow
Tₒ = Base.promote_op(/, eltype(A), Int)
Σ = zero(Tₒ)
@tturbo for i eachindex(A)
@tturbo check_empty=true for i eachindex(A)
Σ += A[i]
end
return Σ / length(A)
Expand Down
4 changes: 2 additions & 2 deletions src/vstd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ sqrt!(x, multithreaded::Symbol) = sqrt!(x, (multithreaded===:auto && length(x) >
sqrt!(x, multithreaded::Bool) = sqrt!(x, static(multithreaded))
sqrt!(x::Number, multithreaded::StaticBool) = sqrt(x)
function sqrt!(A::AbstractArray, multithreaded::False)
@turbo for i eachindex(A)
@turbo check_empty=true for i eachindex(A)
A[i] = sqrt(A[i])
end
return A
end
function sqrt!(A::AbstractArray, multithreaded::True)
@tturbo for i eachindex(A)
@tturbo check_empty=true for i eachindex(A)
A[i] = sqrt(A[i])
end
return A
Expand Down
4 changes: 2 additions & 2 deletions src/vsum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function _vsum(A, ::Colon, multithreaded::False)
# Promote type of accumulator to avoid overflow
Tₒ = Base.promote_op(+, eltype(A), Int)
Σ = zero(Tₒ)
@turbo for i eachindex(A)
@turbo check_empty=true for i eachindex(A)
Σ += A[i]
end
return Σ
Expand Down Expand Up @@ -149,7 +149,7 @@ function _vsum(A, ::Colon, multithreaded::True)
# Promote type of accumulator to avoid overflow
Tₒ = Base.promote_op(+, eltype(A), Int)
Σ = zero(Tₒ)
@tturbo for i eachindex(A)
@tturbo check_empty=true for i eachindex(A)
Σ += A[i]
end
return Σ
Expand Down
12 changes: 6 additions & 6 deletions src/vvar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function _vvar(μ::Number, corrected::Bool, A, ::Colon, multithreaded::False)
# Reduce all the dims!
n = length(A)
σ² = zero(typeof(μ))
@turbo for i eachindex(A)
@turbo check_empty=true for i eachindex(A)
δ = A[i] - μ
σ² += δ * δ
end
Expand All @@ -58,7 +58,7 @@ function _vvar(μ::Number, corrected::Bool, A, ::Colon, multithreaded::True)
# Reduce all the dims!
n = length(A)
σ² = zero(typeof(μ))
@tturbo for i eachindex(A)
@tturbo check_empty=true for i eachindex(A)
δ = A[i] - μ
σ² += δ * δ
end
Expand All @@ -72,12 +72,12 @@ function _vvar(::Nothing, corrected::Bool, A, ::Colon, multithreaded::False)
n = length(A)
Tₒ = Base.promote_op(/, eltype(A), Int)
Σ = zero(Tₒ)
@turbo for i eachindex(A)
@turbo check_empty=true for i eachindex(A)
Σ += A[i]
end
μ = Σ / n
σ² = zero(typeof(μ))
@turbo for i eachindex(A)
@turbo check_empty=true for i eachindex(A)
δ = A[i] - μ
σ² += δ * δ
end
Expand All @@ -88,12 +88,12 @@ function _vvar(::Nothing, corrected::Bool, A, ::Colon, multithreaded::True)
n = length(A)
Tₒ = Base.promote_op(/, eltype(A), Int)
Σ = zero(Tₒ)
@tturbo for i eachindex(A)
@tturbo check_empty=true for i eachindex(A)
Σ += A[i]
end
μ = Σ / n
σ² = zero(typeof(μ))
@tturbo for i eachindex(A)
@tturbo check_empty=true for i eachindex(A)
δ = A[i] - μ
σ² += δ * δ
end
Expand Down

2 comments on commit 6d8fc6d

@brenhinkeller
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/83524

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.5 -m "<description of version>" 6d8fc6ddaef82b365fe9709a85ccf1a46fd80108
git push origin v0.5.5

Please sign in to comment.