Skip to content

Commit

Permalink
Add VectorizedStatistics dependency, faster sorting in linterp1s! w…
Browse files Browse the repository at this point in the history
…ith one less buffer required
  • Loading branch information
brenhinkeller committed Nov 15, 2022
1 parent 626b878 commit 597eb2f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StatGeochemBase"
uuid = "61e559cd-58b4-4257-8528-26bb26ff2b9a"
authors = ["C. Brenhin Keller"]
version = "0.4.2"
version = "0.4.3"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand All @@ -10,6 +10,7 @@ LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
NaNStatistics = "b946abbf-3ea7-4610-9019-9858bfdeaf2d"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
VectorizationBase = "3d5dd08c-fd9d-11e8-17fa-ed2836048c2f"
VectorizedStatistics = "3b853605-1c98-4422-8364-4bd93ee0529e"

[compat]
Colors = "0.10 - 0.12"
Expand All @@ -18,6 +19,7 @@ LoopVectorization = "0.11, 0.12"
NaNStatistics = "0.3, 0.4, 0.5, 0.6"
SpecialFunctions = "0.5 - 0.10, 1, 2"
VectorizationBase = "0.18, 0.19, 0.20, 0.21"
VectorizedStatistics = "0.4.4"
julia = "1.6"

[extras]
Expand Down
4 changes: 2 additions & 2 deletions src/Geochronology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@
# terms that don't depend on a or b
α = sqrt.(ωx .* ωy)

= _vmean(x, :)
= _vmean(y, :)
= vmean(x)
= vmean(y)
r = sum((x .- x̄).*(y .- ȳ)) ./ (sqrt(sum((x .- x̄).^2)) * sqrt(sum((y .- ȳ).^2)))

## 3. Perform the York fit (must iterate)
Expand Down
26 changes: 16 additions & 10 deletions src/Interpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,24 @@

"""
```julia
linterp1s!(yq::DenseArray, x::AbstractArray, y::AbstractArray, xq; extrapolate=:Linear, sort_index=ones(Int, length(x)), knot_index=ones(Int, length(xq)))
linterp1s!(yq::AbstractArray, x::AbstractArray, y::AbstractArray, xq; extrapolate=:Linear)
linterp1s!(yq::AbstractArray, knot_index::AbstractArray{Int}, x::AbstractArray, y::AbstractArray, xq::AbstractArray; extrapolate=:Linear)
```
In-place variant of `linterp1s`. Will sort `x` and permute `y` to match.
In-place variant of `linterp1s`.
Will sort `x` and permute `y` to match, before interpolating at `xq` and storing the result in `yq`.
An optional temporary working array `knot_index = similar(xq, Int)` may be provided to fully eliminate allocations.
"""
function linterp1s!(yq::AbstractArray, x::AbstractArray, y::AbstractArray, xq; extrapolate=:Linear, sort_index::AbstractVector{Int}=ones(Int, length(x)), knot_index::AbstractVector{Int}=ones(Int, length(xq)))
@assert eachindex(sort_index) === eachindex(x) === eachindex(y)
@assert eachindex(knot_index) === eachindex(xq)
if !issorted(x)
sortperm!(sort_index, x) # indices to construct sorted array
permute!(x, sort_index)
permute!(y, sort_index)
end
function linterp1s!(yq::AbstractArray, x::AbstractArray, y::AbstractArray, xq; extrapolate=:Linear)
@assert eachindex(xq) === eachindex(yq)
@assert eachindex(x) === eachindex(y)
vsort!(y, x) # Sort x and permute y to match
return _linterp1!(yq, x, y, xq, extrapolate)
end
function linterp1s!(yq::AbstractArray, knot_index::AbstractArray{Int}, x::AbstractArray, y::AbstractArray, xq::AbstractArray; extrapolate=:Linear)
@assert eachindex(knot_index) === eachindex(xq) === eachindex(yq)
@assert eachindex(x) === eachindex(y)
vsort!(y, x) # Sort x and permute y to match
return _linterp1!(yq, knot_index, x, y, xq, extrapolate)
end
export linterp1s!
Expand Down
10 changes: 0 additions & 10 deletions src/Math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@
end
export fast_inv_sqrt

## --- Fast vectorized mean

function _vmean(A::DenseArray{T}, ::Colon) where {T<:Number}
m = zero(T)
@turbo for i eachindex(A)
m += A[i]
end
return m / length(A)
end


## --- Base-10 version of log1p
#
Expand Down
1 change: 1 addition & 0 deletions src/StatGeochemBase.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module StatGeochemBase

using NaNStatistics
using VectorizedStatistics

# AVX vectorziation tools
using LoopVectorization
Expand Down
2 changes: 1 addition & 1 deletion test/testInterpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@test linterp1s!(similar(xq), 1:10, 21:30, xq) == [25.0, 25.5, 26.0]
@test linterp1s!(similar(xq), collect(10:-1:1), collect(21:30), xq) == [26.0, 25.5, 25.0]
xq = 5:0.5:7
@test linterp1s!(similar(xq), collect(10:-1:1), collect(21:30), xq; knot_index=ones(Int,5), sort_index=ones(Int,10)) == [26.0, 25.5, 25.0, 24.5, 24]
@test linterp1s!(similar(xq), rand(Int,length(xq)), collect(10:-1:1), collect(21:30), xq) == [26.0, 25.5, 25.0, 24.5, 24]
xq = 0:0.01:1
x = rand(200)
y = rand(200)
Expand Down

2 comments on commit 597eb2f

@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:

  • Add VectorizedStatistics dependency, faster sorting in linterp1s! with one less buffer required

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

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.4.3 -m "<description of version>" 597eb2ff8845599dd83137bcf2c81014e7e4effd
git push origin v0.4.3

Please sign in to comment.