DataInterpolations.jl icon indicating copy to clipboard operation
DataInterpolations.jl copied to clipboard

refactor: methods for higher dim arrays

Open sathvikbhagavan opened this issue 1 year ago • 8 comments

  • [x] QuadraticInterpolation
  • [x] LagrangeInterpolation
  • [x] AkimaInterpolation
  • [x] ConstantInterpolation
  • [x] QuadraticSpline
  • [x] CubicHermiteSpline
  • [x] QuinticHermiteSpline
  • [ ] Derivatives
  • [ ] Integrals
  • [ ] Show methods for higher dim arrays
  • [ ] Add tests for all

sathvikbhagavan avatar Oct 17 '24 21:10 sathvikbhagavan

This adds methods for BSplines: https://github.com/SciML/DataInterpolations.jl/pull/349

ashutosh-b-b avatar Oct 19 '24 09:10 ashutosh-b-b

Cool, I will add the rest.

sathvikbhagavan avatar Oct 19 '24 10:10 sathvikbhagavan

There is one more issue that needs to be added to the checklist. The show methods fail when in Array{T, N} N >= 3

ashutosh-b-b avatar Oct 19 '24 10:10 ashutosh-b-b

Yes, I am aware about that. Added it to the checklist.

sathvikbhagavan avatar Oct 19 '24 10:10 sathvikbhagavan

Do we need to write different dispatches for Vector{Vector} implementation of BSplines? Essentially we can get away with:

BSplineInterpolation(u::AbstractVector{<:AbstractVector}, args...; kw...) = BSplineInterpolation(reduce(hcat, u), args...; kw...)
# Same for BSplineApprox

ashutosh-b-b avatar Oct 22 '24 03:10 ashutosh-b-b

reduce(hcat, u) is a fairly expensive operation.

ChrisRackauckas avatar Oct 22 '24 13:10 ChrisRackauckas

reduce(hcat, u) is a fairly expensive operation.

But in existing methods we do it anyways. For example in the method for CubicSplines{Vector{Vector}} we do a reduce(hcat, d) down here: https://github.com/SciML/DataInterpolations.jl/blob/76c545b0607bb477846464033bbbad20a7f8e65b/src/interpolation_caches.jl#L522 And the complexity of this reduce(hcat) is the same as reduce(hcat, u) . Similarly for BSplines: we do a matrix division right here: https://github.com/SciML/DataInterpolations.jl/blob/76c545b0607bb477846464033bbbad20a7f8e65b/src/interpolation_caches.jl#L662 which will need a reduce(hcat) over all vector of vectors.

Meanwhile, all of this happens during the construction of the interpolation function. So we donot loose on performance while actually interpolating.

ashutosh-b-b avatar Oct 23 '24 04:10 ashutosh-b-b

Doing it once for construction is fine.

But note that only works for the linear algebra. If you do that, you will change the type of the output, so something like a ComponentArray will loose its type and structure.

ChrisRackauckas avatar Oct 24 '24 04:10 ChrisRackauckas