-
-
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
improve a[...] .= handling of arrays of arrays and dicts of arrays #17568
Conversation
…d dictionaries of arrays
Hey, thanks! :) |
Once the Arraypocolypse (#13157) lands and slices become views, I think all of this So, hopefully this is all just a temporary hack for Julia 0.5. |
@StefanKarpinski, merge? |
Seems good to me. I think @JeffBezanson should probably also review it. |
Would it work to have |
Sure. |
Changed to default to |
seems considerably simpler 👍 |
|
||
dotview(args...) = getindex(args...) | ||
dotview(A::AbstractArray, args...) = view(A, args...) | ||
dotview{T<:AbstractArray}(A::AbstractArray{T}, args...) = getindex(A, args...) |
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.
@stevengj Why did you decide to default to getindex
and not view
in this case? @alanedelman showed me this example today
s = zeros(2,2)
A = fill(s, 4, 4)
A[1:3,1:3] .= [ones(2,2)]
which doesn't set A
because of this.
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.
You're right, it should be view
also. I was thinking that view
wasn't necessary, since A[i,j]
returns a mutable object.
My ideal in #17510 was to have
x .= f.(y)
be a synonym forbroadcast!(f, x, y)
. However, because slices return copies and not views, in #17546 I had to modify this so thatx[...] .= f.(y)
turns intobroadcast!(f, view(x, ...), y)
. This PR extends that solution so that in-place semantics are achieved for arrays of arrays and dictionaries of arrays, to fix a problem pointed out by @iamed2.In particular,
x[...] .= f.(y)
now turns intobroadcast!(f, Base.dotview(x, ...), y)
. Thedotview
function defaults to callingview
, but we can override it for dictionaries and arrays-of-arrays to achieve the desired semantics without affecting explicit calls toview
.