-
Notifications
You must be signed in to change notification settings - Fork 42
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
WIP: Access the values of an axis with getproperty #152
base: master
Are you sure you want to change the base?
Conversation
I do think it's very important to have a better way to access the values of an axis, and this seems as good as any. |
0b36ee6
to
12aad27
Compare
Cool, I've added
I'm not sure whether |
CI failures seem to be an unrelated problem in a different test (only on julia master) |
I would implement There is currently no public interface to get Inferred tests are really good! I would test that |
12aad27
to
7151cff
Compare
Oh, excellent point, I didn't know about that the |
This is particularly useful and succinct when you're working on domain specific data with known axis names.
7151cff
to
25a66e3
Compare
Documenter CI failures should be fixed by #153 |
Test failure on nightly is addressed by JuliaArrays/OffsetArrays.jl#62. I really like this---I'd even favor it as a way of resolving the issue of renaming But there's one niggling issue: do you return the range values or the corresponding for i in eachindex(A.time)
timeslice = @view A[A.time(i)]
...
end |
I think then we need a public interface for getting the values of an axis. But perhaps now that we have the possibility of deprecating field access with
At the very least the multi-arg version should be deprecated IMO |
Agreed, good question. The reason I didn't do this was because the user already knows (syntactically) which axis name they're accessing, so it seemed redundant to return the wrapped value. So far in practical use this has been the right decision in most cases, but occasionally I've needed to re-wrap the axis which is annoying. One solution would be to make the However as the package is currently implemented, |
Perhaps we should do this. I'm a bit cautious about So for this reason I'm not sure Would it make more sense just merge |
So thinking about the But then I wondered whether This would be a breaking change of course, because the We could just have a function
@andyferris I know you've been thinking hard about things very much like this, I'd appreciate your thoughts! |
Merging the two is hard, see #81. Fundamentally the problem is that we're pretty committed to the notion that |
I have a swirling of thoughts in this space. Sorry, they are a bit disorganized.
Technically, |
My only point was that if |
Thanks Tim, it looks like @mbauman has already done versions of
Having thought about it a bit more it does seem that we need the latter as a thing to return from
Yes, I was trying to suggest that the return of |
Right. #81 looks like great work. I'm in favour of using You still need a convenient way of accessing axis values, of course (hence this PR I suppose). So yes, |
Just be aware that #58 could kill this (concept: I collected images with non-uniform sampling time): julia> import AxisArrays
julia> using AxisArrays: AxisArray, Axis
julia> img0 = rand(100, 100, 8);
julia> img = AxisArray(img0, Axis{:y}(1:100), Axis{:x}(1:100), Axis{:time}(sort(rand(8))));
julia> AxisArrays.axes(img)
(Axis{:y,UnitRange{Int64}}(1:100), Axis{:x,UnitRange{Int64}}(1:100), Axis{:time,Array{Float64,1}}([0.0157872, 0.252618, 0.284213, 0.452175, 0.806429, 0.809029, 0.850077, 0.960828])) (And yes, we're actually doing that in practice these days.) Dang we need traits. |
I didn't follow - what does #58 kill?
I can really see why you need something like AxisArrays to keep track of the relevant data. A couple of quick questions (since I'm thinking of how to implement multi-dimensional dictionaries) - do you find you often need to access the
:) |
Sorry, what I meant was that if |
Most often we iterate over the time axis. Rarely indexed by |
Right! This is precisely why I’m interested in dictionaries. A dictionary is a container where lookup from key to value is fast. What you wrote is basically a multidimensional sort-based dictionary; there is a logarithmic time algorithm to find a given Some axes might be categorical and be suited to a hash-based approach. Others might be small and brute-force lookup may be best (or else be “static” as in StaticArrays). A multidimensional dictionary should seemlessly handle all the cases from a dense ND array to a hash map with full efficiently. |
This has always seemed super clunky to me for i in AxisArrays.axes(img, Axis{:x}())
...
end
We do this a lot as well. For me, the flexibility to have non-uniform sampling is a large advantage of |
Here's one possible use for
getproperty
with anAxisArray
. I'm not yet sure this is a good idea (being an extremely new user ofAxisArrays
), but it seems rather convenient. [Edit: After a few days of using this I'd say that it's extremely convenient.]A small demo in a signal processing-like context: