-
-
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
Support repeat at any dimension #29626
Conversation
Welcome and thanks for the contribution! |
Thanks for the reviewing @mbauman and sorry for the back-and-forth commits on the same code. I am not very familiar with the index mechanisms of Julia Arrays; I thought I was even thinking of using R[axes(A)...,ones(Int, length(shape) - length(inner))...] = A to replace idxs = (axes(A)..., ntuple(n->OneTo(1), length(shape) - length(inner))...)
R[idxs...] = A But not very sure if this works. (Actually I don't know how to fully test it in my own machine) |
The best way to test changes like this locally is to use Revise.jl, but sometimes it's quickest/easiest to just Sorry for the misdirection on the colons — of course we just want to be assigning into the first block. Using repeat(ones(2,2), inner=(1, 1, 1), outer=(2, 2, 2)) With respect to your question about |
Thanks for this explanation, this helps me a lot. With regard to optimization, I did some related benchmark tests as a reference (kind of interesting to me). This benchmark says, at least, we can optimize # Baseline
# without this patch
julia> @btime repeat(ones(100,100), 20, 20); # 2000×2000 Array{Float64,2}
8.828 ms (4 allocations: 30.59 MiB)
# without this patch (slightly faster than Baseline)
julia> @btime reshape(repeat(ones(100,100),20,20),2000,2000,1,1,1); # 2000×2000×1×1×1 Array{Float64,5}
8.590 ms (6 allocations: 30.59 MiB)
# without this patch
julia> @btime repeat(reshape(ones(100,100),100,100,1,1,1),20,20,1,1,1); # 2000×2000×1×1×1 Array{Float64,5}
66.962 ms (3625 allocations: 61.17 MiB)
# with this patch
julia> @btime repeat(ones(100,100), 20, 20,1,1,1); # 2000×2000×1×1×1 Array{Float64,5}
70.049 ms (3625 allocations: 61.17 MiB) I'll tell you when I have a solution to support this feature without loss much performance. (I have some other jobs to do, so no sooner than Nov) |
ping @mbauman I think this is good to merge. Can you have a quick look? In the meantime, I'm wondering if we can support partial indexing julia> a = ones(5,5,5);
julia> a[1] # this works, indexing by memory order
julia> a[1,1] # this doesn't work though, can we support this? If this feature can be supported, then this patch becomes unnecessary. And other similar operations can be done without code changing. Perhaps it's because supporting this would make the performance terrible? or because this would introduce ambiguity with |
Yes, you're exactly right and this did indeed work previously. It had the somewhat strange behavior that the trailing index was always allowed to "linearly span" (working through memory order for plain old
In other words, you've found and cleaned up some of my own dirty laundry — thank you! |
Cool, I'll keep this in mind. |
This solves issue #29614 as an enhancement
now
repeat(ones(2,2), 2,2,2)
won't raiseBoundsError
but instead return aArray{T,3}
as intuition expects.Benchmark: