Skip to content

Commit ef06b36

Browse files
some rearrangements
close the longest open pull request? #89, fixing #67 also, stop the type piracy of DSP's conv for certain bitstype floating-point types
1 parent 1cf16ae commit ef06b36

File tree

8 files changed

+58
-39
lines changed

8 files changed

+58
-39
lines changed

src/FastTransforms.jl

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
module FastTransforms
22

3-
using FastGaussQuadrature, LinearAlgebra
4-
using Reexport, SpecialFunctions, ToeplitzMatrices, FillArrays, ArrayLayouts
3+
using ArrayLayouts, FastGaussQuadrature, FillArrays, LinearAlgebra,
4+
Reexport, SpecialFunctions, ToeplitzMatrices
55

66
import DSP
77

88
@reexport using AbstractFFTs
99
@reexport using FFTW
1010

11-
import Base: unsafe_convert, eltype, ndims, adjoint, transpose, show, *, \,
12-
inv, length, size, view, getindex, convert
11+
import Base: convert, unsafe_convert, eltype, ndims, adjoint, transpose, show,
12+
*, \, inv, length, size, view, getindex
1313

1414
import Base.GMP: Limb
1515

1616
import AbstractFFTs: Plan, ScaledPlan,
17-
fft, ifft, bfft, fft!, ifft!, bfft!,
18-
plan_fft, plan_ifft, plan_bfft, plan_fft!, plan_ifft!, plan_bfft!,
19-
rfft, irfft, brfft, plan_rfft, plan_irfft, plan_brfft,
20-
fftshift, ifftshift,
21-
rfft_output_size, brfft_output_size,
17+
fft, ifft, bfft, fft!, ifft!, bfft!, rfft, irfft, brfft,
18+
plan_fft, plan_ifft, plan_bfft, plan_fft!, plan_ifft!,
19+
plan_bfft!, plan_rfft, plan_irfft, plan_brfft,
20+
fftshift, ifftshift, rfft_output_size, brfft_output_size,
2221
plan_inv, normalization
2322

2423
import DSP: conv
@@ -53,28 +52,37 @@ include("clenshaw.jl")
5352

5453
include("libfasttransforms.jl")
5554

56-
export plan_nufft, plan_nufft1, plan_nufft2, plan_nufft3, plan_inufft1, plan_inufft2
5755
export nufft, nufft1, nufft2, nufft3, inufft1, inufft2
5856

57+
export plan_nufft, plan_nufft1, plan_nufft2, plan_nufft3,
58+
plan_inufft1, plan_inufft2
59+
5960
include("nufft.jl")
6061
include("inufft.jl")
6162

6263
export paduatransform, ipaduatransform, paduatransform!, ipaduatransform!,
63-
paduapoints, plan_paduatransform!, plan_ipaduatransform!
64+
paduapoints
65+
66+
export plan_paduatransform!, plan_ipaduatransform!
6467

6568
include("PaduaTransform.jl")
6669

67-
export plan_chebyshevtransform, plan_ichebyshevtransform, plan_chebyshevtransform!, plan_ichebyshevtransform!,
68-
chebyshevtransform, ichebyshevtransform, chebyshevpoints,
69-
plan_chebyshevutransform, plan_ichebyshevutransform, plan_chebyshevutransform!, plan_ichebyshevutransform!,
70-
chebyshevutransform, ichebyshevutransform,
71-
chebyshevtransform!, ichebyshevtransform!, chebyshevutransform!, ichebyshevutransform!
70+
export chebyshevtransform, ichebyshevtransform,
71+
chebyshevtransform!, ichebyshevtransform!,
72+
chebyshevutransform, ichebyshevutransform,
73+
chebyshevutransform!, ichebyshevutransform!, chebyshevpoints
74+
75+
export plan_chebyshevtransform, plan_ichebyshevtransform,
76+
plan_chebyshevtransform!, plan_ichebyshevtransform!,
77+
plan_chebyshevutransform, plan_ichebyshevutransform,
78+
plan_chebyshevutransform!, plan_ichebyshevutransform!
7279

7380
include("chebyshevtransform.jl")
7481

75-
export plan_clenshawcurtis, clenshawcurtisnodes, clenshawcurtisweights
76-
export plan_fejer1, fejernodes1, fejerweights1,
77-
plan_fejer2, fejernodes2, fejerweights2
82+
export clenshawcurtisnodes, clenshawcurtisweights, fejernodes1, fejerweights1,
83+
fejernodes2, fejerweights2
84+
85+
export plan_clenshawcurtis, plan_fejer1, plan_fejer2
7886

7987
include("clenshawcurtis.jl")
8088
include("fejer.jl")
@@ -97,10 +105,6 @@ export sphones, sphzeros, sphrand, sphrandn, sphevaluate,
97105
tetones, tetzeros, tetrand, tetrandn,
98106
spinsphones, spinsphzeros, spinsphrand, spinsphrandn
99107

100-
lgamma(x) = logabsgamma(x)[1]
101-
102108
include("specialfunctions.jl")
103109

104-
105-
106110
end # module

src/fftBigFloat.jl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function generic_fft(x::Vector{T}) where T<:AbstractFloats
5151
ks = range(zero(real(T)),stop=n-one(real(T)),length=n)
5252
Wks = exp.((-im).*convert(T,π).*ks.^2 ./ n)
5353
xq, wq = x.*Wks, conj([exp(-im*convert(T,π)*n);reverse(Wks);Wks[2:end]])
54-
return Wks.*conv(xq,wq)[n+1:2n]
54+
return Wks.*_conv!(xq,wq)[n+1:2n]
5555
end
5656

5757
generic_bfft(x::StridedArray{T, N}, region) where {T <: AbstractFloats, N} = conj!(generic_fft(conj(x), region))
@@ -69,16 +69,23 @@ function generic_irfft(v::Vector{T}, n::Integer, region) where T<:ComplexFloats
6969
end
7070
generic_brfft(v::StridedArray, n::Integer, region) = generic_irfft(v, n, region)*n
7171

72-
function conv(u::StridedVector{T}, v::StridedVector{T}) where T<:AbstractFloats
73-
nu,nv = length(u),length(v)
72+
function _conv!(u::StridedVector{T}, v::StridedVector{T}) where T<:AbstractFloats
73+
nu = length(u)
74+
nv = length(v)
7475
n = nu + nv - 1
75-
np2 = nextpow(2,n)
76-
append!(u,zeros(T,np2-nu)),append!(v,zeros(T,np2-nv))
76+
np2 = nextpow(2, n)
77+
append!(u, zeros(T, np2-nu))
78+
append!(v, zeros(T, np2-nv))
7779
y = generic_ifft_pow2(generic_fft_pow2(u).*generic_fft_pow2(v))
7880
#TODO This would not handle Dual/ComplexDual numbers correctly
7981
y = T<:Real ? real(y[1:n]) : y[1:n]
8082
end
8183

84+
conv(u::AbstractArray{T, N}, v::AbstractArray{T, N}) where {T<:AbstractFloat, N} = _conv!(deepcopy(u), deepcopy(v))
85+
conv(u::AbstractArray{T, N}, v::AbstractArray{Complex{T}, N}) where {T<:AbstractFloat, N} = _conv!(complex(deepcopy(u)), deepcopy(v))
86+
conv(u::AbstractArray{Complex{T}, N}, v::AbstractArray{T, N}) where {T<:AbstractFloat, N} = _conv!(deepcopy(u), complex(deepcopy(v)))
87+
conv(u::AbstractArray{Complex{T}, N}, v::AbstractArray{Complex{T}, N}) where {T<:AbstractFloat, N} = _conv!(deepcopy(u), deepcopy(v))
88+
8289
# This is a Cooley-Tukey FFT algorithm inspired by many widely available algorithms including:
8390
# c_radix2.c in the GNU Scientific Library and four1 in the Numerical Recipes in C.
8491
# However, the trigonometric recurrence is improved for greater efficiency.
@@ -120,16 +127,16 @@ function generic_fft_pow2!(x::Vector{T}) where T<:AbstractFloat
120127
end
121128

122129
function generic_fft_pow2(x::Vector{Complex{T}}) where T<:AbstractFloat
123-
y = interlace(real(x),imag(x))
130+
y = interlace(real(x), imag(x))
124131
generic_fft_pow2!(y)
125-
return complex.(y[1:2:end],y[2:2:end])
132+
return complex.(y[1:2:end], y[2:2:end])
126133
end
127-
generic_fft_pow2(x::Vector{T}) where {T<:AbstractFloat} = generic_fft_pow2(complex(x))
134+
generic_fft_pow2(x::Vector{T}) where T<:AbstractFloat = generic_fft_pow2(complex(x))
128135

129136
function generic_ifft_pow2(x::Vector{Complex{T}}) where T<:AbstractFloat
130-
y = interlace(real(x),-imag(x))
137+
y = interlace(real(x), -imag(x))
131138
generic_fft_pow2!(y)
132-
return complex.(y[1:2:end],-y[2:2:end])/length(x)
139+
return ldiv!(length(x), conj!(complex.(y[1:2:end], y[2:2:end])))
133140
end
134141

135142
function generic_dct(x::StridedVector{T}, region::Integer) where T<:AbstractFloats

src/specialfunctions.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ function pochhammer(x::Number,n::UnitRange{T}) where T<:Real
5656
ret
5757
end
5858

59+
lgamma(x) = logabsgamma(x)[1]
60+
5961
ogamma(x::Number) = (isinteger(x) && x<0) ? zero(float(x)) : inv(gamma(x))
6062

6163
"""

test/fftBigFloattests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using FastTransforms, FFTW, Test
1+
using DSP, FFTW, FastTransforms, LinearAlgebra, Test
22

33
@testset "BigFloat FFT and DCT" begin
44

@@ -9,6 +9,12 @@ using FastTransforms, FFTW, Test
99
c = collect(range(-big(1.0),stop=1.0,length=201))
1010
@test norm(ifft(fft(c))-c) < 200norm(c)eps(BigFloat)
1111

12+
s = big(1) ./ (1:10)
13+
s64 = Float64.(s)
14+
@test Float64.(conv(s, s)) conv(s64, s64)
15+
@test s == big(1) ./ (1:10) #67, ensure conv doesn't overwrite input
16+
@test all(s64 .=== Float64.(big(1) ./ (1:10)))
17+
1218
p = plan_dct(c)
1319
@test norm(FastTransforms.generic_dct(c) - p*c) == 0
1420

test/gaunttests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using FastTransforms, Test
1+
using FastTransforms, LinearAlgebra, Test
22

33
import FastTransforms: δ
44

test/nuffttests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using FastTransforms, Test, FFTW
1+
using FFTW, FastTransforms, LinearAlgebra, Test
22

33
FFTW.set_num_threads(ceil(Int, Sys.CPU_THREADS/2))
44

@@ -75,7 +75,7 @@ FFTW.set_num_threads(ceil(Int, Sys.CPU_THREADS/2))
7575
fftc = fft(c)
7676
if Sys.WORD_SIZE == 64
7777
@test_skip norm(nufft1(c, ω, ϵ) - fftc) == 0 # skip because fftw3 seems to change this
78-
@test_skip norm(nufft2(c, x, ϵ) - fftc) == 0 # skip because fftw3 seems to change this
78+
@test norm(nufft2(c, x, ϵ) - fftc) == 0
7979
@test_skip norm(nufft3(c, x, ω, ϵ) - fftc) == 0 # skip because fftw3 seems to change this
8080
end
8181
err_bnd = 500*eps(Float64)*norm(c)

test/quadraturetests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using FastTransforms, Test
1+
using FastTransforms, LinearAlgebra, Test
22

33
import FastTransforms: chebyshevmoments1, chebyshevmoments2,
44
chebyshevjacobimoments1, chebyshevjacobimoments2,

test/specialfunctionstests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using FastTransforms, Test
1+
using FastTransforms, LinearAlgebra, Test
22

33
import FastTransforms: pochhammer, sqrtpi, SpecialFunctions.gamma
44
import FastTransforms: Cnλ, Λ, lambertw, Cnαβ, Anαβ

0 commit comments

Comments
 (0)