Skip to content

Commit 3cbb9fc

Browse files
committed
WIP
1 parent 2cc82d2 commit 3cbb9fc

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

base/deprecated.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,28 @@ function _depwarn_for_trailing_indices(t::Tuple)
16681668
true
16691669
end
16701670

1671+
# issue #...: nonscalar indexed assignment of many values to many locations
1672+
@generated function _unsafe_setindex!(::IndexStyle, A::AbstractArray, X::AbstractArray, I::Union{Real,AbstractArray}...)
1673+
N = length(I)
1674+
quote
1675+
if ndims(A) == ndims(X)
1676+
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!)
1677+
else
1678+
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!)
1679+
@nexprs $N d->(I_d = I[d])
1680+
idxlens = @ncall $N index_lengths I
1681+
@ncall $N setindex_shape_check X (d->idxlens[d])
1682+
Xs = start(X)
1683+
@inbounds @nloops $N i d->I_d begin
1684+
v, Xs = next(X, Xs)
1685+
@ncall $N setindex! A v i
1686+
end
1687+
A
1688+
end
1689+
end
1690+
@deprecate setindex!(B::BitArray, X::StridedArray, I::Union{Colon,UnitRange{Int}}) B[I] .= X
1691+
@deprecate setindex!(B::BitArray, X::StridedArray, I0::Union{Colon,AbstractUnitRange}, I::Union{Int,Colon,AbstractUnitRange}...) B[I0, I...] .= X
1692+
16711693
# issue #22791
16721694
@deprecate select partialsort
16731695
@deprecate select! partialsort!

base/multidimensional.jl

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -666,19 +666,12 @@ function _setindex!(l::IndexStyle, A::AbstractArray, x, I::Union{Real, AbstractA
666666
A
667667
end
668668

669-
_iterable(v::AbstractArray) = v
670-
_iterable(v) = Iterators.repeated(v)
671669
@generated function _unsafe_setindex!(::IndexStyle, A::AbstractArray, x, I::Union{Real,AbstractArray}...)
672670
N = length(I)
673671
quote
674-
X = _iterable(x)
675672
@nexprs $N d->(I_d = I[d])
676-
idxlens = @ncall $N index_lengths I
677-
@ncall $N setindex_shape_check X (d->idxlens[d])
678-
Xs = start(X)
679673
@inbounds @nloops $N i d->I_d begin
680-
v, Xs = next(X, Xs)
681-
@ncall $N setindex! A v i
674+
@ncall $N setindex! A x i
682675
end
683676
A
684677
end
@@ -1476,32 +1469,33 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra
14761469
end
14771470
end
14781471

1472+
# These had been specializations on setindex! previously
14791473
# contiguous multidimensional indexing: if the first dimension is a range,
14801474
# we can get some performance from using copy_chunks!
1481-
1482-
@inline function setindex!(B::BitArray, X::StridedArray, J0::Union{Colon,UnitRange{Int}})
1483-
I0 = to_indices(B, (J0,))[1]
1484-
@boundscheck checkbounds(B, I0)
1475+
function broadcast!(::typeof(identity), B::BitArray, X::StridedArray)
1476+
size(B) == size(X) || return Broadcast.broadcast_c!(identity, containertype(B), containertype(X), B, X)
1477+
copy_to_bitarray_chunks!(B.chunks, 1, X, 1, length(B))
1478+
return B
1479+
end
1480+
function broadcast!(::typeof(identity), V::SubArray{<:Any,<:Any,<:BitArray,<:Tuple{AbstractUnitRange}}, X::StridedArray)
1481+
size(V) == size(X) || return Broadcast.broadcast_c!(identity, containertype(V), containertype(X), V, X)
1482+
B = V.parent
1483+
I0 = V.indexes[1]
14851484
l0 = length(I0)
1486-
setindex_shape_check(X, l0)
14871485
l0 == 0 && return B
14881486
f0 = indexoffset(I0)+1
14891487
copy_to_bitarray_chunks!(B.chunks, f0, X, 1, l0)
14901488
return B
14911489
end
1492-
1493-
@inline function setindex!(B::BitArray, X::StridedArray,
1494-
I0::Union{Colon,UnitRange{Int}}, I::Union{Int,UnitRange{Int},Colon}...)
1495-
J = to_indices(B, (I0, I...))
1496-
@boundscheck checkbounds(B, J...)
1497-
_unsafe_setindex!(B, X, J...)
1498-
end
1499-
@generated function _unsafe_setindex!(B::BitArray, X::StridedArray,
1500-
I0::Union{Slice,UnitRange{Int}}, I::Union{Int,UnitRange{Int},Slice}...)
1490+
@generated function broadcast!(::typeof(identity),
1491+
V::SubArray{<:Any,<:Any,<:BitArray,<:Tuple{AbstractUnitRange,Vararg{Union{AbstractUnitRange,Int}}}}, X::StridedArray)
15011492
N = length(I)
15021493
quote
1494+
size(V) == size(X) || return Broadcast.broadcast_c!(identity, containertype(V), containertype(X), V, X)
1495+
B = V.parent
1496+
I0 = V.indexes[1]
1497+
I = tail(V.indexes)
15031498
idxlens = @ncall $N index_lengths I0 d->I[d]
1504-
@ncall $N setindex_shape_check X idxlens[1] d->idxlens[d+1]
15051499
isempty(X) && return B
15061500
f0 = indexoffset(I0)+1
15071501
l0 = idxlens[1]

0 commit comments

Comments
 (0)