Skip to content

Commit 1f4d91c

Browse files
committed
points and transform for DuffyCone
1 parent e81ad6c commit 1f4d91c

File tree

3 files changed

+51
-28
lines changed

3 files changed

+51
-28
lines changed

src/Cone/Cone.jl

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -170,46 +170,62 @@ spacescompatible(::LegendreCone, ::LegendreCone) = true
170170
domain(::DuffyCone) = Cone()
171171
domain(::LegendreCone) = Cone()
172172

173-
tensorizer(K::DuffyCone) = BallTensorizer()
174-
tensorizer(K::LegendreCone) = BallTensorizer()
173+
ConeTensorizer() = Tensorizer((Ones{Int}(∞),Base.OneTo(∞)))
174+
175+
tensorizer(K::DuffyCone) = ConeTensorizer()
176+
tensorizer(K::LegendreCone) = ConeTensorizer()
175177

176178
rectspace(::DuffyCone) = NormalizedJacobi(0,1,Segment(1,0))*ZernikeDisk()
177179

178-
function points(sp::Cone,n)
179-
pts=Array{float(eltype(domain(sp)))}(undef,0)
180-
a,b = sp.spaces
181-
if isfinite(dimension(a)) && isfinite(dimension(b))
182-
N,M=dimension(a),dimension(b)
183-
elseif isfinite(dimension(a))
184-
N=dimension(a)
185-
M=n÷N
186-
elseif isfinite(dimension(b))
187-
M=dimension(b)
188-
N=n÷M
189-
else
190-
N=M=round(Int,sqrt(n))
191-
end
180+
blocklengths(d::DuffyCone) = blocklengths(rectspace(d))
192181

193-
for y in points(b,M), x in points(a,N)
182+
function points(sp::DuffyCone,n)
183+
N = ceil(Int, n^(1/3))
184+
pts=Array{float(eltype(domain(sp)))}(undef,0)
185+
a,b = rectspace(sp).spaces
186+
for y in points(a,N), x in points(b,N^2)
194187
push!(pts,Vec(x...,y...))
195188
end
196-
pts
189+
conemap.(pts)
197190
end
198191

199192

200-
points(::Cone, n) = conemap.(points(rectspace(DuffyCone()), n))
201193
checkpoints(::Cone) = conemap.(checkpoints(rectspace(DuffyCone())))
202194

203195

204-
function plan_transform(sp::DuffyCone, n::AbstractVector)
205-
rs = rectspace(S)
206-
P = TransformPlan(sp,((plan_transform(sp.spaces[1],T,N),N), (plan_transform(sp.spaces[2],T,M),M)), Val{false})
207-
TransformPlan(S, P, Val{false})
196+
function plan_transform(sp::DuffyCone, n::AbstractVector{T}) where T
197+
rs = rectspace(sp)
198+
N = ceil(Int, length(n)^(1/3))
199+
M = length(points(rs.spaces[2], N^2))
200+
@assert N*M == length(n)
201+
TransformPlan(sp,((plan_transform(rs.spaces[1],T,N),N), (plan_transform(rs.spaces[2],T,M),M)), Val{false})
208202
end
209203
plan_itransform(S::DuffyCone, n::AbstractVector) =
210204
ITransformPlan(S, plan_itransform(rectspace(S),n), Val{false})
211205

212-
*(P::TransformPlan{<:Any,<:DuffyCone}, v::AbstractArray) = P.plan*v
206+
function *(T::TransformPlan{<:Any,<:DuffyCone,true}, M::AbstractMatrix)
207+
n=size(M,1)
208+
209+
for k=1:size(M,2)
210+
M[:,k]=T.plan[1][1]*M[:,k]
211+
end
212+
for k=1:n
213+
M[k,:] = (T.plan[2][1]*M[k,:])[1:size(M,2)]
214+
end
215+
M
216+
end
217+
218+
function *(T::TransformPlan{<:Any,<:DuffyCone,true},v::AbstractVector)
219+
N,M = T.plan[1][2],T.plan[2][2]
220+
V=reshape(v,N,M)
221+
fromtensor(T.space,T*V)
222+
end
223+
224+
function *(T::TransformPlan{<:Any,SS,false},v::AbstractVector) where {SS<:DuffyCone}
225+
P = TransformPlan(T.space,T.plan,Val{true})
226+
P*AbstractVector{rangetype(SS)}(v)
227+
end
228+
213229
*(P::ITransformPlan{<:Any,<:DuffyCone}, v::AbstractArray) = P.plan*v
214230

215231
evaluate(cfs::AbstractVector, S::DuffyCone, txy) = evaluate(cfs, rectspace(S), ipolar(txy[Vec(2,3)]))

src/MultivariateOrthogonalPolynomials.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ import ApproxFunBase: DirectSumSpace, AbstractProductSpace, factor,
4848
BivariateFun, ProductFun, LowRankFun, lap, columnspace,
4949
blockbandwidths, subblockbandwidths, fromtensor, totensor, isbandedblockbanded,
5050
Tensorizer, tensorizer, block, blockstart, blockstop, blocklengths,
51-
domaintensorizer, rangetensorizer, blockrange, Block, BlockRange1
51+
domaintensorizer, rangetensorizer, blockrange, Block, BlockRange1,
52+
float
5253

5354
# Singularities
5455
import ApproxFunBase: WeightSpace, weight

test/test_cone.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ApproxFun, MultivariateOrthogonalPolynomials, StaticArrays, Test
1+
using ApproxFun, MultivariateOrthogonalPolynomials, StaticArrays, FillArrays, Test
22
import ApproxFunBase: checkpoints
33
import MultivariateOrthogonalPolynomials: rectspace, totensor, duffy2legendreconic!, legendre2duffyconic!, c_plan_rottriangle, plan_transform
44

@@ -76,9 +76,15 @@ end
7676
end
7777

7878
@testset "DuffyCone" begin
79+
p = points(DuffyCone(), 10)
80+
@test p isa Vector{SVector{3,Float64}}
81+
P = plan_transform(DuffyCone(), Vector{Float64}(undef, length(p)))
82+
83+
@test P * fill(1.0, length(p)) [1.2533141373154997; Zeros(164)] [Fun((x,y) -> 1, ZernikeDisk()).coefficients; Zeros(164)]
84+
7985
f = Fun((t,x,y) -> 1, DuffyCone(), 10)
80-
@test f.coefficients [1; zeros(ncoefficients(f)-1)]
81-
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) 1
86+
@test f.coefficients [1.2533141373154997; Zeros(164)]
87+
@test f(0.3,0.1,0.2) 1
8288

8389
f = Fun((t,x,y) -> t, DuffyConic(), 10)
8490
@test f(sqrt(0.1^2+0.2^2),0.1,0.2) sqrt(0.1^2+0.2^2)

0 commit comments

Comments
 (0)