Skip to content

Commit 9a4642d

Browse files
committed
Switch to FFTA
This change adds support for more element types and drops a binary GPL dependency. For small problems, there is a minor slowdown, but it goes away for slightly larger problems where the processing between the ffts start dominating.
1 parent 335fcea commit 9a4642d

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

Project.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
name = "KernelDensity"
22
uuid = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
3-
authors = ["Simon Byrne and various contributors"]
43
version = "0.6.10"
4+
authors = ["Simon Byrne and various contributors"]
55

66
[deps]
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
88
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
9-
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
9+
FFTA = "b86e33f2-c0db-4aa1-a6e0-ab43e668529e"
1010
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
1111
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1212

13+
[sources]
14+
FFTA = {rev = "an/rfftas2cfft", url = "https://github.com/JuliaMath/FFTA.jl.git"}
15+
1316
[compat]
1417
Distributions = "0.23, 0.24, 0.25"
1518
DocStringExtensions = "0.8, 0.9"
16-
FFTW = "1"
19+
FFTA = "0.3"
1720
Interpolations = "0.9, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16"
1821
StatsBase = "0.33, 0.34"
1922
julia = "1"

src/KernelDensity.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using Distributions
66
using Interpolations
77

88
import Distributions: twoπ, pdf
9-
import FFTW: rfft, irfft
9+
import FFTA: rfft, irfft
1010

1111
export kde, kde_lscv, UnivariateKDE, BivariateKDE, InterpKDE, pdf
1212

src/bivariate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ end
7979
function conv(k::BivariateKDE, dist::Tuple{UnivariateDistribution,UnivariateDistribution})
8080
# Transform to Fourier basis
8181
Kx, Ky = size(k.density)
82-
ft = rfft(k.density)
82+
ft::Matrix{Complex{Float64}} = rfft(k.density)
8383

8484
distx, disty = dist
8585

src/univariate.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ end
123123
function conv(k::UnivariateKDE, dist::UnivariateDistribution)
124124
# Transform to Fourier basis
125125
K = length(k.density)
126-
ft = rfft(k.density)
126+
ft::Vector{Complex{Float64}} = rfft(k.density)
127127

128128
# Convolve fft with characteristic function of kernel
129129
# empirical cf
@@ -152,7 +152,7 @@ end
152152
153153
kde(data; kwargs...)
154154
kde((xdata, ydata); kwargs...)
155-
155+
156156
Kernel density estimation method. Returns 1D or 2D KDE object. The grid used and the values of the estimated density can be obtained from fields `.x` and `.density` respectively. To obtain kde values at points different than the initial grid use the `pdf` method.
157157
158158
The keyword arguments are

test/bivariate.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using KernelDensity
44

55
import KernelDensity: kernel_dist, default_bandwidth, kde_boundary, kde_range, tabulate
66

7-
for D in [Tuple{Normal,Normal}, Tuple{Uniform,Uniform}, Tuple{Logistic,Logistic},
7+
@testset "kernel_dist: D=$D" for D in [Tuple{Normal,Normal}, Tuple{Uniform,Uniform}, Tuple{Logistic,Logistic},
88
(Normal, Normal), (Uniform, Uniform), (Logistic, Logistic)]
99
d = KernelDensity.kernel_dist(D,(0.5,0.5))
1010
dx,dy = d
@@ -17,7 +17,7 @@ end
1717
r = kde_range((-2.0,2.0), 128)
1818
@test step(r) > 0
1919

20-
for X in ([0.0], [0.0,0.0], [0.0,0.5], [-0.5:0.1:0.5;])
20+
@testset "X=$X" for X in ([0.0], [0.0,0.0], [0.0,0.5], [-0.5:0.1:0.5;])
2121
w = default_bandwidth(X)
2222
@test w > 0
2323
lo, hi = kde_boundary(X,w)
@@ -62,8 +62,10 @@ for X in ([0.0], [0.0,0.0], [0.0,0.5], [-0.5:0.1:0.5;])
6262
end
6363

6464
k11 = kde([0.0 0.0; 1.0 1.0], (r,r), bandwidth=(1,1), weights=[0,1])
65-
k12 = kde([1.0 1.0], (r,r), bandwidth=(1,1))
66-
@test k11.density k12.density
65+
@testset "weight argument" begin
66+
k12 = kde([1.0 1.0], (r,r), bandwidth=(1,1))
67+
@test k11.density k12.density
68+
end
6769

6870
@testset "broadcasting. Issue 63" begin
6971
xyvals = [0.0, 1.0]

test/runtests.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
using Test
2+
13
tests = [
24
"univariate",
35
"bivariate",
46
"interp",
57
]
68

7-
println("Running tests:")
8-
9-
for t in tests
9+
@testset "$t" for t in tests
1010
test_fn = "$t.jl"
11-
println(" * $test_fn")
1211
include(test_fn)
1312
end

0 commit comments

Comments
 (0)