Skip to content

Commit

Permalink
Restructure the package to only define FFTW on 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jul 17, 2017
1 parent 48923f4 commit 26d9c76
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 66 deletions.
64 changes: 3 additions & 61 deletions src/FFTW.jl
Original file line number Diff line number Diff line change
@@ -1,63 +1,5 @@
__precompile__()

module FFTW

# Since nothing is exported from AbstractFFTs as long as the FFT functionality is
# defined (or deprecated) in Base, we need to be very explicit about the things we
# want to import
import AbstractFFTs: Plan, ScaledPlan,
fft, ifft, bfft, fft!, ifft!, bfft!,
plan_fft, plan_ifft, plan_bfft, plan_fft!, plan_ifft!, plan_bfft!,
rfft, irfft, brfft, plan_rfft, plan_irfft, plan_brfft,
fftshift, ifftshift,
rfft_output_size, brfft_output_size,
plan_inv, normalization

if VERSION >= v"0.7.0-DEV.602"
if isdefined(Base, :FFTW)
import Base.FFTW: dct, idct, dct!, idct!, plan_dct, plan_idct, plan_dct!, plan_idct!
else
export dct, idct, dct!, idct!, plan_dct, plan_idct, plan_dct!, plan_idct!
end
end

const depsfile = joinpath(dirname(@__DIR__), "deps", "deps.jl")
if isfile(depsfile)
include(depsfile)
else
error("FFTW is not properly installed. Please run Pkg.build(\"FFTW\") ",
"and restart Julia.")
end

# MKL provides its own FFTW
fftw_vendor() = Base.BLAS.vendor() === :mkl ? :mkl : :fftw

if fftw_vendor() === :mkl
const libfftw_name = "libmkl_rt"
const libfftwf_name = "libmkl_rt"
elseif is_windows()
const libfftw_name = "libfftw3"
const libfftwf_name = "libfftw3f"
if VERSION < v"0.7.0-DEV.602"
import Base.FFTW
else
const libfftw_name = "libfftw3_threads"
const libfftwf_name = "libfftw3f_threads"
end

# Threads must be initialized before any FFTW planning routine.
# -- This initializes FFTW's threads support (defaulting to 1 thread).
# If this isn't called before the FFTW planner is created, then
# FFTW's threads algorithms won't be registered or used at all.
# (Previously, we called fftw_cleanup, but this invalidated existing
# plans, causing Base Julia issue #19892.)
function __init__()
stat = ccall((:fftw_init_threads, libfftw), Int32, ())
statf = ccall((:fftwf_init_threads, libfftwf), Int32, ())
if stat == 0 || statf == 0
error("could not initialize FFTW threads")
end
include("package.jl") # defines module FFTW
end

include("fft.jl")
include("dct.jl")

end # module
61 changes: 61 additions & 0 deletions src/package.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
__precompile__()

module FFTW

# Since nothing is exported from AbstractFFTs as long as the FFT functionality is
# defined (or deprecated) in Base, we need to be very explicit about the things we
# want to import
import AbstractFFTs: Plan, ScaledPlan,
fft, ifft, bfft, fft!, ifft!, bfft!,
plan_fft, plan_ifft, plan_bfft, plan_fft!, plan_ifft!, plan_bfft!,
rfft, irfft, brfft, plan_rfft, plan_irfft, plan_brfft,
fftshift, ifftshift,
rfft_output_size, brfft_output_size,
plan_inv, normalization

if isdefined(Base, :FFTW)
import Base.FFTW: dct, idct, dct!, idct!, plan_dct, plan_idct, plan_dct!, plan_idct!
else
export dct, idct, dct!, idct!, plan_dct, plan_idct, plan_dct!, plan_idct!
end

const depsfile = joinpath(dirname(@__DIR__), "deps", "deps.jl")
if isfile(depsfile)
include(depsfile)
else
error("FFTW is not properly installed. Please run Pkg.build(\"FFTW\") ",
"and restart Julia.")
end

# MKL provides its own FFTW
fftw_vendor() = Base.BLAS.vendor() === :mkl ? :mkl : :fftw

if fftw_vendor() === :mkl
const libfftw_name = "libmkl_rt"
const libfftwf_name = "libmkl_rt"
elseif is_windows()
const libfftw_name = "libfftw3"
const libfftwf_name = "libfftw3f"
else
const libfftw_name = "libfftw3_threads"
const libfftwf_name = "libfftw3f_threads"
end

# Threads must be initialized before any FFTW planning routine.
# -- This initializes FFTW's threads support (defaulting to 1 thread).
# If this isn't called before the FFTW planner is created, then
# FFTW's threads algorithms won't be registered or used at all.
# (Previously, we called fftw_cleanup, but this invalidated existing
# plans, causing Base Julia issue #19892.)
function __init__()
stat = ccall((:fftw_init_threads, libfftw), Int32, ())
statf = ccall((:fftwf_init_threads, libfftwf), Int32, ())
if stat == 0 || statf == 0
error("could not initialize FFTW threads")
end
end

include("fft.jl")
include("dct.jl")

end # module
18 changes: 13 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
using FFTW
using Base.Test

# Make super sure we don't pull in Base names
importall FFTW
import AbstractFFTs: Plan, fft, ifft, bfft, fft!, ifft!, bfft!,
if VERSION >= v"0.7.0-DEV.602"
import AbstractFFTs: Plan, fft, ifft, bfft, fft!, ifft!, bfft!,
plan_fft, plan_ifft, plan_bfft, plan_fft!, plan_ifft!, plan_bfft!,
rfft, irfft, brfft, plan_rfft, plan_irfft, plan_brfft,
fftshift, ifftshift, plan_inv
import FFTW: fftw_vendor
else
import Base.DFT: Plan, fft, ifft, bfft, fft!, ifft!, bfft!,
plan_fft, plan_ifft, plan_bfft, plan_fft!, plan_ifft!, plan_bfft!,
rfft, irfft, brfft, plan_rfft, plan_irfft, plan_brfft,
fftshift, ifftshift, plan_inv
import Base: fftw_vendor
end
import FFTW: dct, idct, dct!, idct!, plan_dct, plan_idct, plan_dct!, plan_idct!

# Base Julia issue #19892
Expand Down Expand Up @@ -149,7 +157,7 @@ for (f,fi,pf,pfi) in ((fft,ifft,plan_fft,plan_ifft),

# The following capabilities are FFTW only.
# They are not available in MKL, and hence do not test them.
if FFTW.fftw_vendor() != :mkl
if fftw_vendor() != :mkl
ifft3_fft3_m3d = fi(f(m3d))

fftd3_m3d = f(m3d,3)
Expand Down Expand Up @@ -232,7 +240,7 @@ for (f,fi,pf,pfi) in ((fft,ifft,plan_fft,plan_ifft),
@test pirfftn_rfftn_m4[i] m4[i]
end

if FFTW.fftw_vendor() != :mkl
if fftw_vendor() != :mkl
rfftn_m3d = rfft(m3d)
rfftd3_m3d = rfft(m3d,3)
@test size(rfftd3_m3d) == size(fftd3_m3d)
Expand Down Expand Up @@ -363,7 +371,7 @@ a16 = convert(Vector{Float16}, a)

# Discrete cosine transform (DCT) tests

if FFTW.fftw_vendor() != :mkl
if fftw_vendor() != :mkl
a = rand(8,11) + im*rand(8,11)
@test norm(idct(dct(a)) - a) < 1e-8

Expand Down

0 comments on commit 26d9c76

Please sign in to comment.