7VIMUPV7XRRR3NTHQBBAFKUGI3Y23PSCOEY4CXQ3DVFKC2ACHN5AC
cmaybe(::Type{T}, x::Maybe) where {T} = x === nothing ? Ptr{T}() : Ref{T}(x)
function cmayberef(::Type{T}, x::Maybe{Ref{T}}) where {T}
return x === nothing ? Ptr{T}() : (x::Ref{T})
end
# For optional arguments
cmaybe(::Type{T}, x::Maybe{T}) where {T} = x === nothing ? Ptr{T}() : Ref{T}(x)
export $op
function $op(lmax::Union{Cint,Int}, z::Union{Cdouble,Float64,Int};
csphase::Maybe{Int}=nothing, cnorm::Maybe{Int}=nothing,
exitstatus::Maybe{Ref{Int}}=nothing)
p = Array{Cdouble}(undef, (lmax + 1) * (lmax + 2) ÷ 2)
export $op!
function $op!(p::AbstractVector{Cdouble}, lmax::Integer,
z::Union{AbstractFloat,Integer};
csphase::Maybe{Integer}=nothing,
cnorm::Maybe{Integer}=nothing,
exitstatus::Maybe{Ref{<:Integer}}=nothing)
@assert length(p) ≥ (lmax + 1) * (lmax + 2) ÷ 2
exitstatus′ = 0
export $op_d1
function $op_d1(lmax::Union{Cint,Int}, z::Union{Cdouble,Float64,Int};
csphase::Maybe{Int}=nothing, cnorm::Maybe{Int}=nothing,
exitstatus::Maybe{Ref{Int}}=nothing)
export $op
function $op(lmax::Integer, z::Union{AbstractFloat,Integer};
csphase::Maybe{Integer}=nothing,
cnorm::Maybe{Integer}=nothing,
exitstatus::Maybe{Ref{<:Integer}}=nothing)
dp = Array{Cdouble}(undef, (lmax + 1) * (lmax + 2) ÷ 2)
$op!(p, lmax, z; csphase=csphase, cnorm=cnorm,
exitstatus=exitstatus)
return p
end
#
export $op_d1!
function $op_d1!(p::AbstractVector{Cdouble},
dp::AbstractVector{Cdouble}, lmax::Integer,
z::Union{AbstractVector,Integer};
csphase::Maybe{Integer}=nothing,
cnorm::Maybe{Integer}=nothing,
exitstatus::Maybe{Ref{<:Integer}}=nothing)
@assert length(p) ≥ lmax + 1
@assert length(dp) ≥ lmax + 1
exitstatus′ = 0
cmaybe(Cint, cnorm), cmayberef(Cint, exitstatus))
cmaybe(Cint, cnorm), exitstatus′)
if exitstatus === nothing
exitstatus′ ≠ 0 && error("$($op_d1!): Error code $exitstatus′")
else
exitstatus[] = exitstatus′
end
return p, dp
end
#
export $op_d1
function $op_d1(lmax::Integer, z::Union{AbstractFloat,Integer};
csphase::Maybe{Integer}=nothing,
cnorm::Maybe{Integer}=nothing,
exitstatus::Maybe{Ref{<:Integer}}=nothing)
p = Array{Cdouble}(undef, (lmax + 1) * (lmax + 2) ÷ 2)
dp = Array{Cdouble}(undef, (lmax + 1) * (lmax + 2) ÷ 2)
$op_d1!(p, dp, lmax, z; csphase=csphase, cnorm=cnorm,
exitstatus=exitstatus)
export $op
function $op(lmax::Union{Cint,Int}, z::Union{Cdouble,Float64,Int};
exitstatus::Maybe{Ref{Int}}=nothing)
p = Array{Cdouble}(undef, (lmax + 1) * (lmax + 2) ÷ 2)
export $op!
function $op!(p::AbstractVector{Cdouble}, lmax::Integer,
z::Union{AbstractFloat,Integer};
exitstatus::Maybe{Ref{<:Integer}}=nothing)
@assert length(p) ≥ lmax + 1
exitstatus′ = 0
export $op_d1
function $op_d1(lmax::Union{Cint,Int}, z::Union{Cdouble,Float64,Int};
exitstatus::Maybe{Ref{Int}}=nothing)
p = Array{Cdouble}(undef, (lmax + 1) * (lmax + 2) ÷ 2)
dp = Array{Cdouble}(undef, (lmax + 1) * (lmax + 2) ÷ 2)
export $op
function $op(lmax::Integer, z::Union{AbstractFloat,Integer};
exitstatus::Maybe{Ref{<:Integer}}=nothing)
p = Array{Cdouble}(undef, lmax + 1)
$op!(p, lmax, z; exitstatus=exitstatus)
return p
end
#
export $op_d1!
function $op_d1!(p::AbstractVector{Cdouble},
dp::AbstractVector{Cdouble}, lmax::Integer,
z::Union{AbstractFloat,Integer};
exitstatus::Maybe{Ref{<:Integer}}=nothing)
@assert length(p) ≥ lmax + 1
@assert length(dp) ≥ lmax + 1
exitstatus′ = 0
lmax, z, cmayberef(Cint, exitstatus))
lmax, z, exitstatus′)
if exitstatus === nothing
exitstatus′ ≠ 0 && error("$($op_d1!): Error code $exitstatus′")
else
exitstatus[] = exitstatus′
end
return p, dp
end
#
export $op_d1
function $op_d1(lmax::Integer, z::Union{AbstractFloat,Integer};
exitstatus::Maybe{Ref{<:Integer}}=nothing)
p = Array{Cdouble}(undef, lmax + 1)
dp = Array{Cdouble}(undef, lmax + 1)
$op_d1!(p, dp, lmax, z; exitstatus=exitstatus)
p = PlmBar(4, 0)
p, dp = PlmBar_d1(4, 0)
p = PlBar(4, 0)
p, dp = PlBar_d1(4, 0)
p, dp = PlmBar_d1(4, 0)
dp′ = zeros(15)
PlmBar_d1!(p′, dp′, 4, 0)
@test p′ == p
@test dp′ == dp
p = PlBar(4, 0)
p′ = zeros(5)
PlBar!(p′, 4, 0)
@test p′ == p
p, dp = PlBar_d1(4, 0)
dp′ = zeros(5)
PlBar_d1!(p′, dp′, 4, 0)
@test p′ == p
@test dp′ == dp
end
index = PlmIndex(4, 3)
@test index == 14
p, dp = PlON_d1(4, 0)
dp′ = zeros(5)
PlON_d1!(p′, dp′, 4, 0)
@test p′ == p
@test dp′ == dp
end
@testset "PlmSchmidt" begin
p = PlmSchmidt(4, 0)
p′ = zeros(15)
PlmSchmidt!(p′, 4, 0)
@test p′ == p
p, dp = PlmSchmidt_d1(4, 0)
dp′ = zeros(15)
PlmSchmidt_d1!(p′, dp′, 4, 0)
@test p′ == p
@test dp′ == dp
p = PlSchmidt(4, 0)
p′ = zeros(5)
PlSchmidt!(p′, 4, 0)
@test p′ == p
p, dp = PlSchmidt_d1(4, 0)
dp′ = zeros(5)
PlSchmidt_d1!(p′, dp′, 4, 0)
@test p′ == p
@test dp′ == dp
end
@testset "PLegendreA" begin
p = PLegendreA(4, 0)
p′ = zeros(15)
PLegendreA!(p′, 4, 0)
@test p′ == p
p, dp = PLegendreA_d1(4, 0)
dp′ = zeros(15)
PLegendreA_d1!(p′, dp′, 4, 0)
@test p′ == p
@test dp′ == dp
p = PLegendre(4, 0)
p′ = zeros(5)
PLegendre!(p′, 4, 0)
@test p′ == p
p, dp = PLegendre_d1(4, 0)
dp′ = zeros(5)
PLegendre_d1!(p′, dp′, 4, 0)
@test p′ == p
@test dp′ == dp
end
@testset "PlmIndex" begin
index = PlmIndex(4, 3)
@test index == 14
end