Skip to content

Commit

Permalink
Merge pull request #218 from yuyichao/0.4-dev
Browse files Browse the repository at this point in the history
Remove left over `::Function` for plans and support new DFT API
  • Loading branch information
dlfivefifty committed Jul 19, 2015
2 parents c81255b + 639e24a commit 736b330
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
18 changes: 16 additions & 2 deletions src/Extras/fftGeneric.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
typealias BigFloats Union(BigFloat,Complex{BigFloat})

if VERSION >= v"0.4-dev"
# old DFT API: p(x) # deprecated
wrap_fft_plan(x::Function) = x
# new DFT API
immutable FFTPlanWrapper{P}
p::P
end
call(p::FFTPlanWrapper, arg) = p.p * arg
wrap_fft_plan(x) = FFTPlanWrapper(x)
else
# 0.3 (old) DFT API
wrap_fft_plan(x) = x
end

# The following implements Bluestein's algorithm, following http://www.dsprelated.com/dspbooks/mdft/Bluestein_s_FFT_Algorithm.html
# To add more types, add them in the union of the function's signature.
function Base.fft{T<:BigFloats}(x::Vector{T})
Expand Down Expand Up @@ -46,7 +60,7 @@ plan_chebyshevtransform{T<:BigFloats}(x::Vector{T};kwds...) = identity
plan_ichebyshevtransform{T<:BigFloats}(x::Vector{T};kwds...) = identity

#following Chebfun's @Chebtech1/vals2coeffs.m and @Chebtech2/vals2coeffs.m
function chebyshevtransform{T<:BigFloats}(x::Vector{T},plan::Function;kind::Integer=1)
function chebyshevtransform{T<:BigFloats}(x::Vector{T},plan;kind::Integer=1)
if kind == 1
n = length(x)
if n == 1
Expand All @@ -72,7 +86,7 @@ function chebyshevtransform{T<:BigFloats}(x::Vector{T},plan::Function;kind::Inte
end

#following Chebfun's @Chebtech1/vals2coeffs.m and @Chebtech2/vals2coeffs.m
function ichebyshevtransform{T<:BigFloats}(x::Vector{T},plan::Function;kind::Integer=1)
function ichebyshevtransform{T<:BigFloats}(x::Vector{T},plan;kind::Integer=1)
if kind == 1
n = length(x)
if n == 1
Expand Down
12 changes: 6 additions & 6 deletions src/LinearAlgebra/chebyshevtransform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export plan_chebyshevtransform, plan_ichebyshevtransform, chebyshevtransform, ic

function plan_chebyshevtransform{T<:FFTW.fftwNumber}(x::Vector{T};kind::Integer=1)
if kind == 1
length(x)==1?identity:FFTW.plan_r2r(x, FFTW.REDFT10)
length(x)==1?identity:wrap_fft_plan(FFTW.plan_r2r(x, FFTW.REDFT10))
elseif kind == 2
length(x)==1?identity:FFTW.plan_r2r(x, FFTW.REDFT00)
length(x)==1?identity:wrap_fft_plan(FFTW.plan_r2r(x, FFTW.REDFT00))
end
end

function chebyshevtransform{T<:FFTW.fftwNumber}(x::Vector{T},plan::Function;kind::Integer=1)
function chebyshevtransform{T<:FFTW.fftwNumber}(x::Vector{T},plan;kind::Integer=1)
if kind == 1
n = length(x)
if n == 1
Expand Down Expand Up @@ -40,13 +40,13 @@ chebyshevtransform{T<:FFTW.fftwNumber}(x::Vector{T};kind::Integer=1)=chebyshevtr

function plan_ichebyshevtransform{T<:FFTW.fftwNumber}(x::Vector{T};kind::Integer=1)
if kind == 1
length(x)==1?identity:FFTW.plan_r2r(x, FFTW.REDFT01)
length(x)==1?identity:wrap_fft_plan(FFTW.plan_r2r(x, FFTW.REDFT01))
elseif kind == 2
length(x)==1?identity:FFTW.plan_r2r(x, FFTW.REDFT00)
length(x)==1?identity:wrap_fft_plan(FFTW.plan_r2r(x, FFTW.REDFT00))
end
end

function ichebyshevtransform{T<:FFTW.fftwNumber}(x::Vector{T},plan::Function;kind::Integer=1)
function ichebyshevtransform{T<:FFTW.fftwNumber}(x::Vector{T},plan;kind::Integer=1)
if kind == 1
x[1] *=2
ret = plan(negateeven!(x))/2
Expand Down
8 changes: 4 additions & 4 deletions src/LinearAlgebra/helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ end

##FFT That interlaces coefficients

plan_svfft(x::Vector) = plan_fft(x)
plan_isvfft(x::Vector) = plan_ifft(x)
plan_svfft(x::Vector) = wrap_fft_plan(plan_fft(x))
plan_isvfft(x::Vector) = wrap_fft_plan(plan_ifft(x))

function svfft(v::Vector,plan::Function)
function svfft(v::Vector,plan)
n=length(v)
v=plan(v)/n
if mod(n,2) == 0
Expand All @@ -229,7 +229,7 @@ function svfft(v::Vector,plan::Function)
end
end

function isvfft(sv::Vector,plan::Function)
function isvfft(sv::Vector,plan)
n=length(sv)

if mod(n,2) == 0
Expand Down
16 changes: 8 additions & 8 deletions src/Spaces/Fourier/Fourier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ spacescompatible{s}(a::Hardy{s},b::Hardy{s})=domainscompatible(a,b)

typealias Taylor Hardy{true}

plan_transform(::Taylor,x::Vector)=plan_fft(x)
plan_itransform(::Taylor,x::Vector)=plan_ifft(x)
plan_transform(::Taylor,x::Vector)=wrap_fft_plan(plan_fft(x))
plan_itransform(::Taylor,x::Vector)=wrap_fft_plan(plan_ifft(x))
transform(::Taylor,vals::Vector,plan)=alternatesign!(plan(vals)/length(vals))
itransform(::Taylor,cfs::Vector,plan)=plan(alternatesign!(cfs))*length(cfs)

plan_transform(::Hardy{false},x::Vector)=plan_fft(x)
plan_itransform(::Hardy{false},x::Vector)=plan_ifft(x)
plan_transform(::Hardy{false},x::Vector)=wrap_fft_plan(plan_fft(x))
plan_itransform(::Hardy{false},x::Vector)=wrap_fft_plan(plan_ifft(x))
transform(::Hardy{false},vals::Vector,plan)=-alternatesign!(flipdim(plan(vals),1)/length(vals))
itransform(::Hardy{false},cfs::Vector,plan)=plan(flipdim(alternatesign!(-cfs),1))*length(cfs)

Expand Down Expand Up @@ -100,8 +100,8 @@ evaluate(f::Fun{CosSpace},t)=clenshaw(f.coefficients,cos(tocanonical(f,t)))


points(sp::SinSpace,n)=points(domain(sp),2n+2)[n+3:2n+2]
plan_transform{T<:FFTW.fftwNumber}(::SinSpace,x::Vector{T})=FFTW.plan_r2r(x,FFTW.RODFT00)
plan_itransform{T<:FFTW.fftwNumber}(::SinSpace,x::Vector{T})=FFTW.plan_r2r(x,FFTW.RODFT00)
plan_transform{T<:FFTW.fftwNumber}(::SinSpace,x::Vector{T})=wrap_fft_plan(FFTW.plan_r2r(x,FFTW.RODFT00))
plan_itransform{T<:FFTW.fftwNumber}(::SinSpace,x::Vector{T})=wrap_fft_plan(FFTW.plan_r2r(x,FFTW.RODFT00))
transform(::SinSpace,vals,plan)=plan(vals)/(length(vals)+1)
itransform(::SinSpace,cfs,plan)=plan(cfs)/2
evaluate(f::Fun{SinSpace},t)=sineshaw(f.coefficients,tocanonical(f,t))
Expand Down Expand Up @@ -131,8 +131,8 @@ Fourier{T<:Number}(d::Vector{T}) = Fourier(PeriodicInterval(d))


points(sp::Fourier,n)=points(domain(sp),n)
plan_transform{T<:FFTW.fftwNumber}(::Fourier,x::Vector{T}) = FFTW.plan_r2r(x, FFTW.R2HC)
plan_itransform{T<:FFTW.fftwNumber}(::Fourier,x::Vector{T}) = FFTW.plan_r2r(x, FFTW.HC2R)
plan_transform{T<:FFTW.fftwNumber}(::Fourier,x::Vector{T}) = wrap_fft_plan(FFTW.plan_r2r(x, FFTW.R2HC))
plan_itransform{T<:FFTW.fftwNumber}(::Fourier,x::Vector{T}) = wrap_fft_plan(FFTW.plan_r2r(x, FFTW.HC2R))

function transform{T<:Number}(::Fourier,vals::Vector{T},plan)
n=length(vals)
Expand Down

0 comments on commit 736b330

Please sign in to comment.