Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Dec 30, 2020
1 parent 9b0125b commit b47a399
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/LegendrePolynomials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Pl_hyperdual(x::Real, l::Integer)
"Legendre Polynomials are defined for arguments lying in -1 ⩽ x ⩽ 1"))

hd1 = hyper(one(x))
hdx = hyper(x,one(x),one(x),zero(x))
hdx = hyper(x, one(x), one(x), zero(x))

if l==0
return hd1
Expand All @@ -82,7 +82,7 @@ function Pl_derivatives_allmodes!(arr::AbstractVector{<:Real}, x::Real,
lmax::Integer = maximum(axes(arr,1)), deriv=0)

# Only compute Pl
arr_hyperdual = view(Pl_hyperdual_allmodes(x,lmax),0:lmax)
arr_hyperdual = view(Pl_hyperdual_allmodes(x, lmax), 0:lmax)

@inbounds @. arr[0:lmax] = realpart(arr_hyperdual)
arr
Expand All @@ -92,10 +92,10 @@ function Pl_derivatives_allmodes!(arr::AbstractMatrix{<:Real}, x::Real,
lmax::Integer = maximum(axes(arr,1)),
deriv::Integer = maximum(axes(arr,2)))

arr_hyperdual = view(Pl_hyperdual_allmodes(x,lmax),0:lmax)
arr_hyperdual = view(Pl_hyperdual_allmodes(x, lmax), 0:lmax)

@inbounds for (d_order,f) in zip(0:deriv,(realpart,eps1,eps1eps2))
@. arr[0:lmax,d_order] = f(arr_hyperdual)
@inbounds for (d_order,f) in zip(0:deriv, (realpart,eps1,eps1eps2))
@. arr[0:lmax, d_order] = f(arr_hyperdual)
end
arr
end
Expand All @@ -114,7 +114,7 @@ end
Computes the Legendre Polynomials ``P_l(x)`` for the argument `x` and `l = 0:lmax`.
Returns an `OffsetArray` `P` with indices `0:lmax`, where `P[l] == Pl(x,l)`
"""
Pl(x::Real; lmax::Integer) = Pl_derivatives_allmodes(x,lmax,0)[:,0]
Pl(x::Real; lmax::Integer) = Pl_derivatives_allmodes(x, lmax, 0)[:,0]

"""
Pl(x::Real, l::Integer)
Expand All @@ -133,7 +133,7 @@ Computes the first derivatives of Legendre Polynomials ``d_xP_l(x)`` for the
argument `x` and `l = 0:lmax`.
Returns an `OffsetArray` `dP` with indices `0:lmax`, where `dP[l] = dPl(x,l)`
"""
dPl(x::Real; lmax::Integer) = Pl_derivatives_allmodes(x,lmax,1)[:,1]
dPl(x::Real; lmax::Integer) = Pl_derivatives_allmodes(x, lmax, 1)[:,1]

"""
dPl(x::Real, l::Integer)
Expand Down Expand Up @@ -175,7 +175,7 @@ Returns `OffsetArray`s `P` and `dP` with indices `0:lmax`, where `P[l] == Pl(x,l
`dP[l] == dPl(x,l)`.
"""
function Pl_dPl(x::Real; lmax::Integer)
P = Pl_derivatives_allmodes(x,lmax,1)
P = Pl_derivatives_allmodes(x, lmax, 1)
P[:,0], P[:,1]
end

Expand Down Expand Up @@ -235,7 +235,7 @@ Computes the the first and second derivatives of Legendre Polynomials ``d_xP_l(x
and ``d_x^2P_l(x)`` for the argument `x` and the degree `l`
"""
function dPl_d2Pl(x::Real, l::Integer)
Ph = Pl_hyperdual(x,l)
Ph = Pl_hyperdual(x, l)
eps1(Ph), eps1eps2(Ph)
end

Expand Down Expand Up @@ -279,7 +279,7 @@ The optional keyword argument `lmax` may specify the range of ``l``'s to compute
It defaults to `lmax = maximum(axes(arr,1))`
"""
Pl!(arr::AbstractVecOrMat{<:Real}, x::Real; lmax::Integer = maximum(axes(arr,1))) =
Pl_derivatives_allmodes!(arr,x,lmax,0)
Pl_derivatives_allmodes!(arr, x, lmax, 0)

"""
Pl_dPl!(arr, x; [lmax = maximum(axes(arr,1))])
Expand Down Expand Up @@ -316,14 +316,15 @@ The optional keyword argument `lmax` may specify the range of ``l``'s to compute
It defaults to `lmax = maximum(axes(arr,1))`
"""
function dPl!(arr::AbstractVector{<:Real}, x::Real; lmax::Integer = maximum(axes(arr,1)))
P = zeros(axes(arr,1),0:1)
P = zeros(axes(arr,1), 0:1)
Pl_dPl_d2Pl!(P, x; lmax = lmax)
@views @. arr = P[:,1]
arr
end

function dPl!(arr::AbstractMatrix{<:Real}, x::Real;
lmax::Integer = maximum(axes(arr,1)))

P = zeros(axes(arr,1),0:1)
Pl_dPl_d2Pl!(P, x; lmax = lmax)
@views @. arr[:,1] = P[:,1]
Expand Down

2 comments on commit b47a399

@jishnub
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/27086

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.4 -m "<description of version>" b47a399b91eaa3e50421a7056805394df971e82b
git push origin v0.2.4

Please sign in to comment.