Skip to content

Commit b23f557

Browse files
KristofferCKristofferC
andauthored
Revert "Avoid allocations in views of views (#53231)" (#57044)
This reverts commit 2bd4cf8. (#53231) The reason for this revert is that it caused exponential blowup of types in iterated views causing some packages to simply freeze when doing something that worked ok in 1.10. In my opinion, the perf gain from the PR is not outweighed by the "risk" of hitting this compilation blowup case. Fixes #56760. Co-authored-by: KristofferC <kristoffer.carlsson@juliacomputing.com>
1 parent 3ba504a commit b23f557

2 files changed

Lines changed: 3 additions & 28 deletions

File tree

base/subarray.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,18 @@ reindex(idxs::Tuple{Slice, Vararg{Any}}, subidxs::Tuple{Any, Vararg{Any}}) =
291291

292292
# Re-index into parent vectors with one subindex
293293
reindex(idxs::Tuple{AbstractVector, Vararg{Any}}, subidxs::Tuple{Any, Vararg{Any}}) =
294-
(@_propagate_inbounds_meta; (maybeview(idxs[1], subidxs[1]), reindex(tail(idxs), tail(subidxs))...))
294+
(@_propagate_inbounds_meta; (idxs[1][subidxs[1]], reindex(tail(idxs), tail(subidxs))...))
295295

296296
# Parent matrices are re-indexed with two sub-indices
297297
reindex(idxs::Tuple{AbstractMatrix, Vararg{Any}}, subidxs::Tuple{Any, Any, Vararg{Any}}) =
298-
(@_propagate_inbounds_meta; (maybeview(idxs[1], subidxs[1], subidxs[2]), reindex(tail(idxs), tail(tail(subidxs)))...))
298+
(@_propagate_inbounds_meta; (idxs[1][subidxs[1], subidxs[2]], reindex(tail(idxs), tail(tail(subidxs)))...))
299299

300300
# In general, we index N-dimensional parent arrays with N indices
301301
@generated function reindex(idxs::Tuple{AbstractArray{T,N}, Vararg{Any}}, subidxs::Tuple{Vararg{Any}}) where {T,N}
302302
if length(subidxs.parameters) >= N
303303
subs = [:(subidxs[$d]) for d in 1:N]
304304
tail = [:(subidxs[$d]) for d in N+1:length(subidxs.parameters)]
305-
:(@_propagate_inbounds_meta; (maybeview(idxs[1], $(subs...)), reindex(tail(idxs), ($(tail...),))...))
305+
:(@_propagate_inbounds_meta; (idxs[1][$(subs...)], reindex(tail(idxs), ($(tail...),))...))
306306
else
307307
:(throw(ArgumentError("cannot re-index SubArray with fewer indices than dimensions\nThis should not occur; please submit a bug report.")))
308308
end

test/subarray.jl

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,31 +1027,6 @@ catch err
10271027
err isa ErrorException && startswith(err.msg, "syntax:")
10281028
end
10291029

1030-
1031-
@testset "avoid allocating in reindex" begin
1032-
a = reshape(1:16, 4, 4)
1033-
inds = ([2,3], [3,4])
1034-
av = view(a, inds...)
1035-
av2 = view(av, 1, 1)
1036-
@test parentindices(av2) === (2,3)
1037-
av2 = view(av, 2:2, 2:2)
1038-
@test parentindices(av2) === (view(inds[1], 2:2), view(inds[2], 2:2))
1039-
1040-
inds = (reshape([eachindex(a);], size(a)),)
1041-
av = view(a, inds...)
1042-
av2 = view(av, 1, 1)
1043-
@test parentindices(av2) === (1,)
1044-
av2 = view(av, 2:2, 2:2)
1045-
@test parentindices(av2) === (view(inds[1], 2:2, 2:2),)
1046-
1047-
inds = (reshape([eachindex(a);], size(a)..., 1),)
1048-
av = view(a, inds...)
1049-
av2 = view(av, 1, 1, 1)
1050-
@test parentindices(av2) === (1,)
1051-
av2 = view(av, 2:2, 2:2, 1:1)
1052-
@test parentindices(av2) === (view(inds[1], 2:2, 2:2, 1:1),)
1053-
end
1054-
10551030
@testset "isassigned" begin
10561031
a = Vector{BigFloat}(undef, 5)
10571032
a[2] = 0

0 commit comments

Comments
 (0)