Skip to content

Commit ae92c07

Browse files
authored
Inplace ultraspherical transform (#95)
* inplace ultraspherical transform * version bump to v0.5.3 * add tests for integer orders * invtransform tests
1 parent 746547a commit ae92c07

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunOrthogonalPolynomials"
22
uuid = "b70543e2-c0d9-56b8-a290-0d4d6d4de211"
3-
version = "0.5.7"
3+
version = "0.5.8"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Spaces/Ultraspherical/Ultraspherical.jl

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,50 +41,58 @@ canonicalspace(S::Ultraspherical) = Chebyshev(domain(S))
4141
pointscompatible(A::Ultraspherical, B::Chebyshev) = domain(A) == domain(B)
4242
pointscompatible(A::Chebyshev, B::Ultraspherical) = domain(A) == domain(B)
4343

44-
struct UltrasphericalPlan{CT,FT}
44+
struct UltrasphericalPlan{CT,FT,IP}
4545
chebplan::CT
4646
cheb2legplan::FT
4747

48-
UltrasphericalPlan{CT,FT}(cp,c2lp) where {CT,FT} = new{CT,FT}(cp,c2lp)
48+
UltrasphericalPlan{CT,FT}(cp,c2lp,::Val{IP}) where {CT,FT,IP} = new{CT,FT,IP}(cp,c2lp)
4949
end
5050

51-
struct UltrasphericalIPlan{CT,FT}
51+
struct UltrasphericalIPlan{CT,FT,IP}
5252
chebiplan::CT
5353
leg2chebplan::FT
5454

55-
UltrasphericalIPlan{CT,FT}(cp,c2lp) where {CT,FT} = new{CT,FT}(cp,c2lp)
55+
UltrasphericalIPlan{CT,FT}(cp,c2lp,::Val{IP}) where {CT,FT,IP} = new{CT,FT,IP}(cp,c2lp)
5656
end
5757

58-
function UltrasphericalPlan::Number,vals)
58+
function UltrasphericalPlan::Number,vals,inplace = Val(false))
5959
if λ == 0.5
60-
cp = plan_transform(Chebyshev(),vals)
60+
cp = ApproxFunBase._plan_transform!!(inplace)(Chebyshev(),vals)
6161
c2lp = plan_cheb2leg(eltype(vals),length(vals))
62-
UltrasphericalPlan{typeof(cp),typeof(c2lp)}(cp,c2lp)
62+
UltrasphericalPlan{typeof(cp),typeof(c2lp)}(cp,c2lp,inplace)
6363
else
6464
error("Not implemented")
6565
end
6666
end
6767

68-
function UltrasphericalIPlan::Number,cfs)
68+
function UltrasphericalIPlan::Number,cfs,inplace = Val(false))
6969
if λ == 0.5
70-
cp=plan_itransform(Chebyshev(),cfs)
70+
cp = ApproxFunBase._plan_itransform!!(inplace)(Chebyshev(),cfs)
7171
c2lp=plan_leg2cheb(eltype(cfs),length(cfs))
72-
UltrasphericalIPlan{typeof(cp),typeof(c2lp)}(cp,c2lp)
72+
UltrasphericalIPlan{typeof(cp),typeof(c2lp)}(cp,c2lp,inplace)
7373
else
7474
error("Not implemented")
7575
end
7676
end
7777

78-
*(UP::UltrasphericalPlan,v::AbstractVector) =
78+
*(UP::UltrasphericalPlan{<:Any,<:Any,false},v::AbstractVector) =
7979
UP.cheb2legplan*(UP.chebplan*v)
80-
*(UP::UltrasphericalIPlan,v::AbstractVector) =
80+
*(UP::UltrasphericalIPlan{<:Any,<:Any,false},v::AbstractVector) =
8181
UP.chebiplan*(UP.leg2chebplan*v)
8282

83+
*(UP::UltrasphericalPlan{<:Any,<:Any,true},v::AbstractVector) =
84+
lmul!(UP.cheb2legplan, UP.chebplan*v)
85+
*(UP::UltrasphericalIPlan{<:Any,<:Any,true},v::AbstractVector) =
86+
UP.chebiplan * lmul!(UP.leg2chebplan, v)
8387

8488
plan_transform(sp::Ultraspherical{Int},vals::AbstractVector) = CanonicalTransformPlan(sp,vals)
89+
plan_transform!(sp::Ultraspherical{Int},vals::AbstractVector) = CanonicalTransformPlan(sp,vals,Val(true))
8590
plan_transform(sp::Ultraspherical,vals::AbstractVector) = UltrasphericalPlan(order(sp),vals)
91+
plan_transform!(sp::Ultraspherical,vals::AbstractVector) = UltrasphericalPlan(order(sp),vals,Val(true))
8692
plan_itransform(sp::Ultraspherical{Int},cfs::AbstractVector) = ICanonicalTransformPlan(sp,cfs)
93+
plan_itransform!(sp::Ultraspherical{Int},cfs::AbstractVector) = ICanonicalTransformPlan(sp,cfs,Val(true))
8794
plan_itransform(sp::Ultraspherical,cfs::AbstractVector) = UltrasphericalIPlan(order(sp),cfs)
95+
plan_itransform!(sp::Ultraspherical,cfs::AbstractVector) = UltrasphericalIPlan(order(sp),cfs,Val(true))
8896

8997
## Construction
9098

test/UltrasphericalTest.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,23 @@ import ApproxFunOrthogonalPolynomials: jacobip
4949
end
5050
end
5151
end
52+
53+
@testset "inplace transform" begin
54+
@testset for T in [Float32, Float64, ComplexF32, ComplexF64]
55+
v = rand(T, 4)
56+
vc = copy(v)
57+
@testset for d in Any[(), (0..1,)], order in Any[0.5, 1, 3]
58+
S = Ultraspherical(order, d...)
59+
v2 = transform(S, v)
60+
if order == 0.5
61+
@test v2 transform(Legendre(domain(S)), v)
62+
end
63+
transform!(S, v)
64+
@test v v2
65+
itransform!(S, v)
66+
@test v vc
67+
@test v itransform(S, v2)
68+
end
69+
end
70+
end
5271
end

0 commit comments

Comments
 (0)