Skip to content

Commit 27cd3bc

Browse files
committed
Faster clenshaw
1 parent 5c35982 commit 27cd3bc

File tree

3 files changed

+121
-329
lines changed

3 files changed

+121
-329
lines changed

src/MultivariateOrthogonalPolynomials.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using Base, RecipesBase, ApproxFun, BandedMatrices, BlockArrays,
77

88
# package code goes here
99
import Base: values,getindex,setindex!,*, +, -, ==,<,<=,>,
10-
>=,/,^,\,,transpose, in
10+
>=,/,^,\,,transpose, in, convert
1111

1212

1313
import BandedMatrices: inbands_getindex, inbands_setindex!
@@ -68,7 +68,7 @@ include("c_tri2cheb.jl")
6868
include("Triangle.jl")
6969
include("DirichletTriangle.jl")
7070

71-
# include("clenshaw.jl")
71+
include("clenshaw.jl")
7272

7373
# include("SphericalHarmonics.jl")
7474

src/Triangle.jl

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ function getindex(C::ConcreteConversion{JacobiTriangle,JacobiTriangle,T},k::Inte
664664
end
665665

666666

667-
function Base.convert(::Type{BandedBlockBandedMatrix},S::SubOperator{T,ConcreteConversion{JacobiTriangle,JacobiTriangle,T},
667+
function Base.convert(::Type{BandedBlockBandedMatrix}, S::SubOperator{T,ConcreteConversion{JacobiTriangle,JacobiTriangle,T},
668668
Tuple{BlockRange1,BlockRange1}}) where T
669669
ret = BandedBlockBandedMatrix(Zeros,S)
670670
K1=domainspace(parent(S))
@@ -1296,74 +1296,74 @@ function getindex(D::ConcreteDerivative{TriangleWeight{JacobiTriangle},OT,T},k::
12961296
end
12971297

12981298
## Multiplication Operators
1299-
function operator_clenshaw2D(Jx,Jy,cfs::Vector{Vector{T}},x,y) where T
1300-
N=length(cfs)
1301-
S = domainspace(x)
1302-
Z=ZeroOperator(S,S)
1303-
bk1=Array{Operator{T}}(undef,N+1); fill!(bk1 , Z)
1304-
bk2=Array{Operator{T}}(undef,N+2); fill!(bk2 , Z)
1305-
1306-
Abk1x=Array{Operator{T}}(undef,N+1); fill!(Abk1x , Z)
1307-
Abk1y=Array{Operator{T}}(undef,N+1); fill!(Abk1y , Z)
1308-
Abk2x=Array{Operator{T}}(undef,N+1); fill!(Abk2x , Z)
1309-
Abk2y=Array{Operator{T}}(undef,N+1); fill!(Abk2y , Z)
1310-
1311-
for= N:-1:2
1312-
K = Block(K̃)
1313-
1314-
Bx,By=view(Jx,K,K),view(Jy,K,K)
1315-
Cx,Cy=view(Jx,K,K+1),view(Jy,K,K+1)
1316-
JxK=view(Jx,K+1,K)
1317-
JyK=view(Jy,K+1,K)
1318-
@inbounds for k=1:Int(K)
1319-
bk1[k] /= JxK[k,k]
1320-
end
1321-
1322-
bk1[Int(K)-1] -= JyK[Int(K)-1,end]/(JxK[Int(K)-1,Int(K)-1]*JyK[end,end])*bk1[Int(K)+1]
1323-
bk1[Int(K)] -= JyK[Int(K),end]/(JxK[Int(K),Int(K)]*JyK[end,end])*bk1[Int(K)+1]
1324-
bk1[Int(K)+1] /= JyK[Int(K)+1,end]
1325-
1326-
resize!(Abk2x,Int(K))
1327-
Abk2x[:]=bk1[1:Int(K)]
1328-
resize!(Abk2y,Int(K))
1329-
Abk2y[1:Int(K)-1] .= Ref(Z)
1330-
Abk2y[end]=bk1[Int(K)+1]
1331-
1332-
Abk1x,Abk2x=Abk2x,Abk1x
1333-
Abk1y,Abk2y=Abk2y,Abk1y
1334-
1335-
1336-
bk1,bk2 = bk2,bk1
1337-
resize!(bk1,Int(K))
1338-
bk1[:]=map((opx,opy)->x*opx+y*opy,Abk1x,Abk1y)
1339-
bk1[:]-=Matrix(Bx)*Abk1x+Matrix(By)*Abk1y
1340-
bk1[:]-=Matrix(Cx)*Abk2x+Matrix(Cy)*Abk2y
1341-
for k=1:length(bk1)
1342-
bk1[k]+=cfs[Int(K)][k]*I
1343-
end
1344-
end
1345-
1346-
1347-
K =Block(1)
1348-
Bx,By=view(Jx,K,K),view(Jy,K,K)
1349-
Cx,Cy=view(Jx,K,K+1),view(Jy,K,K+1)
1350-
JxK=view(Jx,K+1,K)
1351-
JyK=view(Jy,K+1,K)
1352-
1353-
bk1[1] /= JxK[1,1]
1354-
bk1[1] -= JyK[1,end]/(JxK[1,1]*JyK[2,end])*bk1[2]
1355-
bk1[2] /= JyK[2,end]
1356-
1357-
Abk1x,Abk2x=bk1[1:1],Abk1x
1358-
Abk1y,Abk2y=[bk1[2]],Abk1y
1359-
cfs[1][1]*I + x*Abk1x[1] + y*Abk1y[1] -
1360-
Bx[1,1]*Abk1x[1] - By[1,1]*Abk1y[1] -
1361-
(Matrix(Cx)*Abk2x)[1] - (Matrix(Cy)*Abk2y)[1]
1362-
end
1363-
1364-
1365-
function Multiplication(f::Fun{JacobiTriangle},S::JacobiTriangle)
1366-
S1=space(f)
1367-
op=operator_clenshaw2D(jacobioperators(S1)...,plan_evaluate(f).coefficients,jacobioperators(S)...)
1368-
MultiplicationWrapper(f,op)
1369-
end
1299+
# function operator_clenshaw2D(Jx,Jy,cfs::Vector{Vector{T}},x,y) where T
1300+
# N=length(cfs)
1301+
# S = domainspace(x)
1302+
# Z=ZeroOperator(S,S)
1303+
# bk1=Array{Operator{T}}(undef,N+1); fill!(bk1 , Z)
1304+
# bk2=Array{Operator{T}}(undef,N+2); fill!(bk2 , Z)
1305+
#
1306+
# Abk1x=Array{Operator{T}}(undef,N+1); fill!(Abk1x , Z)
1307+
# Abk1y=Array{Operator{T}}(undef,N+1); fill!(Abk1y , Z)
1308+
# Abk2x=Array{Operator{T}}(undef,N+1); fill!(Abk2x , Z)
1309+
# Abk2y=Array{Operator{T}}(undef,N+1); fill!(Abk2y , Z)
1310+
#
1311+
# for K̃ = N:-1:2
1312+
# K = Block(K̃)
1313+
#
1314+
# Bx,By=view(Jx,K,K),view(Jy,K,K)
1315+
# Cx,Cy=view(Jx,K,K+1),view(Jy,K,K+1)
1316+
# JxK=view(Jx,K+1,K)
1317+
# JyK=view(Jy,K+1,K)
1318+
# @inbounds for k=1:Int(K)
1319+
# bk1[k] /= JxK[k,k]
1320+
# end
1321+
#
1322+
# bk1[Int(K)-1] -= JyK[Int(K)-1,end]/(JxK[Int(K)-1,Int(K)-1]*JyK[end,end])*bk1[Int(K)+1]
1323+
# bk1[Int(K)] -= JyK[Int(K),end]/(JxK[Int(K),Int(K)]*JyK[end,end])*bk1[Int(K)+1]
1324+
# bk1[Int(K)+1] /= JyK[Int(K)+1,end]
1325+
#
1326+
# resize!(Abk2x,Int(K))
1327+
# Abk2x[:]=bk1[1:Int(K)]
1328+
# resize!(Abk2y,Int(K))
1329+
# Abk2y[1:Int(K)-1] .= Ref(Z)
1330+
# Abk2y[end]=bk1[Int(K)+1]
1331+
#
1332+
# Abk1x,Abk2x=Abk2x,Abk1x
1333+
# Abk1y,Abk2y=Abk2y,Abk1y
1334+
#
1335+
#
1336+
# bk1,bk2 = bk2,bk1
1337+
# resize!(bk1,Int(K))
1338+
# bk1[:]=map((opx,opy)->x*opx+y*opy,Abk1x,Abk1y)
1339+
# bk1[:]-=Matrix(Bx)*Abk1x+Matrix(By)*Abk1y
1340+
# bk1[:]-=Matrix(Cx)*Abk2x+Matrix(Cy)*Abk2y
1341+
# for k=1:length(bk1)
1342+
# bk1[k]+=cfs[Int(K)][k]*I
1343+
# end
1344+
# end
1345+
#
1346+
#
1347+
# K =Block(1)
1348+
# Bx,By=view(Jx,K,K),view(Jy,K,K)
1349+
# Cx,Cy=view(Jx,K,K+1),view(Jy,K,K+1)
1350+
# JxK=view(Jx,K+1,K)
1351+
# JyK=view(Jy,K+1,K)
1352+
#
1353+
# bk1[1] /= JxK[1,1]
1354+
# bk1[1] -= JyK[1,end]/(JxK[1,1]*JyK[2,end])*bk1[2]
1355+
# bk1[2] /= JyK[2,end]
1356+
#
1357+
# Abk1x,Abk2x=bk1[1:1],Abk1x
1358+
# Abk1y,Abk2y=[bk1[2]],Abk1y
1359+
# cfs[1][1]*I + x*Abk1x[1] + y*Abk1y[1] -
1360+
# Bx[1,1]*Abk1x[1] - By[1,1]*Abk1y[1] -
1361+
# (Matrix(Cx)*Abk2x)[1] - (Matrix(Cy)*Abk2y)[1]
1362+
# end
1363+
#
1364+
#
1365+
# function Multiplication(f::Fun{JacobiTriangle},S::JacobiTriangle)
1366+
# S1=space(f)
1367+
# op=operator_clenshaw2D(jacobioperators(S1)...,plan_evaluate(f).coefficients,jacobioperators(S)...)
1368+
# MultiplicationWrapper(f,op)
1369+
# end

0 commit comments

Comments
 (0)