@@ -614,8 +614,9 @@ Base.@propagate_inbounds Base.getindex(bc::Broadcasted) = bc[CartesianIndex(())]
614
614
615
615
Index into `A` with `I`, collapsing broadcasted indices to their singleton indices as appropriate.
616
616
"""
617
- Base. @propagate_inbounds _broadcast_getindex (A:: Union{Ref,AbstractArray{<:Any,0},Number} , I) = A[] # Scalar-likes can just ignore all indices
617
+ Base. @propagate_inbounds _broadcast_getindex (A:: Union{Ref,Some, AbstractArray{<:Any,0},Number} , I) = A[] # Scalar-likes can just ignore all indices
618
618
Base. @propagate_inbounds _broadcast_getindex (:: Ref{Type{T}} , I) where {T} = T
619
+ Base. @propagate_inbounds _broadcast_getindex (:: Some{Type{T}} , I) where {T} = T
619
620
# Tuples are statically known to be singleton or vector-like
620
621
Base. @propagate_inbounds _broadcast_getindex (A:: Tuple{Any} , I) = A[1 ]
621
622
Base. @propagate_inbounds _broadcast_getindex (A:: Tuple , I) = A[I[1 ]]
@@ -661,6 +662,20 @@ Base.@propagate_inbounds function _broadcast_getindex(bc::Broadcasted{<:Any,<:An
661
662
args = _getindex (tail (tail (bc. args)), I)
662
663
return _broadcast_getindex_evalf (bc. f, T, S, args... )
663
664
end
665
+ Base. @propagate_inbounds function _broadcast_getindex (bc:: Broadcasted {<: Any ,<: Any ,<: Any ,<: Tuple{Some{Type{T}},Vararg{Any}} }, I) where {T}
666
+ args = _getindex (tail (bc. args), I)
667
+ return _broadcast_getindex_evalf (bc. f, T, args... )
668
+ end
669
+ Base. @propagate_inbounds function _broadcast_getindex (bc:: Broadcasted {<: Any ,<: Any ,<: Any ,<: Tuple{Any,Some{Type{T}},Vararg{Any}} }, I) where {T}
670
+ arg1 = _broadcast_getindex (bc. args[1 ], I)
671
+ args = _getindex (tail (tail (bc. args)), I)
672
+ return _broadcast_getindex_evalf (bc. f, arg1, T, args... )
673
+ end
674
+ Base. @propagate_inbounds function _broadcast_getindex (bc:: Broadcasted {<: Any ,<: Any ,<: Any ,<: Tuple{Some{Type{T}},Some{Type{S}},Vararg{Any}} }, I) where {T,S}
675
+ args = _getindex (tail (tail (bc. args)), I)
676
+ return _broadcast_getindex_evalf (bc. f, T, S, args... )
677
+ end
678
+
664
679
665
680
# Utilities for _broadcast_getindex
666
681
Base. @propagate_inbounds _getindex (args:: Tuple , I) = (_broadcast_getindex (args[1 ], I), _getindex (tail (args), I)... )
@@ -691,15 +706,15 @@ julia> Broadcast.broadcastable([1,2,3]) # like `identity` since arrays already s
691
706
3
692
707
693
708
julia> Broadcast.broadcastable(Int) # Types don't support axes, indexing, or iteration but are commonly used as scalars
694
- Base.RefValue {Type{Int64}}(Int64)
709
+ Base.Some {Type{Int64}}(Int64)
695
710
696
711
julia> Broadcast.broadcastable("hello") # Strings break convention of matching iteration and act like a scalar instead
697
- Base.RefValue {String}("hello")
712
+ Base.Some {String}("hello")
698
713
```
699
714
"""
700
- broadcastable (x:: Union{Symbol,AbstractString,Function,UndefInitializer,Nothing,RoundingMode,Missing,Val,Ptr,AbstractPattern,Pair,IO} ) = Ref (x)
701
- broadcastable (:: Type{T} ) where {T} = Ref {Type{T}} (T)
702
- broadcastable (x:: Union{AbstractArray,Number,AbstractChar,Ref,Tuple,Broadcasted} ) = x
715
+ broadcastable (x:: Union{Symbol,AbstractString,Function,UndefInitializer,Nothing,RoundingMode,Missing,Val,Ptr,AbstractPattern,Pair,IO} ) = Some (x)
716
+ broadcastable (:: Type{T} ) where {T} = Some {Type{T}} (T)
717
+ broadcastable (x:: Union{AbstractArray,Number,AbstractChar,Some, Ref,Tuple,Broadcasted} ) = x
703
718
# Default to collecting iterables — which will error for non-iterables
704
719
broadcastable (x) = collect (x)
705
720
broadcastable (:: Union{AbstractDict, NamedTuple} ) = throw (ArgumentError (" broadcasting over dictionaries and `NamedTuple`s is reserved" ))
@@ -722,7 +737,7 @@ combine_eltypes(f, args::Tuple) =
722
737
"""
723
738
broadcast(f, As...)
724
739
725
- Broadcast the function `f` over the arrays, tuples, collections, [`Ref `](@ref)s and/or scalars `As`.
740
+ Broadcast the function `f` over the arrays, tuples, collections, [`Some `](@ref)s and/or scalars `As`.
726
741
727
742
Broadcasting applies the function `f` over the elements of the container arguments and the
728
743
scalars themselves in `As`. Singleton and missing dimensions are expanded to match the
@@ -781,7 +796,7 @@ julia> abs.((1, -2))
781
796
julia> broadcast(+, 1.0, (0, -2.0))
782
797
(1.0, -1.0)
783
798
784
- julia> (+).([[0,2], [1,3]], Ref {Vector{Int}}([1,-1]))
799
+ julia> (+).([[0,2], [1,3]], Some {Vector{Int}}([1,-1]))
785
800
2-element Vector{Vector{Int64}}:
786
801
[1, 1]
787
802
[2, 2]
0 commit comments