Skip to content

Commit 3c363bd

Browse files
committed
Microoptimization to use convolution type constants instead of symbols
This has a minute effect on the package image size, reducing the size 0.010MiB (-0.2%, relative to the previous commit).
1 parent 160d1c1 commit 3c363bd

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/conv.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ function plan_conv(f::AbstractArray{U,N}, K::AbstractArray{V,N}) where {N, U, V}
8181
return replan_conv!(plan, K)
8282
end
8383

84-
function conv(f, K, shape::Symbol)
85-
if shape === :full
86-
return conv(f, K, ConvShape.FULL)
87-
elseif shape === :same
88-
return conv(f, K, ConvShape.SAME)
89-
elseif shape === :valid
90-
return conv(f, K, ConvShape.VALID)
91-
else
92-
throw(ArgumentError("Invalid convolution shape, $shape"))
93-
end
94-
end
84+
#function conv(f, K, shape::Symbol)
85+
# if shape === :full
86+
# return conv(f, K, ConvShape.FULL)
87+
# elseif shape === :same
88+
# return conv(f, K, ConvShape.SAME)
89+
# elseif shape === :valid
90+
# return conv(f, K, ConvShape.VALID)
91+
# else
92+
# throw(ArgumentError("Invalid convolution shape, $shape"))
93+
# end
94+
#end
9595
conv(f, K) = conv(f, K, ConvShape.FULL)
9696

9797
function conv(f::AbstractArray{S,N}, K::AbstractArray{T,N}, shape::ConvShape.T) where {N, S, T}

src/kde.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ function estimate(::BasicKDE, binned::UnivariateKDE{T}, info::UnivariateKDEInfo)
484484
info.kernel = UnivariateKDE{eltype(xx)}(xx, kernel)
485485

486486
# convolve the data with the kernel to construct a density estimate
487-
= conv(f, kernel, :same)
487+
= conv(f, kernel, ConvShape.SAME)
488488
estim = UnivariateKDE{T}(x, f̂)
489489
return estim, info
490490
end
@@ -531,20 +531,20 @@ function estimate(method::LinearBoundaryKDE, binned::UnivariateKDE{T}, info::Uni
531531
= plan_conv(f, K)
532532

533533
Θ = fill!(similar(f, R), one(R))
534-
μ₀ = conv(Θ, K̂, :same)
534+
μ₀ = conv(Θ, K̂, ConvShape.SAME)
535535

536536
@simd for ii in KI
537537
@inbounds K[ii] *= kx[ii]
538538
end
539539
replan_conv!(K̂, K)
540-
μ₁ = conv(Θ, K̂, :same)
541-
f′ = conv(h, K̂, :same)
540+
μ₁ = conv(Θ, K̂, ConvShape.SAME)
541+
f′ = conv(h, K̂, ConvShape.SAME)
542542

543543
@simd for ii in KI
544544
@inbounds K[ii] *= kx[ii]
545545
end
546546
replan_conv!(K̂, K)
547-
μ₂ = conv(Θ, K̂, :same)
547+
μ₂ = conv(Θ, K̂, ConvShape.SAME)
548548

549549
# Function to force f̂ to be positive — see Eqn. 17 of Lewis (2019)
550550
# N.B. Mathematically f from basic KDE is strictly non-negative, but numerically we

test/conv.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,6 @@ end
108108
@test_throws DimensionMismatch conv!(zeros(10), f, plan)
109109

110110
# invalid shape symbol
111-
@test_throws ArgumentError conv(zeros(5), zeros(3), :invalid)
111+
# disabled because the symbol method is commented out in src/conv.jl
112+
#@test_throws ArgumentError conv(zeros(5), zeros(3), :invalid)
112113
end

0 commit comments

Comments
 (0)