-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to transform from Legendre -> (1-x)^m * P_n^{2m,0} #96
Comments
For gurus only: using ApproxFun, LinearAlgebra, FastTransforms
import Base: unsafe_convert, eltype, ndims
import FastTransforms: libfasttransforms
struct ft_rotation_plan_struct end
mutable struct FTRotationPlan{T}
plan::Ptr{ft_rotation_plan_struct}
n::Int
function FTRotationPlan{T}(plan::Ptr{ft_rotation_plan_struct}, n::Int) where T
p = new(plan, n)
finalizer(destroy_rotation_plan, p)
p
end
end
eltype(p::FTRotationPlan{T}) where {T} = T
ndims(p::FTRotationPlan{T}) where {T} = 1
function checksize(p::FTRotationPlan{T}, x::Array{T}) where T
if p.n != size(x, 1)
throw(DimensionMismatch("FTRotationPlan has dimensions $(p.n) × $(p.n), x has leading dimension $(size(x, 1))"))
end
end
unsafe_convert(::Type{Ptr{ft_rotation_plan_struct}}, p::FTRotationPlan) = p.plan
destroy_rotation_plan(p::FTRotationPlan{Float64}) = ccall((:ft_destroy_rotation_plan, libfasttransforms), Cvoid, (Ptr{ft_rotation_plan_struct}, ), p)
function plan_rotsphere(::Type{Float64}, n::Integer)
plan = ccall((:ft_plan_rotsphere, libfasttransforms), Ptr{ft_rotation_plan_struct}, (Cint, ), n)
return FTRotationPlan{Float64}(plan, n)
end
function plan_rotdisk(::Type{Float64}, n::Integer)
plan = ccall((:ft_plan_rotdisk, libfasttransforms), Ptr{ft_rotation_plan_struct}, (Cint, ), n)
return FTRotationPlan{Float64}(plan, n)
end
function plan_rottriangle(::Type{Float64}, n::Integer, α, β, γ)
plan = ccall((:ft_plan_rottriangle, libfasttransforms), Ptr{ft_rotation_plan_struct}, (Cint, Float64, Float64, Float64), n, α, β, γ)
return FTRotationPlan{Float64}(plan, n)
end
function kernel_tri_hi2lo!(p::FTRotationPlan{Float64}, m::Integer, x::Vector{Float64})
checksize(p, x)
ccall((:ft_kernel_tri_hi2lo, libfasttransforms), Cvoid, (Ptr{ft_rotation_plan_struct}, Cint, Ptr{Float64}), p, m, x)
return x
end
function kernel_tri_lo2hi!(p::FTRotationPlan{Float64}, m::Integer, x::Vector{Float64})
checksize(p, x)
ccall((:ft_kernel_tri_lo2hi, libfasttransforms), Cvoid, (Ptr{ft_rotation_plan_struct}, Cint, Ptr{Float64}), p, m, x)
return x
end
m = 4
n = 10
wJ = Fun(JacobiWeight(0, m, NormalizedJacobi(0, 2m)), [1.0; zeros(Float64, n-1)])
P = Fun(x->wJ(x), NormalizedLegendre(), n)
p = plan_rottriangle(Float64, n, 0.0, -0.5, -0.5)
x = [1.0; zeros(Float64, n-1)]
# To convert down
kernel_tri_hi2lo!(p, m, x)
norm(P.coefficients - x)
# To convert back up
kernel_tri_lo2hi!(p, m, x)
|
I think this should be added to FastTransforms.jl. The best name I could come up with is
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know they are hidden in the triangle transform, is there an easy way to call it?
The text was updated successfully, but these errors were encountered: