Skip to content

Commit ea8b6ad

Browse files
add complex transforms, part deux
Closes #79
1 parent 7b43d91 commit ea8b6ad

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

src/libfasttransforms.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ for (fJ, fC, fE, K) in ((:plan_sph_synthesis, :ft_plan_sph_synthesis, :ft_execut
436436
(:plan_tri_analysis, :ft_plan_tri_analysis, :ft_execute_tri_analysis, TRIANGLEANALYSIS))
437437
@eval begin
438438
$fJ(x::Matrix{T}) where T = $fJ(T, size(x, 1), size(x, 2))
439+
$fJ(x::Matrix{Complex{T}}) where T <: Real = $fJ(T, size(x, 1), size(x, 2))
439440
function $fJ(::Type{Float64}, n::Integer, m::Integer)
440441
plan = ccall(($(string(fC)), libfasttransforms), Ptr{ft_plan_struct}, (Cint, Cint), n, m)
441442
return FTPlan{Float64, 2, $K}(plan, n, m)
@@ -451,6 +452,7 @@ for (fJ, fC, fE, K) in ((:plan_sph_synthesis, :ft_plan_sph_synthesis, :ft_execut
451452
end
452453

453454
plan_tet_synthesis(x::Array{T, 3}) where T = plan_tet_synthesis(T, size(x, 1), size(x, 2), size(x, 3))
455+
plan_tet_synthesis(x::Array{Complex{T}, 3}) where T <: Real = plan_tet_synthesis(T, size(x, 1), size(x, 2), size(x, 3))
454456

455457
function plan_tet_synthesis(::Type{Float64}, n::Integer, l::Integer, m::Integer)
456458
plan = ccall((:ft_plan_tet_synthesis, libfasttransforms), Ptr{ft_plan_struct}, (Cint, Cint, Cint), n, l, m)
@@ -466,6 +468,7 @@ function lmul!(p::FTPlan{Float64, 3, TETRAHEDRONSYNTHESIS}, x::Array{Float64, 3}
466468
end
467469

468470
plan_tet_analysis(x::Array{T, 3}) where T = plan_tet_analysis(T, size(x, 1), size(x, 2), size(x, 3))
471+
plan_tet_analysis(x::Array{Complex{T}, 3}) where T <: Real = plan_tet_analysis(T, size(x, 1), size(x, 2), size(x, 3))
469472

470473
function plan_tet_analysis(::Type{Float64}, n::Integer, l::Integer, m::Integer)
471474
plan = ccall((:ft_plan_tet_analysis, libfasttransforms), Ptr{ft_plan_struct}, (Cint, Cint, Cint), n, l, m)

test/libfasttransformstests.jl

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FastTransforms.set_num_threads(ceil(Int, Base.Sys.CPU_THREADS/2))
55
@testset "libfasttransforms" begin
66
n = 64
77
α, β, γ, δ, λ, μ = 0.1, 0.2, 0.3, 0.4, 0.5, 0.6
8-
for T in (Float32, Float64, BigFloat, Complex{Float32}, Complex{Float64}), Complex{BigFloat})
8+
for T in (Float32, Float64, Complex{Float32}, Complex{Float64})
99
x = T(1)./(1:n)
1010
Id = Matrix{T}(I, n, n)
1111
for (p1, p2) in ((plan_leg2cheb(Id), plan_cheb2leg(Id)),
@@ -32,7 +32,6 @@ FastTransforms.set_num_threads(ceil(Int, Base.Sys.CPU_THREADS/2))
3232
y = p2'\z
3333
z = p2\y
3434
@test z x
35-
Id = Matrix{T}(I, n, n)
3635
P = p1*Id
3736
Q = p2*P
3837
@test Q Id
@@ -53,8 +52,55 @@ FastTransforms.set_num_threads(ceil(Int, Base.Sys.CPU_THREADS/2))
5352
end
5453
end
5554

55+
for T in (BigFloat, Complex{BigFloat})
56+
x = T(1)./(1:n)
57+
Id = Matrix{T}(I, n, n)
58+
for (p1, p2) in ((plan_leg2cheb(Id), plan_cheb2leg(Id)),
59+
(plan_ultra2ultra(Id, λ, μ), plan_ultra2ultra(Id, μ, λ)),
60+
(plan_jac2jac(Id, α, β, γ, δ), plan_jac2jac(Id, γ, δ, α, β)),
61+
(plan_lag2lag(Id, α, β), plan_lag2lag(Id, β, α)),
62+
(plan_jac2ultra(Id, α, β, λ), plan_ultra2jac(Id, λ, α, β)),
63+
(plan_jac2cheb(Id, α, β), plan_cheb2jac(Id, α, β)),
64+
(plan_ultra2cheb(Id, λ), plan_cheb2ultra(Id, λ)))
65+
y = p1*x
66+
z = p2*y
67+
@test z x
68+
y = p1*x
69+
z = p1'y
70+
y = transpose(p1)*z
71+
z = transpose(p1)\y
72+
y = p1'\z
73+
z = p1\y
74+
@test z x
75+
y = p2*x
76+
z = p2'y
77+
y = transpose(p2)*z
78+
z = transpose(p2)\y
79+
y = p2'\z
80+
z = p2\y
81+
@test z x
82+
P = p1*Id
83+
Q = p2*P
84+
@test_skip Q Id
85+
P = p1*Id
86+
Q = p1'P
87+
P = transpose(p1)*Q
88+
Q = transpose(p1)\P
89+
P = p1'\Q
90+
Q = p1\P
91+
@test_skip Q Id
92+
P = p2*Id
93+
Q = p2'P
94+
P = transpose(p2)*Q
95+
Q = transpose(p2)\P
96+
P = p2'\Q
97+
Q = p2\P
98+
@test_skip Q Id
99+
end
100+
end
101+
56102
for T in (Float64, Complex{Float64})
57-
A = sphones(T, n, 2n-1)
103+
A = T <: Real ? sphones(T, n, 2n-1) : sphones(T, n, 2n-1) + im*sphones(T, n, 2n-1)
58104
p = plan_sph2fourier(A)
59105
ps = plan_sph_synthesis(A)
60106
pa = plan_sph_analysis(A)
@@ -63,7 +109,7 @@ FastTransforms.set_num_threads(ceil(Int, Base.Sys.CPU_THREADS/2))
63109
A = p\(pa*C)
64110
@test A B
65111

66-
A = sphvones(T, n, 2n-1)
112+
A = T <: Real ? sphvones(T, n, 2n-1) : sphvones(T, n, 2n-1) + im*sphvones(T, n, 2n-1)
67113
p = plan_sphv2fourier(A)
68114
ps = plan_sphv_synthesis(A)
69115
pa = plan_sphv_analysis(A)
@@ -72,7 +118,7 @@ FastTransforms.set_num_threads(ceil(Int, Base.Sys.CPU_THREADS/2))
72118
A = p\(pa*C)
73119
@test A B
74120

75-
A = diskones(T, n, 4n-3)
121+
A = T <: Real ? diskones(T, n, 4n-3) : diskones(T, n, 4n-3) + im*diskones(T, n, 4n-3)
76122
p = plan_disk2cxf(A)
77123
ps = plan_disk_synthesis(A)
78124
pa = plan_disk_analysis(A)
@@ -81,7 +127,7 @@ FastTransforms.set_num_threads(ceil(Int, Base.Sys.CPU_THREADS/2))
81127
A = p\(pa*C)
82128
@test A B
83129

84-
A = triones(T, n, n)
130+
A = T <: Real ? triones(T, n, n) : triones(T, n, n) + im*triones(T, n, n)
85131
p = plan_tri2cheb(A, α, β, γ)
86132
ps = plan_tri_synthesis(A)
87133
pa = plan_tri_analysis(A)
@@ -90,7 +136,7 @@ FastTransforms.set_num_threads(ceil(Int, Base.Sys.CPU_THREADS/2))
90136
A = p\(pa*C)
91137
@test A B
92138

93-
A = tetones(T, n, n, n)
139+
A = T <: Real ? tetones(T, n, n, n) : tetones(T, n, n, n) + im*tetones(T, n, n, n)
94140
p = plan_tet2cheb(A, α, β, γ, δ)
95141
ps = plan_tet_synthesis(A)
96142
pa = plan_tet_analysis(A)

0 commit comments

Comments
 (0)