AssociatedLegendrePolynomials.jl
AssociatedLegendrePolynomials.jl copied to clipboard
Use OffsetArrays
Since the Associated Legendre Polynomials are naturally 0-indexed, we should take advantage of the OffsetArrays package and work with 0-indexed arrays.
It looks like CustomUnitRanges.jl provides a ZeroRange type which will probably be needed to get 0-indexed OffsetArrays without the overhead of an unknown start index (as I expect will happen if you use regular UnitRanges).
OffsetArrays store an offset as a struct field, so the fact that CustomUnitRanges.jl provides a type-based zero-indexed range type doesn't actually lift the indexing calculations to the type domain/compile time.
I haven't yet checked whether LLVM can lift the index offset out of the inner loops to avoid the overhead or not, but as a practical matter it might be easier to instead add an interface which accepts OffsetArray inputs, validates the range of the degree/order dimensions has a zero starting index, and then passes the underlying parent Arrays to the inner calculation function. That way OffsetArrays also becomes an optional interface rather than a necessary one.