Skip to content

Commit 85b5073

Browse files
committed
Revert "Add _unsetindex! methods for SubArrays and CartesianIndexes (#53383)"
This reverts commit 1a90409.
1 parent b8f5997 commit 85b5073

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
@@ -1469,20 +1469,7 @@ function _setindex!(::IndexCartesian, A::AbstractArray, v, I::Vararg{Int,M}) whe
14691469
r
14701470
end
14711471

1472-
function _unsetindex!(A::AbstractArray, i::Integer...)
1473-
@_propagate_inbounds_meta
1474-
_unsetindex!(A, map(to_index, i)...)
1475-
end
1476-
1477-
function _unsetindex!(A::AbstractArray{T}, i::Int...) where T
1478-
# this provides a fallback method which is a no-op if the element is already unassigned
1479-
# such that copying into an uninitialized object generally always will work,
1480-
# even if the specific custom array type has not implemented `_unsetindex!`
1481-
@inline
1482-
@boundscheck checkbounds(A, i...)
1483-
allocatedinline(T) || @inbounds(!isassigned(A, i...)) || throw(MethodError(_unsetindex!, (A, i...)))
1484-
return A
1485-
end
1472+
_unsetindex!(A::AbstractArray, i::Integer) = _unsetindex!(A, to_index(i))
14861473

14871474
"""
14881475
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
@@ -1612,12 +1612,6 @@ end
16121612
end
16131613
end
16141614

1615-
# _unsetindex
1616-
@propagate_inbounds function Base._unsetindex!(A::AbstractArray, i::CartesianIndex)
1617-
Base._unsetindex!(A, to_indices(A, (i,))...)
1618-
return A
1619-
end
1620-
16211615
## permutedims
16221616

16231617
## Permute array dims ##

base/subarray.jl

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

412-
function _unsetindex!(V::FastSubArray, i::Int)
413-
@inline
414-
@boundscheck checkbounds(V, i)
415-
@inbounds _unsetindex!(V.parent, _reindexlinear(V, i))
416-
return V
417-
end
418-
function _unsetindex!(V::FastSubArray{<:Any,1}, i::Int)
419-
@inline
420-
@boundscheck checkbounds(V, i)
421-
@inbounds _unsetindex!(V.parent, _reindexlinear(V, i))
422-
return V
423-
end
424-
function _unsetindex!(V::SubArray{T,N}, i::Vararg{Int,N}) where {T,N}
425-
@inline
426-
@boundscheck checkbounds(V, i...)
427-
@inbounds _unsetindex!(V.parent, reindex(V.indices, i)...)
428-
return V
429-
end
430-
431412
IndexStyle(::Type{<:FastSubArray}) = IndexLinear()
432413

433414
# Strides are the distance in memory between adjacent elements in a given dimension

test/abstractarray.jl

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,37 +2040,6 @@ end
20402040
end
20412041
end
20422042

2043-
@testset "_unsetindex!" begin
2044-
struct MyMatrixUnsetIndexCartInds{T,A<:AbstractMatrix{T}} <: AbstractMatrix{T}
2045-
data :: A
2046-
end
2047-
Base.size(A::MyMatrixUnsetIndexCartInds) = size(A.data)
2048-
Base.getindex(M::MyMatrixUnsetIndexCartInds, i::Int, j::Int) = M.data[i,j]
2049-
Base.setindex!(M::MyMatrixUnsetIndexCartInds, v, i::Int, j::Int) = setindex!(M.data, v, i, j)
2050-
struct MyMatrixUnsetIndexLinInds{T,A<:AbstractMatrix{T}} <: AbstractMatrix{T}
2051-
data :: A
2052-
end
2053-
Base.size(A::MyMatrixUnsetIndexLinInds) = size(A.data)
2054-
Base.getindex(M::MyMatrixUnsetIndexLinInds, i::Int) = M.data[i]
2055-
Base.setindex!(M::MyMatrixUnsetIndexLinInds, v, i::Int) = setindex!(M.data, v, i)
2056-
Base.IndexStyle(::Type{<:MyMatrixUnsetIndexLinInds}) = IndexLinear()
2057-
2058-
function test_unsetindex(MT)
2059-
M = MT(ones(2,2))
2060-
M2 = MT(Matrix{BigFloat}(undef, 2,2))
2061-
copyto!(M, M2)
2062-
@test all(==(1), M)
2063-
M3 = MT(Matrix{BigFloat}(undef, 2,2))
2064-
for i in eachindex(M3)
2065-
@test !isassigned(M3, i)
2066-
end
2067-
M3 .= 1
2068-
@test_throws MethodError copyto!(M3, M2)
2069-
end
2070-
test_unsetindex(MyMatrixUnsetIndexCartInds)
2071-
test_unsetindex(MyMatrixUnsetIndexLinInds)
2072-
end
2073-
20742043
@testset "reshape for offset arrays" begin
20752044
p = Base.IdentityUnitRange(3:4)
20762045
r = reshape(p, :, 1)

test/subarray.jl

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

11241080
@testset "aliasing check with reshaped subarrays" begin

0 commit comments

Comments
 (0)