Skip to content

Commit 343c6ee

Browse files
KristofferCKristofferC
andcommitted
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 <[email protected]> (cherry picked from commit b23f557)
1 parent f66a1cf commit 343c6ee

File tree

2 files changed

+3
-28
lines changed

2 files changed

+3
-28
lines changed

base/subarray.jl

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

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

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

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

test/subarray.jl

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

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

0 commit comments

Comments
 (0)