Skip to content

Commit 4174b82

Browse files
committed
Use broadcast syntax for all special functions
1 parent 8d39317 commit 4174b82

20 files changed

+70
-89
lines changed

src/ChebyshevJacobiPlan.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function ForwardChebyshevJacobiPlan{T}(c_jac::AbstractVector{T},α::T,β::T,M::I
142142
@inbounds for i=1:N+1 tempcosβsinα[i] = tempcos[i]^+1/2)*tempsin[i]^+1/2) end
143143

144144
# Initialize normalizing constant
145-
cnαβ = Cnαβ(0:N,α,β)
145+
cnαβ = Cnαβ.(0:N,α,β)
146146
cnmαβ = zero(cnαβ)
147147

148148
# Get indices
@@ -184,11 +184,11 @@ function BackwardChebyshevJacobiPlan{T}(c_cheb::AbstractVector{T},α::T,β::T,M:
184184
@inbounds for i=1:2N+1 tempcosβsinα[i] = tempcos[i]^+1/2)*tempsin[i]^+1/2) end
185185

186186
# Initialize normalizing constant
187-
cnαβ = Cnαβ(0:2N,α,β)
187+
cnαβ = Cnαβ.(0:2N,α,β)
188188
cnmαβ = zero(cnαβ)
189189

190190
# Initialize orthonormality constants
191-
anαβ = Anαβ(0:N,α,β)
191+
anαβ = Anαβ.(0:N,α,β)
192192

193193
# Get indices
194194
CJI = ChebyshevJacobiIndices(α,β,CJC,tempmindices,cfs,tempcos,tempsin,tempcosβsinα)

src/ChebyshevUltrasphericalPlan.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function BackwardChebyshevUltrasphericalPlan{T}(c_ultra::AbstractVector{T},λ::T
184184
cnmλ = similar(cnλ)
185185

186186
# Initialize orthonormality constants
187-
anλ = Anαβ(0:N,λ-half(λ),λ-half(λ))
187+
anλ = Anαβ.(0:N,λ-half(λ),λ-half(λ))
188188

189189
# Get indices
190190
CUI = ChebyshevUltrasphericalIndices(λ,CUC,tempmindices,tempsin,tempsinλ)

src/nufft.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ function plan_nufft3{T<:AbstractFloat}(x::AbstractVector{T}, ω::AbstractVector{
6464

6565
p = plan_nufft1(ω, ϵ)
6666

67-
D1 = Diagonal(1-(s-t+1)/N)
68-
D2 = Diagonal((s-t+1)/N)
69-
D3 = Diagonal(exp.(-2*im*T(π)*ω))
67+
D1 = Diagonal(1 .- (s .- t .+ 1)./N)
68+
D2 = Diagonal((s .- t .+ 1)./N)
69+
D3 = Diagonal(exp.(-2 .* im .* T(π) .* ω ))
7070
U = hcat(D1*u, D2*u)
7171
V = hcat(v, D3*v)
7272

src/specialfunctions.jl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,12 @@ end
103103

104104

105105
stirlingremainder(z::Number,N::Int) = (1+zeta(N))*gamma(N)/((2π)^(N+1)*z^N)/stirlingseries(z)
106-
stirlingremainder{T<:Number}(z::AbstractVector{T},N::Int) = (1+zeta(N))*gamma(N)/(2π)^(N+1)./z.^N./stirlingseries(z)
107106

108107
Aratio(n::Int::Float64::Float64) = exp((n/2+α+1/4)*log1p(-β/(n+α+β+1))+(n/2+β+1/4)*log1p(-α/(n+α+β+1))+(n/2+1/4)*log1p/(n+1))+(n/2+1/4)*log1p/(n+1)))
109108
Aratio(n::Number::Number::Number) = (1++1)/n)^(n+α+1/2)*(1++1)/n)^(n+β+1/2)/(1++β+1)/n)^(n+α+β+1/2)/(1+(zero(α)+zero(β))/n)^(n+1/2)
110-
Aratio(n::AbstractVector::Number::Number) = [ Aratio(n[i],α,β) for i=1:length(n) ]
111109

112110
Cratio(n::Int::Float64::Float64) = exp((n+α+1/2)*log1p((α-β)/(2n+α+β+2))+(n+β+1/2)*log1p((β-α)/(2n+α+β+2))-log1p((α+β+2)/2n)/2)/sqrt(n)
113111
Cratio(n::Number::Number::Number) = n^(-1/2)*(1++1)/n)^(n+α+1/2)*(1++1)/n)^(n+β+1/2)/(1++β+2)/2n)^(2n+α+β+3/2)
114-
Cratio(n::AbstractVector::Number::Number) = [ Cratio(n[i],α,β) for i=1:length(n) ]
115112

116113

117114
Anαβ(n::Number::Number::Number) = 2^+β+1)/(2n+α+β+1)*exp(lgamma(n+α+1)-lgamma(n+α+β+1)+lgamma(n+β+1)-lgamma(n+1))
@@ -135,9 +132,6 @@ function Anαβ(n::Integer,α::Float64,β::Float64)
135132
end
136133
end
137134

138-
Anαβ{T<:Integer}(n::AbstractVector{T}::Number::Number) = [ Anαβ(n[i],α,β) for i=1:length(n) ]
139-
Anαβ{T<:Integer}(n::AbstractMatrix{T}::Number::Number) = [ Anαβ(n[i,j],α,β) for i=1:size(n,1), j=1:size(n,2) ]
140-
141135

142136
doc"""
143137
The Lambda function ``\Lambda(z) = \frac{\Gamma(z+\frac{1}{2})}{\Gamma(z+1)}`` for the ratio of gamma functions.
@@ -168,7 +162,6 @@ function Λ(x::Float64,λ₁::Float64,λ₂::Float64)
168162
(x+λ₂)/(x+λ₁)*Λ(x+1.,λ₁,λ₂)
169163
end
170164
end
171-
Λ{T<:Number}(x::AbstractArray{T},λ₁::Number,λ₂::Number) = promote_type(T,typeof(λ₁),typeof(λ₂))[ Λ(x[i],λ₁,λ₂) for i in eachindex(x) ]
172165

173166
## TODO: deprecate when Lambert-W is supported in a mainstream repository such as SpecialFunctions.jl
174167
doc"""
@@ -210,9 +203,6 @@ function Cnλ{T<:Integer}(n::UnitRange{T},λ::Number)
210203
ret
211204
end
212205

213-
Cnλ{T<:Integer}(n::AbstractVector{T}::Number) = [ Cnλ(n[i],λ) for i=1:length(n) ]
214-
Cnλ{T<:Integer}(n::AbstractMatrix{T}::Number) = [ Cnλ(n[i,j],λ) for i=1:size(n,1), j=1:size(n,2) ]
215-
216206
function Cnmλ(n::Integer,m::Integer::Number)
217207
if m == 0
218208
Cnλ(n,λ)
@@ -221,8 +211,6 @@ function Cnmλ(n::Integer,m::Integer,λ::Number)
221211
end
222212
end
223213

224-
Cnmλ{T<:Integer}(n::AbstractVector{T},m::Integer::Number) = [ Cnmλ(n[i],m,λ) for i=1:length(n) ]
225-
226214

227215
function Cnαβ(n::Integer::Number::Number)
228216
if n==0
@@ -244,9 +232,6 @@ function Cnαβ(n::Integer,α::Float64,β::Float64)
244232
end
245233
end
246234

247-
Cnαβ{T<:Integer}(n::AbstractVector{T}::Number::Number) = [ Cnαβ(n[i],α,β) for i=1:length(n) ]
248-
Cnαβ{T<:Integer}(n::AbstractMatrix{T}::Number::Number) = [ Cnαβ(n[i,j],α,β) for i=1:size(n,1), j=1:size(n,2) ]
249-
250235
function Cnmαβ(n::Integer,m::Integer::Number::Number)
251236
if m == 0
252237
Cnαβ(n,α,β)
@@ -255,8 +240,6 @@ function Cnmαβ(n::Integer,m::Integer,α::Number,β::Number)
255240
end
256241
end
257242

258-
Cnmαβ{T<:Integer}(n::AbstractVector{T},m::Integer::Number::Number) = [ Cnmαβ(n[i],m,α,β) for i=1:length(n) ]
259-
Cnmαβ{T<:Integer}(n::AbstractMatrix{T},m::Integer::Number::Number) = [ Cnmαβ(n[i,j],m,α,β) for i=1:size(n,1), j=1:size(n,2) ]
260243

261244
function Cnmαβ{T<:Number}(n::Integer,m::Integer::AbstractArray{T}::AbstractArray{T})
262245
shp = promote_shape(size(α),size(β))

src/toeplitzhankel.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function leg2chebuTH{S}(::Type{S},n)
126126
t = zeros(S,n)
127127
t[1:2:end] = λ[1:2:n]./(((1:2:n).-2))
128128
T = TriangularToeplitz(-2t/π,:U)
129-
H = Hankel(λ[1:n]./((1:n)+1),λ[n:end]./((n:2n-1)+1))
129+
H = Hankel(λ[1:n]./((1:n).+1),λ[n:end]./((n:2n-1).+1))
130130
T,H
131131
end
132132

@@ -135,9 +135,9 @@ function ultra2ultraTH{S}(::Type{S},n,λ₁,λ₂)
135135
DL = (zero(S):n-one(S)) .+ λ₂
136136
jk = 0:half(S):n-1
137137
t = zeros(S,n)
138-
t[1:2:n] = Λ(jk,λ₁-λ₂,one(S))[1:2:n]
138+
t[1:2:n] = Λ.(jk,λ₁-λ₂,one(S))[1:2:n]
139139
T = TriangularToeplitz(scale!(inv(gamma(λ₁-λ₂)),t),:U)
140-
h = Λ(jk,λ₁,λ₂+one(S))
140+
h = Λ.(jk,λ₁,λ₂+one(S))
141141
scale!(gamma(λ₂)/gamma(λ₁),h)
142142
H = Hankel(h[1:n],h[n:end])
143143
DR = ones(S,n)
@@ -149,10 +149,10 @@ function jac2jacTH{S}(::Type{S},n,α,β,γ,δ)
149149
@assert abs-γ) < 1
150150
@assert α+β > -1
151151
jk = zero(S):n-one(S)
152-
DL = (2jk+γ+β+one(S)).*Λ(jk,γ+β+one(S),β+one(S))
153-
T = TriangularToeplitz(Λ(jk,α-γ,one(S)),:U)
154-
H = Hankel(Λ(jk,α+β+one(S),γ+β+two(S)),Λ(jk+n-one(S),α+β+one(S),γ+β+two(S)))
155-
DR = Λ(jk,β+one(S),α+β+one(S))/gamma-γ)
152+
DL = (2jk .+ γ .+ β .+ one(S)).*Λ.(jk,γ+β+one(S),β+one(S))
153+
T = TriangularToeplitz(Λ.(jk,α-γ,one(S)),:U)
154+
H = Hankel(Λ.(jk,α+β+one(S),γ+β+two(S)),Λ.(jk.+n.-one(S),α+β+one(S),γ+β+two(S)))
155+
DR = Λ.(jk,β+one(S),α+β+one(S))./gamma-γ)
156156
T,H,DL,DR
157157
end
158158

test/basictests.jl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
using FastTransforms, LowRankApprox
2-
3-
if VERSION < v"0.7-"
4-
using Base.Test
5-
else
6-
using Test
7-
end
8-
1+
using Compat, FastTransforms, LowRankApprox
2+
using Compat.Test
93
import FastTransforms: Cnλ, Λ, lambertw, Cnαβ, Anαβ, fejer1, fejer2, clenshawcurtis
104

115
@testset "Special functions" begin
@@ -28,11 +22,11 @@ import FastTransforms: Cnλ, Λ, lambertw, Cnαβ, Anαβ, fejer1, fejer2, clens
2822
α = 0.125
2923
β = 0.375
3024

31-
@time FastTransforms.Cnαβ(n,α,β);
32-
@test norm(FastTransforms.Cnαβ(n,α,β) ./ FastTransforms.Cnαβ(n,big(α),big(β)) .- 1,Inf) < 3eps()
25+
@time FastTransforms.Cnαβ.(n,α,β);
26+
@test norm(FastTransforms.Cnαβ.(n,α,β) ./ FastTransforms.Cnαβ.(n,big(α),big(β)) .- 1,Inf) < 3eps()
3327

34-
@time FastTransforms.Anαβ(n,α,β);
35-
@test norm(FastTransforms.Anαβ(n,α,β) ./ FastTransforms.Anαβ(n,big(α),big(β)) .- 1,Inf) < 4eps()
28+
@time FastTransforms.Anαβ.(n,α,β);
29+
@test norm(FastTransforms.Anαβ.(n,α,β) ./ FastTransforms.Anαβ.(n,big(α),big(β)) .- 1,Inf) < 4eps()
3630
end
3731

3832
@testset "Fejer and Clenshaw--Curtis quadrature" begin

test/butterflytests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using FastTransforms, LowRankApprox
2-
using Base.Test
1+
using FastTransforms, LowRankApprox, Compat
2+
using Compat.Test
33

44
import FastTransforms: Butterfly
55

test/chebyshevjacobitests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FastTransforms, Base.Test
1+
using FastTransforms, Compat
2+
using Compat.Test
23

34
@testset "Chebyshev--Jacobi transform" begin
45
println("Testing the accuracy of asymptotics")

test/chebyshevlegendretests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FastTransforms, Base.Test
1+
using FastTransforms, Compat
2+
using Compat.Test
23

34
@testset "Chebyshev--Legendre transform" begin
45
for k in round.([Int],logspace(1,4,20))

test/fftBigFloattests.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using FastTransforms
2-
if VERSION < v"0.7-"
3-
using Base.Test, Base.FFTW
4-
else
5-
using Test, FFTW
1+
using FastTransforms, Compat
2+
using Compat.Test
3+
if VERSION v"0.7-"
4+
using FFTW
65
end
76

87
@testset "BigFloat FFT and DCT" begin

test/gaunttests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FastTransforms, Base.Test
1+
using FastTransforms, Compat
2+
using Compat.Test
23

34
import FastTransforms: δ
45

test/nuffttests.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using FastTransforms
2-
if VERSION < v"0.7-"
3-
using Base.Test
4-
else
5-
using Test, FFTW
1+
using FastTransforms, Compat
2+
using Compat.Test
3+
4+
if VERSION v"0.7-"
5+
using FFTW
66
end
77

88
@testset "Nonuniform fast Fourier transforms" begin
99

1010
FFTW.set_num_threads(Base.Sys.CPU_CORES)
1111

12-
function nudft1{T<:AbstractFloat}(c::AbstractVector, ω::AbstractVector{T})
12+
function nudft1(c::AbstractVector, ω::AbstractVector{T}) where {T<:AbstractFloat}
1313
# Nonuniform discrete Fourier transform of type I
1414

1515
N = size(ω, 1)
@@ -21,7 +21,7 @@ end
2121
return output
2222
end
2323

24-
function nudft2{T<:AbstractFloat}(c::AbstractVector, x::AbstractVector{T})
24+
function nudft2(c::AbstractVector, x::AbstractVector{T}) where {T<:AbstractFloat}
2525
# Nonuniform discrete Fourier transform of type II
2626

2727
N = size(x, 1)
@@ -34,7 +34,7 @@ end
3434
return output
3535
end
3636

37-
function nudft3{T<:AbstractFloat}(c::AbstractVector, x::AbstractVector{T}, ω::AbstractVector{T})
37+
function nudft3(c::AbstractVector, x::AbstractVector{T}, ω::AbstractVector{T}) where {T<:AbstractFloat}
3838
# Nonuniform discrete Fourier transform of type III
3939

4040
N = size(x, 1)
@@ -91,7 +91,7 @@ end
9191
end
9292
end
9393

94-
function nudft1{T<:AbstractFloat}(C::Matrix{Complex{T}}, ω1::AbstractVector{T}, ω2::AbstractVector{T})
94+
function nudft1(C::Matrix{Complex{T}}, ω1::AbstractVector{T}, ω2::AbstractVector{T}) where {T<:AbstractFloat}
9595
# Nonuniform discrete Fourier transform of type I-I
9696

9797
M, N = size(C)
@@ -104,7 +104,7 @@ end
104104
return output
105105
end
106106

107-
function nudft2{T<:AbstractFloat}(C::Matrix{Complex{T}}, x::AbstractVector{T}, y::AbstractVector{T})
107+
function nudft2(C::Matrix{Complex{T}}, x::AbstractVector{T}, y::AbstractVector{T}) where {T<:AbstractFloat}
108108
# Nonuniform discrete Fourier transform of type II-II
109109

110110
M, N = size(C)

test/paduatests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FastTransforms, Base.Test
1+
using FastTransforms, Compat
2+
using Compat.Test
23

34
@testset "Padua transform and its inverse" begin
45
n=200

test/runtests.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
using FastTransforms
2-
if VERSION < v"0.7-"
3-
using Base.Test
4-
else
5-
using Test
6-
end
1+
using FastTransforms, Compat
2+
using Compat.Test
73

84
srand(0)
95

test/sphericalharmonics/apitests.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using FastTransforms, Base.Test
1+
using FastTransforms, Compat
2+
using Compat.Test
23

34
import FastTransforms: normalizecolumns!, maxcolnorm
45

56
@testset "Spherical harmonic API" begin
6-
n = VERSION < v"0.6.0-" ? 256 : 512
7+
n = 512
78
A = sphrandn(Float64, n, n);
89
normalizecolumns!(A);
910

@@ -17,19 +18,18 @@ import FastTransforms: normalizecolumns!, maxcolnorm
1718

1819
println("The backward difference between slow plan and original: ", maxcolnorm(A-C))
1920

20-
if VERSION v"0.6.0-"
21-
n = 1024
22-
A = sphrandn(Float64, n, n);
23-
normalizecolumns!(A);
2421

25-
B = sph2fourier(A; sketch = :none)
26-
C = fourier2sph(B; sketch = :none)
27-
println("The backward difference between thin plan and original: ", maxcolnorm(A-C))
22+
n = 1024
23+
A = sphrandn(Float64, n, n);
24+
normalizecolumns!(A);
25+
26+
B = sph2fourier(A; sketch = :none)
27+
C = fourier2sph(B; sketch = :none)
28+
println("The backward difference between thin plan and original: ", maxcolnorm(A-C))
2829

29-
P = plan_sph2fourier(A; sketch = :none)
30-
B = P*A
31-
C = P\B
30+
P = plan_sph2fourier(A; sketch = :none)
31+
B = P*A
32+
C = P\B
3233

33-
println("The backward difference between thin plan and original: ", maxcolnorm(A-C))
34-
end
34+
println("The backward difference between thin plan and original: ", maxcolnorm(A-C))
3535
end

test/sphericalharmonics/fastplantests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FastTransforms, Base.Test
1+
using FastTransforms, Compat
2+
using Compat.Test
23

34
import FastTransforms: normalizecolumns!, maxcolnorm
45

test/sphericalharmonics/pointwisetests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FastTransforms, Base.Test
1+
using FastTransforms, Base.Test, Compat
2+
using Compat.Test
23

34
import FastTransforms: normalizecolumns!, maxcolnorm, sphevaluatepi
45

test/sphericalharmonics/sphericalharmonictests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FastTransforms, Base.Test
1+
using FastTransforms, Compat
2+
using Compat.Test
23

34
srand(0)
45

test/sphericalharmonics/synthesisanalysistests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FastTransforms, Base.Test
1+
using FastTransforms, Compat
2+
using Compat.Test
23

34
import FastTransforms: normalizecolumns!, maxcolnorm
45

test/sphericalharmonics/thinplantests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FastTransforms, Base.Test
1+
using FastTransforms, Compat
2+
using Compat.Test
23

34
import FastTransforms: normalizecolumns!, maxcolnorm
45

0 commit comments

Comments
 (0)