Skip to content

Commit d4578a8

Browse files
KristofferCKristofferC
authored andcommitted
Revert "Add _unsetindex! methods for SubArrays and CartesianIndexes (#53383)"
This reverts commit 1a90409. (cherry picked from commit f8a7496)
1 parent 2ec00d0 commit d4578a8

File tree

6 files changed

+2
-120
lines changed

6 files changed

+2
-120
lines changed

base/abstractarray.jl

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,20 +1452,7 @@ function _setindex!(::IndexCartesian, A::AbstractArray, v, I::Vararg{Int,M}) whe
14521452
r
14531453
end
14541454

1455-
function _unsetindex!(A::AbstractArray, i::Integer...)
1456-
@_propagate_inbounds_meta
1457-
_unsetindex!(A, map(to_index, i)...)
1458-
end
1459-
1460-
function _unsetindex!(A::AbstractArray{T}, i::Int...) where T
1461-
# this provides a fallback method which is a no-op if the element is already unassigned
1462-
# such that copying into an uninitialized object generally always will work,
1463-
# even if the specific custom array type has not implemented `_unsetindex!`
1464-
@inline
1465-
@boundscheck checkbounds(A, i...)
1466-
allocatedinline(T) || @inbounds(!isassigned(A, i...)) || throw(MethodError(_unsetindex!, (A, i...)))
1467-
return A
1468-
end
1455+
_unsetindex!(A::AbstractArray, i::Integer) = _unsetindex!(A, to_index(i))
14691456

14701457
"""
14711458
parent(A)

base/array.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,7 @@ function _unsetindex!(A::Array, i::Int)
219219
@inbounds _unsetindex!(GenericMemoryRef(A.ref, i))
220220
return A
221221
end
222-
function _unsetindex!(A::Array, i::Int...)
223-
@inline
224-
@boundscheck checkbounds(A, i...)
225-
@inbounds _unsetindex!(A, _to_linear_index(A, i...))
226-
return A
227-
end
222+
228223

229224
# TODO: deprecate this (aligned_sizeof and/or elsize and/or sizeof(Some{T}) are more correct)
230225
elsize(::Type{A}) where {T,A<:Array{T}} = aligned_sizeof(T)

base/multidimensional.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,12 +1610,6 @@ end
16101610
end
16111611
end
16121612

1613-
# _unsetindex
1614-
@propagate_inbounds function Base._unsetindex!(A::AbstractArray, i::CartesianIndex)
1615-
Base._unsetindex!(A, to_indices(A, (i,))...)
1616-
return A
1617-
end
1618-
16191613
## permutedims
16201614

16211615
## Permute array dims ##

base/subarray.jl

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -413,25 +413,6 @@ function isassigned(V::FastSubArray{<:Any, 1}, i::Int)
413413
r
414414
end
415415

416-
function _unsetindex!(V::FastSubArray, i::Int)
417-
@inline
418-
@boundscheck checkbounds(V, i)
419-
@inbounds _unsetindex!(V.parent, _reindexlinear(V, i))
420-
return V
421-
end
422-
function _unsetindex!(V::FastSubArray{<:Any,1}, i::Int)
423-
@inline
424-
@boundscheck checkbounds(V, i)
425-
@inbounds _unsetindex!(V.parent, _reindexlinear(V, i))
426-
return V
427-
end
428-
function _unsetindex!(V::SubArray{T,N}, i::Vararg{Int,N}) where {T,N}
429-
@inline
430-
@boundscheck checkbounds(V, i...)
431-
@inbounds _unsetindex!(V.parent, reindex(V.indices, i)...)
432-
return V
433-
end
434-
435416
IndexStyle(::Type{<:FastSubArray}) = IndexLinear()
436417
IndexStyle(::Type{<:SubArray}) = IndexCartesian()
437418

test/abstractarray.jl

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,34 +2059,3 @@ end
20592059
@test r2[i] == z[j]
20602060
end
20612061
end
2062-
2063-
@testset "_unsetindex!" begin
2064-
struct MyMatrixUnsetIndexCartInds{T,A<:AbstractMatrix{T}} <: AbstractMatrix{T}
2065-
data :: A
2066-
end
2067-
Base.size(A::MyMatrixUnsetIndexCartInds) = size(A.data)
2068-
Base.getindex(M::MyMatrixUnsetIndexCartInds, i::Int, j::Int) = M.data[i,j]
2069-
Base.setindex!(M::MyMatrixUnsetIndexCartInds, v, i::Int, j::Int) = setindex!(M.data, v, i, j)
2070-
struct MyMatrixUnsetIndexLinInds{T,A<:AbstractMatrix{T}} <: AbstractMatrix{T}
2071-
data :: A
2072-
end
2073-
Base.size(A::MyMatrixUnsetIndexLinInds) = size(A.data)
2074-
Base.getindex(M::MyMatrixUnsetIndexLinInds, i::Int) = M.data[i]
2075-
Base.setindex!(M::MyMatrixUnsetIndexLinInds, v, i::Int) = setindex!(M.data, v, i)
2076-
Base.IndexStyle(::Type{<:MyMatrixUnsetIndexLinInds}) = IndexLinear()
2077-
2078-
function test_unsetindex(MT)
2079-
M = MT(ones(2,2))
2080-
M2 = MT(Matrix{BigFloat}(undef, 2,2))
2081-
copyto!(M, M2)
2082-
@test all(==(1), M)
2083-
M3 = MT(Matrix{BigFloat}(undef, 2,2))
2084-
for i in eachindex(M3)
2085-
@test !isassigned(M3, i)
2086-
end
2087-
M3 .= 1
2088-
@test_throws MethodError copyto!(M3, M2)
2089-
end
2090-
test_unsetindex(MyMatrixUnsetIndexCartInds)
2091-
test_unsetindex(MyMatrixUnsetIndexLinInds)
2092-
end

test/subarray.jl

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,48 +1074,4 @@ end
10741074
@test !isassigned(v, 1, 2) # inbounds but not assigned
10751075
@test !isassigned(v, 3, 3) # out-of-bounds
10761076
end
1077-
1078-
@testset "_unsetindex!" begin
1079-
function test_unsetindex(A, B)
1080-
copyto!(A, B)
1081-
for i in eachindex(A)
1082-
@test !isassigned(A, i)
1083-
end
1084-
inds = eachindex(A)
1085-
@test_throws BoundsError Base._unsetindex!(A, last(inds) + oneunit(eltype(inds)))
1086-
end
1087-
@testset "dest IndexLinear, src IndexLinear" begin
1088-
for p in (fill(BigInt(2)), BigInt[1, 2], BigInt[1 2; 3 4])
1089-
A = view(copy(p), ntuple(_->:, ndims(p))...)
1090-
B = view(similar(A), ntuple(_->:, ndims(p))...)
1091-
test_unsetindex(A, B)
1092-
test_unsetindex(p, B)
1093-
end
1094-
end
1095-
1096-
@testset "dest IndexLinear, src IndexCartesian" begin
1097-
for p in (fill(BigInt(2)), BigInt[1, 2], BigInt[1 2; 3 4])
1098-
A = view(copy(p), ntuple(_->:, ndims(p))...)
1099-
B = view(similar(A), axes(A)...)
1100-
test_unsetindex(A, B)
1101-
test_unsetindex(p, B)
1102-
end
1103-
end
1104-
1105-
@testset "dest IndexCartesian, src IndexLinear" begin
1106-
for p in (fill(BigInt(2)), BigInt[1, 2], BigInt[1 2; 3 4])
1107-
A = view(p, axes(p)...)
1108-
B = similar(A)
1109-
test_unsetindex(A, B)
1110-
end
1111-
end
1112-
1113-
@testset "dest IndexCartesian, src IndexCartesian" begin
1114-
for p in (fill(BigInt(2)), BigInt[1, 2], BigInt[1 2; 3 4])
1115-
A = view(p, axes(p)...)
1116-
B = view(similar(A), axes(A)...)
1117-
test_unsetindex(A, B)
1118-
end
1119-
end
1120-
end
11211077
end

0 commit comments

Comments
 (0)