Skip to content

Commit

Permalink
Switch from avx to turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Jun 20, 2021
1 parent 7322144 commit b61f718
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
16 changes: 8 additions & 8 deletions src/ArrayStats/ArrayStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Fill a Boolean mask of dimensions `size(A)` that is false wherever `A` is `NaN`
"""
function nanmask!(mask, A)
@avx for i=1:length(A)
@turbo for i=1:length(A)
mask[i] = A[i]==A[i]
end
return mask
Expand All @@ -42,7 +42,7 @@
Replace all `NaN`s in A with zeros of the same type
"""
function zeronan!(A::Array)
@avx for i eachindex(A)
@turbo for i eachindex(A)
Aᵢ = A[i]
A[i] = ifelse(Aᵢ==Aᵢ, Aᵢ, 0)
end
Expand Down Expand Up @@ -287,7 +287,7 @@
function _nanmean(A::Array{<:Integer}, W, ::Colon)
n = zero(eltype(W))
m = zero(promote_type(eltype(W), eltype(A)))
@avx for i eachindex(A)
@turbo for i eachindex(A)
Wᵢ = W[i]
n += Wᵢ
m += Wᵢ * A[i]
Expand All @@ -300,7 +300,7 @@
T2 = promote_type(eltype(W), eltype(A))
n = zero(T1)
m = zero(T2)
@avx for i eachindex(A)
@turbo for i eachindex(A)
Aᵢ = A[i]
Wᵢ = W[i]
t = Aᵢ==Aᵢ
Expand Down Expand Up @@ -333,12 +333,12 @@
w = sum(W.*mask, dims=region)
s = sum(A.*W.*mask, dims=region) ./ w
d = A .- s # Subtract mean, using broadcasting
@avx for i eachindex(d)
@turbo for i eachindex(d)
dᵢ = d[i]
d[i] = (dᵢ * dᵢ * W[i]) * mask[i]
end
s .= sum(d, dims=region)
@avx for i eachindex(s)
@turbo for i eachindex(s)
s[i] = sqrt((s[i] * n[i]) / (w[i] * (n[i] - 1)))
end
return s
Expand Down Expand Up @@ -370,7 +370,7 @@
Tm = promote_type(eltype(W), eltype(A))
w = zero(Tw)
m = zero(Tm)
@avx for i eachindex(A)
@turbo for i eachindex(A)
Aᵢ = A[i]
Wᵢ = W[i]
t = Aᵢ==Aᵢ
Expand All @@ -381,7 +381,7 @@
mu = m / w
Tmu = typeof(mu)
s = zero(Tmu)
@avx for i eachindex(A)
@turbo for i eachindex(A)
Aᵢ = A[i]
d = Aᵢ - mu
s += ifelse(Aᵢ==Aᵢ, d * d * W[i], zero(Tmu))
Expand Down
2 changes: 1 addition & 1 deletion src/ArrayStats/nancov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function _nancov(x::AbstractVector, y::AbstractVector, corrected::Bool, μᵪ::N
# Calculate covariance
σᵪᵧ == zero(promote_type(typeof(μᵪ), typeof(μᵧ), Int))
n = 0
@avx for i indices((x,y))
@turbo for i indices((x,y))
δᵪ = x[i] - μᵪ
δᵧ = y[i] - μᵧ
δ² = δᵪ * δᵧ
Expand Down
6 changes: 3 additions & 3 deletions src/ArrayStats/nanmean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function _nanmean(A, ::Colon)
Tₒ = Base.promote_op(/, eltype(A), Int)
n = 0
Σ == zero(Tₒ)
@avx for i eachindex(A)
@turbo for i eachindex(A)
Aᵢ = A[i]
notnan = Aᵢ==Aᵢ
n += notnan
Expand All @@ -65,7 +65,7 @@ end
function _nanmean(A::AbstractArray{<:Integer}, ::Colon)
Tₒ = Base.promote_op(/, eltype(A), Int)
Σ = zero(Tₒ)
@avx for i eachindex(A)
@turbo for i eachindex(A)
Σ += A[i]
end
return Σ / length(A)
Expand Down Expand Up @@ -130,7 +130,7 @@ function staticdim_nanmean_quote(static_dims::Vector{Int}, N::Int)
quote
= zero(eltype(B))
Bᵥ = $Bᵥ
@avx $loops
@turbo $loops
return B
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/ArrayStats/nanstd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export nanstd

sqrt!(x::Number) = sqrt(x)
function sqrt!(A::AbstractArray)
@avx for i eachindex(A)
@turbo for i eachindex(A)
A[i] = sqrt(A[i])
end
return A
Expand Down
6 changes: 3 additions & 3 deletions src/ArrayStats/nansum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ end
function _nansum(A, ::Colon)
Tₒ = Base.promote_op(+, eltype(A), Int)
Σ == zero(Tₒ)
@avx for i eachindex(A)
@turbo for i eachindex(A)
Aᵢ = A[i]
notnan = Aᵢ==Aᵢ
Σ += ifelse(notnan, A[i], ∅)
Expand All @@ -63,7 +63,7 @@ end
function _nansum(A::AbstractArray{<:Integer}, ::Colon)
Tₒ = Base.promote_op(+, eltype(A), Int)
Σ = zero(Tₒ)
@avx for i eachindex(A)
@turbo for i eachindex(A)
Σ += A[i]
end
return Σ
Expand Down Expand Up @@ -126,7 +126,7 @@ function staticdim_nansum_quote(static_dims::Vector{Int}, N::Int)
quote
= zero(eltype(B))
Bᵥ = $Bᵥ
@avx $loops
@turbo $loops
return B
end
end
Expand Down
18 changes: 9 additions & 9 deletions src/ArrayStats/nanvar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ function _nanvar(::Nothing, corrected::Bool, A, ::Colon)
Tₒ = Base.promote_op(/, eltype(A), Int)
n = 0
Σ == zero(Tₒ)
@avx for i eachindex(A)
@turbo for i eachindex(A)
Aᵢ = A[i]
notnan = Aᵢ==Aᵢ
n += notnan
Σ += ifelse(notnan, Aᵢ, ∅)
end
μ = Σ / n
σ² == zero(typeof(μ))
@avx for i eachindex(A)
@turbo for i eachindex(A)
δ = A[i] - μ
notnan = δ==δ
σ² += ifelse(notnan, δ * δ, ∅)
Expand All @@ -69,12 +69,12 @@ function _nanvar(::Nothing, corrected::Bool, A::AbstractArray{<:Integer}, ::Colo
Tₒ = Base.promote_op(/, eltype(A), Int)
n = length(A)
Σ = zero(Tₒ)
@avx for i eachindex(A)
@turbo for i eachindex(A)
Σ += A[i]
end
μ = Σ / n
σ² = zero(typeof(μ))
@avx for i eachindex(A)
@turbo for i eachindex(A)
δ = A[i] - μ
σ² += δ * δ
end
Expand All @@ -89,7 +89,7 @@ function _nanvar(μ::Number, corrected::Bool, A, ::Colon)
# Reduce all the dims!
n = 0
σ² == zero(typeof(μ))
@avx for i eachindex(A)
@turbo for i eachindex(A)
δ = A[i] - μ
notnan = δ==δ
n += notnan
Expand All @@ -101,7 +101,7 @@ function _nanvar(μ::Number, corrected::Bool, A::AbstractArray{<:Integer}, ::Col
# Reduce all the dims!
σ² = zero(typeof(μ))
if μ==μ
@avx for i eachindex(A)
@turbo for i eachindex(A)
δ = A[i] - μ
σ² += δ * δ
end
Expand All @@ -118,12 +118,12 @@ end
# N = sum(mask, dims=region)
# Σ = sum(A.*mask, dims=region)./N
# δ = A .- Σ # Subtract mean, using broadcasting
# @avx for i ∈ eachindex(δ)
# @turbo for i ∈ eachindex(δ)
# δᵢ = δ[i]
# δ[i] = ifelse(mask[i], δᵢ * δᵢ, 0)
# end
# B .= sum(δ, dims=region)
# @avx for i ∈ eachindex(B)
# @turbo for i ∈ eachindex(B)
# B[i] = B[i] / max(N[i] - corrected, 0)
# end
# return B
Expand Down Expand Up @@ -190,7 +190,7 @@ function staticdim_nanvar_quote(static_dims::Vector{Int}, N::Int)
quote
= zero(eltype(B))
Bᵥ = $Bᵥ
@avx $loops
@turbo $loops
return B
end
end
Expand Down

2 comments on commit b61f718

@brenhinkeller
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes

  • Require LoopVectorization >= 0.12.42
  • LoopVectorization.@avx -> LoopVectorization.@turbo
  • Minor bugfixes to nansum

@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/39280

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.3 -m "<description of version>" b61f7184b2ae44ee566e6efe6ebd1d86d67e9805
git push origin v0.5.3

Please sign in to comment.