Skip to content

Commit 7cba684

Browse files
authored
Inplace jacobi/Legendre transforms (#81)
* inplace jacobi/Legendre transforms * tests for non-zero orders * tests for fractional orders * move inplace flag to type-domain
1 parent 0029aa7 commit 7cba684

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/Spaces/Jacobi/jacobitransform.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,31 @@ JacobiTransformPlan(chebplan::CPLAN, cjtplan::CJT) where {CPLAN,CJT} =
1111

1212
plan_transform(S::Jacobi, v::AbstractVector) =
1313
JacobiTransformPlan(plan_transform(Chebyshev(), v), plan_cheb2jac(v, S.a, S.b))
14-
*(P::JacobiTransformPlan, vals::AbstractVector) = P.cjtplan*(P.chebplan*vals)
14+
plan_transform!(S::Jacobi, v::AbstractVector) =
15+
JacobiTransformPlan(plan_transform!(Chebyshev(), v), plan_cheb2jac(v, S.a, S.b))
16+
*(P::JacobiTransformPlan, vals::AbstractVector) = lmul!(P.cjtplan, P.chebplan * vals)
1517

1618

17-
struct JacobiITransformPlan{T,CPLAN,CJT} <: AbstractTransformPlan{T}
19+
struct JacobiITransformPlan{T,CPLAN,CJT,inplace} <: AbstractTransformPlan{T}
1820
ichebplan::CPLAN
1921
icjtplan::CJT
2022
end
2123

22-
JacobiITransformPlan(chebplan::CPLAN, cjtplan::CJT) where {CPLAN,CJT} =
23-
JacobiITransformPlan{eltype(chebplan),CPLAN,CJT}(chebplan, cjtplan)
24-
24+
JacobiITransformPlan(chebplan, cjtplan) = JacobiITransformPlan{false}(chebplan, cjtplan)
25+
JacobiITransformPlan{inplace}(chebplan::CPLAN, cjtplan::CJT) where {CPLAN,CJT,inplace} =
26+
JacobiITransformPlan{eltype(chebplan),CPLAN,CJT,inplace}(chebplan, cjtplan)
2527

28+
inplace(J::JacobiITransformPlan{<:Any,<:Any,<:Any,IP}) where {IP} = IP
2629

2730
plan_itransform(S::Jacobi, v::AbstractVector) =
2831
JacobiITransformPlan(plan_itransform(Chebyshev(), v), plan_jac2cheb(v, S.a, S.b))
29-
*(P::JacobiITransformPlan, cfs::AbstractVector) = P.ichebplan*(P.icjtplan*cfs)
32+
plan_itransform!(S::Jacobi, v::AbstractVector) =
33+
JacobiITransformPlan{true}(plan_itransform!(Chebyshev(), v), plan_jac2cheb(v, S.a, S.b))
34+
icjt(P, cfs, ::Val{true}) = lmul!(P, cfs)
35+
icjt(P, cfs, ::Val{false}) = P * cfs
36+
function *(P::JacobiITransformPlan, cfs::AbstractVector)
37+
P.ichebplan * icjt(P.icjtplan, cfs, Val(inplace(P)))
38+
end
3039

3140

3241
function coefficients(f::AbstractVector{T}, a::Jacobi, b::Chebyshev) where T

test/JacobiTest.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using ApproxFunOrthogonalPolynomials, ApproxFunBase, Test, SpecialFunctions, LinearAlgebra
22
import ApproxFunBase: testbandedbelowoperator, testbandedoperator, testspace, testtransforms, Vec,
33
maxspace, NoSpace, hasconversion, testfunctional,
4-
reverseorientation, ReverseOrientation
4+
reverseorientation, ReverseOrientation, transform!, itransform!
55
import ApproxFunOrthogonalPolynomials: jacobip
66

77
@testset "Jacobi" begin
@@ -33,6 +33,21 @@ import ApproxFunOrthogonalPolynomials: jacobip
3333
@testset "Conversion" begin
3434
testtransforms(Jacobi(-0.5,-0.5))
3535
@test norm(Fun(Fun(exp),Jacobi(-.5,-.5))-Fun(exp,Jacobi(-.5,-.5))) < 300eps()
36+
37+
@testset "inplace transform" begin
38+
for T in [Float32, Float64, BigFloat]
39+
for v in Any[rand(T, 10), rand(complex(T), 10)]
40+
v2 = copy(v)
41+
for a in 0:0.5:3, b in 0:0.5:3
42+
J = Jacobi(a, b)
43+
transform!(J, v)
44+
@test transform(J, v2) v
45+
itransform!(J, v)
46+
@test v2 v
47+
end
48+
end
49+
end
50+
end
3651
end
3752

3853
@testset "Derivative" begin

0 commit comments

Comments
 (0)