Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of numpy's meshgrid function for ndarray #1355

Open
jreniel opened this issue Feb 2, 2024 · 6 comments · May be fixed by #1477
Open

Implementation of numpy's meshgrid function for ndarray #1355

jreniel opened this issue Feb 2, 2024 · 6 comments · May be fixed by #1477

Comments

@jreniel
Copy link

jreniel commented Feb 2, 2024

I have made an attempt to try to replicate the core functionality of numpy's meshgrid function, using ndarray.
My attempt, which seems to be yielding identical results to the numpy version is hosted here.

My hope is that this function, or an equivalent, makes it to ndarray, since I feel like meshgrid is one of those core numpy functions that we tend to use repeatedly in my field, and it would be an invaluable addition to the ndarray crate.

To be clear, I'm asking to not necessarily use the same function that I've posted here, I'll be happy too if the ndarray devs implement a better solution. All I would like to see is to have this function be a part of the ndarray collection of functions.

@ivnsch
Copy link

ivnsch commented Jan 14, 2025

Any updates on this? I also need meshgrid in rust.

@akern40
Copy link
Collaborator

akern40 commented Jan 31, 2025

@jreniel, thank you for the reference implementation! @ivnsch and jreniel, do your applications require mesh grid with an arbitrary (i.e., run-time) number of arrays? This dictates whether we can maintain the dimensionality of the output arrays in the type system, or whether we have to resort to ArrayD like jreniel's approach. Let me know; I have a working implementation that works for up to six meshgrid inputs and avoids heap allocations, and I think I can make it work for dynamic-dimensional arrays if needed.

@ivnsch
Copy link

ivnsch commented Jan 31, 2025

@akern40 sounds great! my current use case requires only a fixed number of arrays (3).

@jreniel
Copy link
Author

jreniel commented Jan 31, 2025

Hi @akern40 , sounds like great news that you are working on this!

I work with ocean and atmospheric spatial data, We often use 2D meshgrids for representing surface data, such as building rasters for bathymetry or other types of data, but the need to represent 3D water/atmos column data is also present and common.
What I can think of is that it would be nice to have both meshgrid2D and meshgrid3D versions. ND is probably an overkill, but who knows if anyone would need that in practice? (maybe some mathematicians involved in higher dimensional computations/numerics?)

Thanks again, I'm excited to know that the Rust language just keeps growing! =)

@akern40
Copy link
Collaborator

akern40 commented Jan 31, 2025

Thanks to you both for the quick responses! I'll see if I can get a PR open to add this over the weekend.

@akern40 akern40 linked a pull request Feb 1, 2025 that will close this issue
@akern40
Copy link
Collaborator

akern40 commented Feb 1, 2025

Alright, draft is up; I'd written it to be compatible with the array reference implementation in #1440, so we need to get that merged in first. But if you need it immediately, you can use the branch in #1477; it should otherwise pass all CI/CD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants