-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Return views from UnitRange indexing of Arrays #9150
Conversation
Exciting stuff! I'll try to find some time over the holiday to review this. Really great to see this come along so quickly! |
@@ -360,7 +360,7 @@ function show_call(io::IO, head, func, func_args, indent) | |||
end | |||
if !isempty(func_args) && isa(func_args[1], Expr) && func_args[1].head === :parameters | |||
print(io, op) | |||
show_list(io, func_args[2:end], ',', indent, 0) | |||
show_list(io, [func_args[i] for i = 2:length(func_args)], ',', indent, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on why any show
methods would need a copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After your latest change that returns FastLinear
more often these might not be necessary, but before they returned SlowLinear
for which iteration was not defined until multidimensional.jl
or cartesian.jl
. I'll try slicing and see if it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good. Obviously, the Travis failure is the main thing to be concerned about. The other thing I'd ask is whether you just focused on test failures, or whether you also searched through |
No I haven't done that systematically, but I a taught some because of the tests. I'll have to spend some more time on making the @StefanKarpinski Would you like to express your view on the |
Given that this is a very important semantic change for 0.4 it would be good getting this in rather earlier than later. |
Everything depends on resolving #8504. |
Ah I see. Hopefully this gets resolved because IMHO this is an important change for 0.4, which I am really looking forward to |
Cherry-picked from a squashed-and-split version of #9150 to exclude the bigger change of returning views from indexing with UnitRanges. Conflicts: base/abstractarray.jl base/multidimensional.jl src/julia-syntax.scm
Cherry-picked from a squashed-and-split version of #9150 to exclude the bigger change of returning views from indexing with UnitRanges. Conflicts: base/abstractarray.jl base/multidimensional.jl src/julia-syntax.scm
Cherry-picked from a squashed-and-split version of #9150 to exclude the bigger change of returning views from indexing with UnitRanges. Conflicts: base/abstractarray.jl base/multidimensional.jl src/julia-syntax.scm
So we are planning to use Julia for space trajectory design package here at JPL and one of the thing which is hurting us is this issue of having array return slices as views. For now, we have decided to use the excellent ArrayViews package, but I wanted to know if there is a plan to address this issue anytime soon (by early 2017) ? thanks, |
@GravityAssisted array views are already part of Julia v0.4 x = randn(5, 5)
x[1:2, 3:4] # makes a copy
sub(x, 1:2, 3:4) # makes a view The syntax isn't quite as convenient, but if you intend to exclusively use views there is nothing stopping you from creating an array wrapper that defines If you need additional assistance you should contact the julia-users mailing list, which is a more suitable location for these kinds of questions. |
This syntax has been proposed for making views: x[1:2, 3:4] # copy
x@[1:2, 3:4] # view |
@GravityAssisted note that global const use_arrayviews = true
if use_arrayviews
global const sview = ArrayViews.unsafe_view
else
global const sview = sub
end and use |
It might be worth mentioning that the |
Thanks all for the quick response. I ended up using |
@andreasnoack is there much of a difference between unsafe_view and |
The inefficiency related to safe |
Thanks for the explanation. Is there plans to handle pointers allocation better? It seems like that would be necessary for applications like defining your own variable length bit types (like unums). And if so, would this inefficiency then be handled? |
I think it is but it's also (I've been told) quite difficult. Stefan talks a bit about it in his JuliaCon talk so if you haven't watched it already it might be worth doing. |
Yes |
This PR changes the behavior of array indexing to return a
SubArray
of the original array instead of anArray
. This should reduce the number of intermediate arrays allocated in computations and hopefully that change will not be notified much in casual command prompt use of Julia.I have decided to use
slice
instead ofsub
which is a change in indexing convention. However, this can easily be changed in the pull request if we decide to stick with the present convention. Because of this, I haven't adjusted thearrayops.jl
tests yet. I'll only do that when we have decided to use eithersub
orslice
. The rest of the tests should have been through the necessary adjustments.Examples:
@carlobaldassi I have made some adjustments to the
BitArray
tests because indexingArray{Bool}
now behaves differently. I haven't changed the behavior ofBitArray
indexing.I have also not made any changes to indexing of
SparseMatrixCSC
.@JeffBezanson I had to change quite a few places in
inference.jl
to avoid the creation ofSubArray
s there. You might want to take a look and see if the changes there are okay.