-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fix for setindex!
with array values
#16
Fix for setindex!
with array values
#16
Conversation
# This will still return `false` for scenarios such as | ||
# | ||
# setindex!!([1, 2, 3], [4, 5, 6], :, 1) | ||
# | ||
# which are in fact valid. However, this cases are rare. | ||
(_index_dimension(indices) == M || _index_dimension(indices) == 1) |
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.
Possibly stupid idea: could we just do >= M instead of == M?
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 don't have a good intuition for that. I guess the question would be: can we cook up an example that would be incorrect / error if we did >=
?
I'd also wager that we could use some functionality from |
Would love some feedback on this! @MasonProtter maybe?:) |
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.
Hey @torfjelde I'm really sorry for the slow reply. This looks like it's on the right track, but I think there's still some cases that need to be caught, like I think this won't work with
setindex!([1,2,3,4,5,6], [7,8,9], 1:3)
right?
Maybe in possible
, a better thing to do would be to test if
size(view(collection, indices...)) == size(value)
? Do you foresee any problems with that? Or maybe this isn't even possible
's job, and we should instead throw an error inside the setindex!!
impl if they give indices that don't make sense with the size of the value being inserted.
src/base.jl
Outdated
::C, | ||
::T, | ||
indices::Vararg | ||
) where {M, C <: AbstractArray{<:Real}, T <: AbstractArray{<:Real,M}} |
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.
Why the restrictions to <:Real
here?
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 don't remember tbh 😕 Might have been me just wanting to limit the extent of this change to avoid potential bugs.
# This will still return `false` for scenarios such as | ||
# | ||
# setindex!!([1, 2, 3], [4, 5, 6], :, 1) | ||
# | ||
# which are in fact valid. However, this cases are rare. | ||
(_index_dimension(indices) == M || _index_dimension(indices) == 1) |
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 don't have a good intuition for that. I guess the question would be: can we cook up an example that would be incorrect / error if we did >=
?
@torfjelde what can I do to help get this PR moving again? Is it still causing problems with Turing? |
That example does work as it hits the
I was under the impression that we wanted to avoid runtime checks in
Sorry about the delay Mason; we just "addressed" this by type-piracy for now so kind of filed this PR away. But I think the current version is working, it's just a matter of determining the scope of the change, i.e. should it also apply to non- |
huh yeah I'm not sure what I was thinking of then, sorry for the noise.
Not at all a problem, I just wanted to make sure this good work you've done here doesn't get lost. I just checked out the PR again, and tried removing the With the julia> let v = [(1,),(2,),(3,)]
setindex!!(v, [(4,), (5,), (6,)], :, 1)
v
end
3-element Vector{Tuple{Int64}}:
(1,)
(2,)
(3,) without the restriction: julia> let v = [(1,),(2,),(3,)]
setindex!!(v, [(4,), (5,), (6,)], :, 1)
v
end
3-element Vector{Tuple{Int64}}:
(4,)
(5,)
(6,) So I say let's just completely drop the element type restriction, maybe add the above block as a test case and merge? |
test failure is unrelated. |
Wonderful; thanks @MasonProtter ! |
The current
possible
implementation forsetindex!
only allows scalars as values, and so something likex[:, 1] = zeros(size(x, 1))
will result in aMatrix{Any}
.This of course has significant perf. implications, so it seems worth it to specialize on these cases.
Related: JuliaFolds/BangBang.jl#238 and TuringLang/DynamicPPL.jl#530