-
Notifications
You must be signed in to change notification settings - Fork 32
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
Grid.build_face_edges_connectivity #205
Comments
@hongyuchen1030 Have you had a look at the I'll also ping @Huite for any feedback and to start up a similar discussion to #130 (comment) Relevant References https://deltares.github.io/xugrid/examples/connectivity.html https://github.com/Deltares/xugrid/blob/main/xugrid/ugrid/connectivity.py#L231 |
Thank you for your information. I will take a look at it. |
After studying the XUGRID, I have some questions:
@Huite Thank you very much for your codes and it helps a lot with my python vectorizations. However, about the questions above, I would like to know if I missed something about your implementations of these marginal cases. @philipc2 And thank you for your help again, after a careful walk-through of the XUGRID codes, I think my implementation ways might be more suitable with the XARRAY. But I definitely will make it more python styles by referring to the usages in the XUGRID. |
Do you have specific questions? I'll just make a couple of remarks here, also from briefly reading through #189.
You also ask about numba in #202. Numba primarily works with numpy arrays. It understands (reimplements) many numpy functions and methods. As long as your functions consume and produce numpy arrays you can easily mix vectorized (numpy) functions and numba compiled functions. I've chosen to use mostly vectorized numpy (and scipy sparse) function. This results in a significantly shorter code, but it's not necessarily much more readable. But if you're dealing with permutations of permutations, it's not trivial to keep in mind anyway I see you're using a Python set. Python sets should be pretty fast (we'd expect pretty optimized C code in the background), but numpy.unique should find unique values faster. Interestingly though, with just ad hoc some benchmarking, it looks like the import numpy as np
import numpy_indexed as npi
nodes = np.arange(2_000_000)
a = np.random.choice(nodes, 500_000)
b = np.random.choice(nodes, 500_000)
edges = np.column_stack((a, b))
%timeit set(tuple(row) for row in edges)
%timeit np.unique(edges, axis=0)
%timeit npi.unique(edges, axis=0)
# 631 ms ± 33.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
# 261 ms ± 3.43 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
# 116 ms ± 903 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) Note that you can return the index and the inverse from the unique calls as well at essentially no cost, which can be rather useful! |
Hi @Huite Thank you so much for your explanation, that helps a lot. I think my understanding of the And thank you for the information about |
Implement
Grid.build_face_edges_connectivity
The text was updated successfully, but these errors were encountered: