Skip to content

Commit ed4fc24

Browse files
committed
Revert "Fix broadcast_indices (#22130)"
This reverts commit fb81c34. And adds a test for the bug this causes.
1 parent 5c90d2e commit ed4fc24

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

base/broadcast.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ promote_containertype(::Type{T}, ::Type{T}) where {T} = T
4545
## Calculate the broadcast indices of the arguments, or error if incompatible
4646
# array inputs
4747
broadcast_indices() = ()
48-
broadcast_indices(A) = broadcast_indices(containertype(A), A)
48+
broadcast_indices(A) = _broadcast_indices(containertype(A), A)
4949
@inline broadcast_indices(A, B...) = broadcast_shape(broadcast_indices(A), broadcast_indices(B...))
50-
broadcast_indices(::ScalarType, A) = ()
51-
broadcast_indices(::Type{Tuple}, A) = (OneTo(length(A)),)
52-
broadcast_indices(::Type{Array}, A::Ref) = ()
53-
broadcast_indices(::Type{Array}, A) = indices(A)
50+
_broadcast_indices(::Type, A) = error("_containertype definition requires a corresponding _broadcast_indices definition")
51+
_broadcast_indices(::ScalarType, A) = ()
52+
_broadcast_indices(::Type{Tuple}, A) = (OneTo(length(A)),)
53+
_broadcast_indices(::Type{Array}, A::Ref) = ()
54+
_broadcast_indices(::Type{Array}, A) = indices(A)
5455

5556
# shape (i.e., tuple-of-indices) inputs
5657
broadcast_shape(shape::Tuple) = shape

base/sparse/higherorderfns.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ module HigherOrderFns
66
# particularly map[!]/broadcast[!] for SparseVectors and SparseMatrixCSCs at present.
77
import Base: map, map!, broadcast, broadcast!
88
import Base.Broadcast: _containertype, promote_containertype,
9-
broadcast_indices, broadcast_c, broadcast_c!
9+
broadcast_indices, _broadcast_indices,
10+
broadcast_c, broadcast_c!
1011

1112
using Base: front, tail, to_shape
1213
using ..SparseArrays: SparseVector, SparseMatrixCSC, AbstractSparseVector,
@@ -900,7 +901,7 @@ end
900901
# (10) broadcast[!] over combinations of broadcast scalars and sparse vectors/matrices
901902

902903
# broadcast shape promotion for combinations of sparse arrays and other types
903-
broadcast_indices(::Type{AbstractSparseArray}, A) = indices(A)
904+
_broadcast_indices(::Type{AbstractSparseArray}, A) = indices(A)
904905
# broadcast container type promotion for combinations of sparse arrays and other types
905906
_containertype(::Type{<:SparseVecOrMat}) = AbstractSparseArray
906907
# combinations of sparse arrays with broadcast scalars should yield sparse arrays
@@ -984,7 +985,7 @@ struct PromoteToSparse end
984985
# broadcast containertype definitions for structured matrices
985986
StructuredMatrix = Union{Diagonal,Bidiagonal,Tridiagonal,SymTridiagonal}
986987
_containertype(::Type{<:StructuredMatrix}) = PromoteToSparse
987-
broadcast_indices(::Type{PromoteToSparse}, A) = indices(A)
988+
_broadcast_indices(::Type{PromoteToSparse}, A) = indices(A)
988989

989990
# combinations explicitly involving Tuples and PromoteToSparse collections
990991
# divert to the generic AbstractArray broadcast code

test/broadcast.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ Base.Broadcast.promote_containertype(::Type{Array19745}, ct) = A
430430
Base.Broadcast.promote_containertype(::Type{Array}, ::Type{Array19745}) = Array19745
431431
Base.Broadcast.promote_containertype(ct, ::Type{Array19745}) = Array19745
432432

433-
Base.Broadcast.broadcast_indices(::Type{Array19745}, A) = indices(A)
434-
Base.Broadcast.broadcast_indices(::Type{Array19745}, A::Ref) = ()
433+
Base.Broadcast._broadcast_indices(::Type{Array19745}, A) = indices(A)
434+
Base.Broadcast._broadcast_indices(::Type{Array19745}, A::Ref) = ()
435435

436436
getfield19745(x::Array19745) = x.data
437437
getfield19745(x) = x
@@ -520,3 +520,6 @@ let t = (0, 1, 2)
520520
o = 1
521521
@test @inferred(broadcast(+, t, o)) == (1, 2, 3)
522522
end
523+
524+
# issue #22130
525+
@test convert.(Any, [1, 2]) == [1, 2]

0 commit comments

Comments
 (0)