Skip to content

Regrid by applying the regridder object to dst and src arrays#16

Merged
navidcy merged 6 commits intomainfrom
ss/regridder
Sep 27, 2025
Merged

Regrid by applying the regridder object to dst and src arrays#16
navidcy merged 6 commits intomainfrom
ss/regridder

Conversation

@simone-silvestri
Copy link
Copy Markdown
Member

@navidcy what do you think about this solution?

Refactor regrid function to improve clarity and performance.
@simone-silvestri
Copy link
Copy Markdown
Member Author

This pattern is the same pattern as for Interpolations.jl and Dierckz.jl where you first build an intepolator object and then apply it as a functor (from the Dierckz.jl README):

Fit a 1-d spline to some input data (points can be unevenly spaced):

x = [0., 1., 2., 3., 4.]
y = [-1., 0., 7., 26., 63.]  # x.^3 - 1.
spl = Spline1D(x, y)

Evaluate the spline at some new points:

spl([1.5, 2.5])  # result = [2.375, 14.625]
spl(1.5)  # result = 2.375 

Comment thread src/XESMF.jl
# Mixed cases
function (regridder::Regridder)(dst::DenseVector, src::AbstractVector)
regridder.src_temp .= src
return LinearAlgebra.mul!(dst, regridder.weights, regridder.src_temp)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does LinearAlgebra.mul! return its first arg?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think so:

julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; Y = similar(B); mul!(Y, A, B)
2×2 Matrix{Float64}:
 3.0  3.0
 7.0  7.0

@navidcy navidcy self-requested a review September 26, 2025 14:07
@navidcy
Copy link
Copy Markdown
Member

navidcy commented Sep 26, 2025

I'll test this with Oceananigans and merge if all seems good

@navidcy navidcy linked an issue Sep 26, 2025 that may be closed by this pull request
@navidcy navidcy merged commit 90cc0cc into main Sep 27, 2025
5 checks passed
@navidcy navidcy deleted the ss/regridder branch September 27, 2025 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XESMF.regrid! conflicts with Oceananigans.Fields.regrid!

2 participants