Skip to content

Commit

Permalink
WIP: through bootstrap!
Browse files Browse the repository at this point in the history
  • Loading branch information
mbauman committed Oct 27, 2017
1 parent ed09c75 commit 9d8c047
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 69 deletions.
4 changes: 2 additions & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ function typed_vcat(::Type{T}, V::AbstractVector...) where T
for k=1:length(V)
Vk = V[k]
p1 = pos+length(Vk)-1
a[pos:p1] = Vk
a[pos:p1] .= Vk
pos = p1+1
end
a
Expand Down Expand Up @@ -1265,7 +1265,7 @@ function _cat(A, shape::NTuple{N}, catdims, X...) where N
end
end
I::NTuple{N, UnitRange{Int}} = (inds...,)
A[I...] = x
A[I...] .= x
end
return A
end
Expand Down
71 changes: 22 additions & 49 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -787,56 +787,29 @@ function setindex! end
@eval setindex!(A::Array{T}, x, i1::Int, i2::Int, I::Int...) where {T} =
(@_inline_meta; arrayset($(Expr(:boundscheck)), A, convert(T,x)::T, i1, i2, I...)) # TODO: REMOVE FOR #14770

# These are redundant with the abstract fallbacks but needed for bootstrap
function setindex!(A::Array, x, I::AbstractVector{Int})
@_propagate_inbounds_meta
A === I && (I = copy(I))
for i in I
A[i] = x
end
return A
end
function setindex!(A::Array, X::AbstractArray, I::AbstractVector{Int})
@_propagate_inbounds_meta
@boundscheck setindex_shape_check(X, length(I))
count = 1
if X === A
X = copy(X)
I===A && (I = X::typeof(I))
elseif I === A
I = copy(I)
end
for i in I
@inbounds x = X[count]
A[i] = x
count += 1
end
return A
end

# Faster contiguous setindex! with copy!
function setindex!(A::Array{T}, X::Array{T}, I::UnitRange{Int}) where T
@_inline_meta
@boundscheck checkbounds(A, I)
lI = length(I)
@boundscheck setindex_shape_check(X, lI)
if lI > 0
unsafe_copy!(A, first(I), X, 1, lI)
end
return A
end
function setindex!(A::Array{T}, X::Array{T}, c::Colon) where T
@_inline_meta
lI = length(A)
@boundscheck setindex_shape_check(X, lI)
if lI > 0
unsafe_copy!(A, 1, X, 1, lI)
end
return A
end

setindex!(A::Array, x::Number, ::Colon) = fill!(A, x)
setindex!(A::Array{T, N}, x::Number, ::Vararg{Colon, N}) where {T, N} = fill!(A, x)
# function setindex!(A::Array{T}, X::Array{T}, I::UnitRange{Int}) where T
# @_inline_meta
# @boundscheck checkbounds(A, I)
# lI = length(I)
# @boundscheck setindex_shape_check(X, lI)
# if lI > 0
# unsafe_copy!(A, first(I), X, 1, lI)
# end
# return A
# end
# function setindex!(A::Array{T}, X::Array{T}, c::Colon) where T
# @_inline_meta
# lI = length(A)
# @boundscheck setindex_shape_check(X, lI)
# if lI > 0
# unsafe_copy!(A, 1, X, 1, lI)
# end
# return A
# end
#
# setindex!(A::Array, x::Number, ::Colon) = fill!(A, x)
# setindex!(A::Array{T, N}, x::Number, ::Vararg{Colon, N}) where {T, N} = fill!(A, x)

# efficiently grow an array

Expand Down
5 changes: 4 additions & 1 deletion base/char.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ bswap(x::Char) = Char(bswap(UInt32(x)))

print(io::IO, c::Char) = (write(io, c); nothing)

const hex_chars = UInt8['0':'9';'a':'z']
const hex_chars = [0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a,
0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74,
0x75, 0x76, 0x77, 0x78, 0x79, 0x7a]

function show(io::IO, c::Char)
if c <= '\\'
Expand Down
27 changes: 10 additions & 17 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1694,25 +1694,18 @@ function _depwarn_for_trailing_indices(t::Tuple)
end

# issue #...: nonscalar indexed assignment of many values to many locations
@generated function _unsafe_setindex!(::IndexStyle, A::AbstractArray, X::AbstractArray, I::Union{Real,AbstractArray}...)
N = length(I)
quote
if ndims(A) == ndims(X)
depwarn("using nonscalar indexed assignment to implicitly broadcast the values of an array to many indices is deprecated. Use `A[I...] .= values` to explicitly opt-in to broadcasting.", :setindex!)
else
depwarn("using nonscalar indexed assignment to implicitly broadcast the values of an array to many indices is deprecated. Use `A[I...] .= reshape(values` to explicitly opt-in to broadcasting.", :setindex!)
end
@nexprs $N d->(I_d = I[d])
idxlens = @ncall $N index_lengths I
@ncall $N setindex_shape_check X (d->idxlens[d])
Xs = start(X)
@inbounds @nloops $N i d->I_d begin
v, Xs = next(X, Xs)
@ncall $N setindex! A v i
end
A
function deprecate_nonscalar_indexed_assignment!(A::AbstractArray, X::AbstractArray, I...)
if ndims(A) == ndims(X)
depwarn("using `A[I...] = X` to implicitly broadcast the elements of `X` to many locations in `A` is deprecated. Use `A[I...] .= X` to explicitly opt-in to broadcasting.", :setindex!)
A[I...] .= X
else
depwarn("using `A[I...] = X` to implicitly broadcast the elements of `X` to many locations in `A` is deprecated. Use `A[I...] .= reshape(X, indices(view(A, I...)))` to explicitly opt-in to broadcasting.", :setindex!)
A[I...] .= reshape(X, indices(view(A, I...)))
end
end
_unsafe_setindex!(::IndexStyle, A::AbstractArray, X::AbstractArray, I::Union{Real,AbstractArray}...) = deprecate_nonscalar_indexed_assignment!(A, X, I...)
setindex!(B::BitArray, X::StridedArray, J0::Union{Colon,UnitRange{Int}}) = deprecate_nonscalar_indexed_assignment(B, X, J0)
setindex!(B::BitArray, X::StridedArray, I0::Union{Colon,UnitRange{Int}}, I::Union{Int,UnitRange{Int},Colon}...) = deprecate_nonscalar_indexed_assignment(B, X, I0, I)

# issue #22791
@deprecate select partialsort
Expand Down

0 comments on commit 9d8c047

Please sign in to comment.