-
Notifications
You must be signed in to change notification settings - Fork 43
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
intersection math on DimArray
#914
Comments
Basic math on a Most likely math is more consistently and broadly implemented here than with xarray. Even functions from a third party julia packages we don't know about will usually work. So julia> a = rand(X(3), Y(4))
┌ 3×4 DimArray{Float64, 2} ┐
├──────────────────────────┴─────────────────────────────── dims ┐
↓ X, → Y
└────────────────────────────────────────────────────────────────┘
0.356113 0.848334 0.60161 0.401837
0.722693 0.546814 0.668194 0.0447609
0.502677 0.820793 0.0470841 0.657557
julia> b = rand(X(3), Y(4))
┌ 3×4 DimArray{Float64, 2} ┐
├──────────────────────────┴─────────────────────────────── dims ┐
↓ X, → Y
└────────────────────────────────────────────────────────────────┘
0.371906 0.209425 0.971638 0.263029
0.290974 0.489066 0.827357 0.997566
0.704057 0.636763 0.480227 0.365513
julia> a - b
┌ 3×4 DimArray{Float64, 2} ┐
├──────────────────────────┴─────────────────────────────── dims ┐
↓ X, → Y
└────────────────────────────────────────────────────────────────┘
-0.0157936 0.63891 -0.370027 0.138808
0.431719 0.0577473 -0.159164 -0.952805
-0.20138 0.184029 -0.433143 0.292044 Additionally, its usually a bad idea to change methods like these yourself. |
What you are talking about is custom operations that don't really map to Julia In Julia we try not to change the semantics of base methods or cause any ambiguities with what would happen to a regular array (because this means DimArray will work everywhere a regular array will without bugs). What I would do instead, and we could even add to the package is add something like an |
You are losing dimensions because of This does a bit better: function intersecting(f, a::DimArray, b::DimArray)
shared_selectors = DimSelectors(a)[DimSelectors(b)]
data = f(a[shared_selectors], b[shared_selectors])
end Then: julia> intersecting(-, a, b)
3×4 Matrix{Float64}:
-0.0157936 0.63891 -0.370027 0.138808
0.431719 0.0577473 -0.159164 -0.952805
-0.20138 0.184029 -0.433143 0.292044 But selecting |
Hi Rafael, thank you for your thoughtful response regarding the implementation of custom operations. |
Great. I will first look at fixing DimSelectors/DimIndices etc so the output is a DimArray through multiple selections, then we can add something like Can you think of a better name? That's really the hardest thing here. |
I would suggest |
Ah good point. |
Maybe |
Ok good ideas. Will see what seems best in the PR |
I am not entirely convinced that we need a special function for that. If this is only going to be two lines of code that might also be properly documented in a how to and not added as a special function. Especially since there are the keyword arguments to the two DimSelectors that we would have to deal with. |
The biggest thing is the But I'm not sure everyone will be able to figure that out even when it works? I don't know if lazy |
The first problem was just a minor bug, fixed in #915 Then we can see if we need the function too. But the output is now: julia> intersecting(-, a, b)
┌ 3×4 DimArray{Float64, 2} ┐
├──────────────────────────┴─────────────────────────────── dims ┐
↓ X, → Y
└────────────────────────────────────────────────────────────────┘
-0.537523 -0.768356 0.284044 0.269776
-0.0890164 -0.535661 -0.246372 -0.647103
-0.656387 0.370359 -0.681565 -0.266145 |
I tried to mimic
xarray
behavorior for doing basic math (result only contains intersected coordinates)However the shared_selectors does not keep dimension as original one. Is there anyway to do the basic math?
The text was updated successfully, but these errors were encountered: