Skip to content

Commit

Permalink
Merge pull request #21 from JuliaMath/aa/ugh-oh-my-god
Browse files Browse the repository at this point in the history
Wrap everything in a version check
  • Loading branch information
ararslan committed Jul 20, 2017
2 parents 48923f4 + feb7c5f commit 070cd89
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 91 deletions.
23 changes: 17 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
os:
- linux
- osx
julia:
- 0.6
- nightly
sudo: required
dist: trusty
matrix:
include:
- os: linux
julia: 0.6
- os: linux
julia: nightly
addons:
apt:
packages:
- libfftw3-double3
- libfftw3-single3
- os: osx
julia: 0.6
- os: osx
julia: nightly
notifications:
email: false
# uncomment the following lines to override the default test script
Expand Down
5 changes: 3 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
julia 0.6.0-rc1
AbstractFFTs
julia 0.6.0
AbstractFFTs 0.2.0
Compat 0.27.0
BinDeps 0.6.0
@osx Homebrew
@windows WinRPM
29 changes: 17 additions & 12 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Don't build and install FFTW if we're on a version of Julia that ships with it
# Using include_string gets around the UndefVarErrors that happen when parsing macros
VERSION >= v"0.7.0-DEV.602" && include_string("""
using BinDeps
using BinDeps: builddir
using Compat.Sys: iswindows, isapple
BinDeps.@setup
const FFTW_VER = v"3.3.6-pl1"
if is_windows()
if iswindows()
const libfftw_name = "libfftw3"
const libfftwf_name = "libfftw3f"
else
Expand Down Expand Up @@ -36,10 +40,10 @@ provides(Zypper, "libfftw3_threads3", [libfftw, libfftwf], os=:Linux)
provides(Yum, "fftw-libs", [libfftw, libfftwf], os=:Linux)
provides(BSDPkg, "fftw3", [libfftw, libfftwf], os=:FreeBSD)
if is_windows()
if iswindows()
using WinRPM
provides(WinRPM.RPM, "libfftw3-3", [libfftw, libfftwf], os=:Windows)
elseif is_apple()
elseif isapple()
using Homebrew
provides(Homebrew.HB, "fftw", [libfftw, libfftwf], os=:Darwin)
end
Expand All @@ -57,12 +61,12 @@ elseif Sys.ARCH === :x86_64
append!(fftw_config, ["--enable-sse2", "--enable-fma"])
end
if is_windows()
if iswindows()
append!(fftw_config, ["--with-our-malloc", "--with-combined-threads"])
Sys.ARCH === :x86_64 || push!(fftw_config, "--with-incoming-stack-boundary=2")
end
provides(Sources, URI("http://www.fftw.org/fftw-$FFTW_VER.tar.gz"), [libfftw, libfftwf])
provides(Sources, URI("http://www.fftw.org/fftw-\$FFTW_VER.tar.gz"), [libfftw, libfftwf])
provides(BuildProcess, (@build_steps begin
GetSources(libfftw)
Expand All @@ -71,20 +75,21 @@ provides(BuildProcess, (@build_steps begin
ChangeDirectory(builddir(libfftw))
FileRule(joinpath(libdir(libfftw), libfftw_name * "." * Libdl.dlext), @build_steps begin
CreateDirectory(libdir(libfftw))
`$(joinpath(srcdir(libfftw), "fftw-$FFTW_VER", "configure")) $general_config $fftw_config`
`$MAKE_CMD`
`$MAKE_CMD install`
`\$(joinpath(srcdir(libfftw), "fftw-\$FFTW_VER", "configure")) \$general_config \$fftw_config`
`\$MAKE_CMD`
`\$MAKE_CMD install`
end)
FileRule(joinpath(libdir(libfftw), libfftwf_name * "." * Libdl.dlext), @build_steps begin
`$(joinpath(srcdir(libfftw), "fftw-$FFTW_VER", "configure")) $general_config $fftw_config $fftw_enable_single`
`$MAKE_CMD`
`$MAKE_CMD install`
`\$(joinpath(srcdir(libfftw), "fftw-\$FFTW_VER", "configure")) \$general_config \$fftw_config \$fftw_enable_single`
`\$MAKE_CMD`
`\$MAKE_CMD install`
end)
end
end), [libfftw, libfftwf])
if is_windows()
if iswindows()
BinDeps.@install Dict([:libfftw3 => :libfftw, :libfftw3f => :libfftwf])
else
BinDeps.@install Dict([:libfftw3_threads => :libfftw, :libfftw3f_threads => :libfftwf])
end
""")
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
60 changes: 60 additions & 0 deletions src/package.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
__precompile__()

module FFTW

using Compat

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.986"
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 Compat.Sys.iswindows()
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
20 changes: 10 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# This file was formerly a part of Julia. License is MIT: https://julialang.org/license
using FFTW
using AbstractFFTs
using AbstractFFTs: Plan, plan_inv
using Base.Test

# Make super sure we don't pull in Base names
importall FFTW
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: dct, idct, dct!, idct!, plan_dct, plan_idct, plan_dct!, plan_idct!
if VERSION >= v"0.7.0-DEV.602"
using FFTW: fftw_vendor
else
using Base: fftw_vendor
end

# Base Julia issue #19892
# (test this first to make sure it happens before set_num_threads)
Expand Down Expand Up @@ -149,7 +149,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 +232,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 +363,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 070cd89

Please sign in to comment.