-
Notifications
You must be signed in to change notification settings - Fork 3
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
Slicing static arrays? #4
Comments
I'm working on this. The syntax would be |
Ah, I missed that you explained it in README. Actually, why not extend |
I've thought about this. The problem is deciding what should be static when there are several numbers involved. Currently, there is a function |
So now, undocumented in the master branch, there's the possibility to do indexing with static numbers and get static arrays back. (Still just proof-of-concept. At the moment you get an MArray. I'll have to think about what the default should be.) There's also a new macro |
Thanks a lot! I'll play with it.
Ah, that's interesting. I was not paying attention to this. But yes, it would be great if
That's OK when |
That's correct. The most efficient code will be |
I also liked your idea of defining generators with static ranges to create static vectors. JuliaArrays/StaticArrays.jl#97 It is now possible to do, e.g. |
This is great! I just quickly played with it but it's super nice to see something like BTW, I realized that julia> x = static(1):static(2):static(5)
staticlength(1:2:5)
julia> x.zeroth
static(-1)
julia> @code_typed optimize=true first(x)
CodeInfo(
1 ─ return 1
) => Int64 Maybe I just hit some WIP portion of the code? |
The reason why (
|
And yes, the display part was work in progress. It shows as |
Yes, that was my confusion. Thanks a lot for fixing this and introducing |
Going back to the main topic of slicing static arrays using static ranges. It now works for one-dimensional indexing, but not yet for multi-dimensional indexing. I think the best course would be to hook into the existing machinery in StaticArrays. This would require making a small PR to that package (or a lot of code would need to be duplicated). I'll leave this issue open, in order to track progress. |
Re JuliaArrays/StaticArrays.jl#703 (comment):
Based on this idea, wouldn't it be better to treat julia> a = SA[1, 2, 3];
julia> b = [1, 2, 3];
julia> @stat a[1:end-1]
2-element SArray{Tuple{2},Int64,1,2} with indices SOneTo(2):
1
2
julia> @stat b[1:end-1]
2-element MArray{Tuple{2},Int64,1,2} with indices SOneTo(2):
1
2 |
With the latest release of StaticNumbers, you do get an |
I tried it in an isolated environment but I can't make it work: (tmpkaq1o1hp.julia_tmp) pkg> st
Status `/tmp/tmpkaq1o1hp.julia_tmp/Project.toml`
[90137ffa] StaticArrays v0.12.1
[c5e4b96a] StaticNumbers v0.3.1
julia> using StaticNumbers, StaticArrays
julia> b = [1, 2, 3];
julia> @stat b[1:end-1]
2-element MArray{Tuple{2},Int64,1,2} with indices SOneTo(2):
1
2 I tried |
I'm guessing what I'm seeing is expected as I see julia> @macroexpand @stat b[1:end-1]
:((StaticNumbers.maybe_wrap(b))[maybe_static(:, static(1), maybe_static(-, static(end), static(1)))]) |
OK. That's clearly a bug. Will look into it. |
Should be fixed now. |
Thanks for fixing it! BTW, it's just a bike-shedding (sorry!) but any reason why it's called |
I would definitely have preferred to name it |
Ah, of course! |
It would be great if I can do
x[static(1):static(end)-static(1)]
to get a static array (whenx
is an either static or regular array). Is it in the scope of this package?The text was updated successfully, but these errors were encountered: