From 37ac53eb13644bbd0d68a977262b30a25240e92d Mon Sep 17 00:00:00 2001 From: Kristoffer Date: Mon, 6 May 2024 12:08:05 +0200 Subject: [PATCH] Revert "Add `_unsetindex!` methods for `SubArray`s and `CartesianIndex`es (#53383)" This reverts commit 1a9040908b9bb89927b2d318da3f9fe1e457abea. (cherry picked from commit f8a74967188d26abd2916d0f21365f14fdfc2bba) --- base/abstractarray.jl | 15 +------------- base/array.jl | 7 +------ base/multidimensional.jl | 6 ------ base/subarray.jl | 19 ----------------- test/subarray.jl | 44 ---------------------------------------- 5 files changed, 2 insertions(+), 89 deletions(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 4bcc763d66a199..56390de1eb5d3f 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1452,20 +1452,7 @@ function _setindex!(::IndexCartesian, A::AbstractArray, v, I::Vararg{Int,M}) whe r end -function _unsetindex!(A::AbstractArray, i::Integer...) - @_propagate_inbounds_meta - _unsetindex!(A, map(to_index, i)...) -end - -function _unsetindex!(A::AbstractArray{T}, i::Int...) where T - # this provides a fallback method which is a no-op if the element is already unassigned - # such that copying into an uninitialized object generally always will work, - # even if the specific custom array type has not implemented `_unsetindex!` - @inline - @boundscheck checkbounds(A, i...) - allocatedinline(T) || @inbounds(!isassigned(A, i...)) || throw(MethodError(_unsetindex!, (A, i...))) - return A -end +_unsetindex!(A::AbstractArray, i::Integer) = _unsetindex!(A, to_index(i)) """ parent(A) diff --git a/base/array.jl b/base/array.jl index 83ca35714c2449..19d79479bef39a 100644 --- a/base/array.jl +++ b/base/array.jl @@ -219,12 +219,7 @@ function _unsetindex!(A::Array, i::Int) @inbounds _unsetindex!(GenericMemoryRef(A.ref, i)) return A end -function _unsetindex!(A::Array, i::Int...) - @inline - @boundscheck checkbounds(A, i...) - @inbounds _unsetindex!(A, _to_linear_index(A, i...)) - return A -end + # TODO: deprecate this (aligned_sizeof and/or elsize and/or sizeof(Some{T}) are more correct) elsize(::Type{A}) where {T,A<:Array{T}} = aligned_sizeof(T) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index fe29e5c1d8e5f7..146f8c160e8e9d 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1610,12 +1610,6 @@ end end end -# _unsetindex -@propagate_inbounds function Base._unsetindex!(A::AbstractArray, i::CartesianIndex) - Base._unsetindex!(A, to_indices(A, (i,))...) - return A -end - ## permutedims ## Permute array dims ## diff --git a/base/subarray.jl b/base/subarray.jl index 759b564aade17d..b67b917a478b3c 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -413,25 +413,6 @@ function isassigned(V::FastSubArray{<:Any, 1}, i::Int) r end -function _unsetindex!(V::FastSubArray, i::Int) - @inline - @boundscheck checkbounds(V, i) - @inbounds _unsetindex!(V.parent, _reindexlinear(V, i)) - return V -end -function _unsetindex!(V::FastSubArray{<:Any,1}, i::Int) - @inline - @boundscheck checkbounds(V, i) - @inbounds _unsetindex!(V.parent, _reindexlinear(V, i)) - return V -end -function _unsetindex!(V::SubArray{T,N}, i::Vararg{Int,N}) where {T,N} - @inline - @boundscheck checkbounds(V, i...) - @inbounds _unsetindex!(V.parent, reindex(V.indices, i)...) - return V -end - IndexStyle(::Type{<:FastSubArray}) = IndexLinear() IndexStyle(::Type{<:SubArray}) = IndexCartesian() diff --git a/test/subarray.jl b/test/subarray.jl index 337e666da918c8..9fd59ef5a41562 100644 --- a/test/subarray.jl +++ b/test/subarray.jl @@ -1074,48 +1074,4 @@ end @test !isassigned(v, 1, 2) # inbounds but not assigned @test !isassigned(v, 3, 3) # out-of-bounds end - - @testset "_unsetindex!" begin - function test_unsetindex(A, B) - copyto!(A, B) - for i in eachindex(A) - @test !isassigned(A, i) - end - inds = eachindex(A) - @test_throws BoundsError Base._unsetindex!(A, last(inds) + oneunit(eltype(inds))) - end - @testset "dest IndexLinear, src IndexLinear" begin - for p in (fill(BigInt(2)), BigInt[1, 2], BigInt[1 2; 3 4]) - A = view(copy(p), ntuple(_->:, ndims(p))...) - B = view(similar(A), ntuple(_->:, ndims(p))...) - test_unsetindex(A, B) - test_unsetindex(p, B) - end - end - - @testset "dest IndexLinear, src IndexCartesian" begin - for p in (fill(BigInt(2)), BigInt[1, 2], BigInt[1 2; 3 4]) - A = view(copy(p), ntuple(_->:, ndims(p))...) - B = view(similar(A), axes(A)...) - test_unsetindex(A, B) - test_unsetindex(p, B) - end - end - - @testset "dest IndexCartesian, src IndexLinear" begin - for p in (fill(BigInt(2)), BigInt[1, 2], BigInt[1 2; 3 4]) - A = view(p, axes(p)...) - B = similar(A) - test_unsetindex(A, B) - end - end - - @testset "dest IndexCartesian, src IndexCartesian" begin - for p in (fill(BigInt(2)), BigInt[1, 2], BigInt[1 2; 3 4]) - A = view(p, axes(p)...) - B = view(similar(A), axes(A)...) - test_unsetindex(A, B) - end - end - end end