jmert / AssociatedLegendrePolynomials.jl

A library for calculating the Associated Legendre polynomials
https://jmert.github.io/AssociatedLegendrePolynomials.jl/
MIT License
20 stars 2 forks source link

Use OffsetArrays #6

Open jmert opened 4 years ago

jmert commented 4 years ago

Since the Associated Legendre Polynomials are naturally 0-indexed, we should take advantage of the OffsetArrays package and work with 0-indexed arrays.

jmert commented 4 years ago

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).

jmert commented 4 years ago

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.