Skip to content

Commit

Permalink
Fix up my garbage and add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jul 16, 2017
1 parent e724056 commit 5df2557
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/univariate/discrete/poissonbinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ end
if VERSION >= v"0.7.0-DEV.602"
function _dft(x::Vector{T}) where T
n = length(x)
y = fill!(copy(x), zero(complex(float(T))))
@inbounds for j = 0:n-1, i = 0:n-1
y = Vector{complex(float(T))}(n)
@inbounds for j = 0:n-1, k = 0:n-1
y[k+1] += x[j+1] * cis(-2π * j * k / n)
end
return y
Expand Down
15 changes: 15 additions & 0 deletions test/poissonbinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,18 @@ for (n₁, n₂, n₃, p₁, p₂, p₃) in [(10, 10, 10, 0.1, 0.5, 0.9),
@test isapprox(pdf(d, k), m, atol=1e-15)
end
end

# Test the _dft helper function
@testset "_dft" begin
x = Distributions._dft(collect(1:8))
# Comparator computed from FFTW
fftw_fft = [36.0 + 0.0im,
-4.0 + 9.65685424949238im,
-4.0 + 4.0im,
-4.0 + 1.6568542494923806im,
-4.0 + 0.0im,
-4.0 - 1.6568542494923806im,
-4.0 - 4.0im,
-4.0 - 9.65685424949238im]
@test x fftw_fft
end

0 comments on commit 5df2557

Please sign in to comment.