diff --git a/base/deprecated.jl b/base/deprecated.jl index dad7aac7da3f9..2c7af050bf812 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -507,15 +507,6 @@ function chol(A::AbstractMatrix, uplo::Symbol) chol(A, Val{uplo}) end -_ensure_vector(A::AbstractArray) = vec(A) -_ensure_vector(A) = A -_ensure_vectors() = () -_ensure_vectors(A, As...) = (_ensure_vector(A), _ensure_vectors(As...)...) -function _unsafe_setindex!(l::LinearIndexing, A::AbstractArray, x, J::Union{Real,AbstractArray,Colon}...) - depwarn("multidimensional indexed assignment with multidimensional arrays is deprecated, use vec to convert indices to vectors", :_unsafe_setindex!) - _unsafe_setindex!(l, A, x, _ensure_vectors(J...)...) -end - # 11554 read!(from::AbstractIOBuffer, p::Ptr, nb::Integer) = read!(from, p, Int(nb)) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 39b0acab6cf81..80f069afc52ff 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -161,8 +161,8 @@ index_lengths_dim(A, dim) = () index_lengths_dim(A, dim, ::Colon) = (trailingsize(A, dim),) @inline index_lengths_dim(A, dim, ::Colon, i, I...) = (size(A, dim), index_lengths_dim(A, dim+1, i, I...)...) @inline index_lengths_dim(A, dim, ::Real, I...) = (1, index_lengths_dim(A, dim+1, I...)...) -@inline index_lengths_dim(A, dim, i::AbstractVector{Bool}, I...) = (sum(i), index_lengths_dim(A, dim+1, I...)...) -@inline index_lengths_dim(A, dim, i::AbstractVector, I...) = (length(i), index_lengths_dim(A, dim+1, I...)...) +@inline index_lengths_dim(A, dim, i::AbstractArray{Bool}, I...) = (sum(i), index_lengths_dim(A, dim+1, I...)...) +@inline index_lengths_dim(A, dim, i::AbstractArray, I...) = (length(i), index_lengths_dim(A, dim+1, I...)...) # shape of array to create for getindex() with indexes I, dropping trailing scalars index_shape(A::AbstractArray, I::AbstractArray) = size(I) # Linear index reshape @@ -290,15 +290,12 @@ _iterable(v) = repeated(v) checkbounds(A, J...) _unsafe_setindex!(l, A, x, J...) end -@inline function _unsafe_setindex!(l::LinearIndexing, A::AbstractArray, x, J::Union{Real,AbstractVector,Colon}...) +@inline function _unsafe_setindex!(l::LinearIndexing, A::AbstractArray, x, J::Union{Real,AbstractArray,Colon}...) _unsafe_batchsetindex!(l, A, _iterable(x), to_indexes(J...)...) end -# While setindex! with one array argument doesn't mean anything special, it is -# still supported for symmetry with getindex. -_unsafe_setindex!(l::LinearIndexing, A::AbstractArray, x, I::AbstractArray) = _unsafe_setindex!(l, A, x, vec(I)) # 1-d logical indexing: override the above to avoid calling find (in to_index) -function _unsafe_setindex!(::LinearIndexing, A::AbstractArray, x, I::AbstractVector{Bool}) +function _unsafe_setindex!(::LinearIndexing, A::AbstractArray, x, I::AbstractArray{Bool}) X = _iterable(x) Xs = start(X) i = 0 @@ -317,7 +314,7 @@ function _unsafe_setindex!(::LinearIndexing, A::AbstractArray, x, I::AbstractVec end # Use iteration over X so we don't need to worry about its storage -@generated function _unsafe_batchsetindex!(::LinearFast, A::AbstractArray, X, I::Union{Real,AbstractVector,Colon}...) +@generated function _unsafe_batchsetindex!(::LinearFast, A::AbstractArray, X, I::Union{Real,AbstractArray,Colon}...) N = length(I) quote @nexprs $N d->(I_d = I[d]) @@ -334,7 +331,7 @@ end A end end -@generated function _unsafe_batchsetindex!(::LinearSlow, A::AbstractArray, X, I::Union{Real,AbstractVector,Colon}...) +@generated function _unsafe_batchsetindex!(::LinearSlow, A::AbstractArray, X, I::Union{Real,AbstractArray,Colon}...) N = length(I) quote @nexprs $N d->(I_d = I[d]) diff --git a/test/arrayops.jl b/test/arrayops.jl index 6b3f78130ff70..217e3c7589035 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -40,6 +40,14 @@ a[2,2] = 4 b = a' @test a[1,1] == 1. && a[1,2] == 2. && a[2,1] == 3. && a[2,2] == 4. @test b[1,1] == 1. && b[2,1] == 2. && b[1,2] == 3. && b[2,2] == 4. +a[[1 2 3 4]] = 0 +@test a == zeros(2,2) +a[[1 2], [1 2]] = 1 +@test a == ones(2,2) +a[[1 2], 1] = 0 +@test a[1,1] == 0. && a[1,2] == 1. && a[2,1] == 0. && a[2,2] == 1. +a[:, [1 2]] = 2 +@test a == 2ones(2,2) a = Array(Float64, 2, 2, 2, 2, 2) a[1,1,1,1,1] = 10