sisl / GridInterpolations.jl

Multidimensional grid interpolation in arbitrary dimensions
Other
52 stars 12 forks source link

Remove allocations in interpolants(grid::RectangleGrid, x::AbstractVector) and interpolate using view #42

Closed himanshugupta1009 closed 8 months ago

himanshugupta1009 commented 8 months ago

1) Modified the interpolants function to return a view of grid.index and grid.weight instead of slicing it (gets rid of allocations). 2) Modified the interpolate function to avoid allocation (data[index] was causing allocations).

Performance comparison

Before these modifications

Screenshot from 2023-12-12 15-46-11

After these modifications

Screenshot from 2023-12-12 15-46-43

If there are any issues with it, please let me know. Thanks!

tawheeler commented 8 months ago

Overall this change looks great to me. I'm surprised dot was contributing to allocations, but the data does not lie. Thank you!

Could the indentation of the code be adjusted to match with the existing code? Usually that delta is a matter of tabs vs. spaces.

himanshugupta1009 commented 8 months ago

@tawheeler I think the allocation was due to the argument that was being passed to the dot function (data[index]).

I didn't realize the indentation mismatch before. Thank you for pointing it out. I have replaced tabs with spaces and it now matches the existing code.