@@ -428,6 +428,9 @@ broadcastable(x::Union{Symbol,AbstractString,Function,UndefInitializer,Nothing,R
428
428
broadcastable (x:: Ptr ) = Ref {Ptr} (x) # Cannot use Ref(::Ptr) until ambiguous deprecation goes through
429
429
broadcastable (:: Type{T} ) where {T} = Ref {Type{T}} (T)
430
430
broadcastable (x:: AbstractArray ) = x
431
+ # In the future, default to collecting arguments. TODO : uncomment once deprecations are removed
432
+ # broadcastable(x) = BroadcastStyle(typeof(x)) isa Unknown ? collect(x) : x
433
+ # broadcastable(::Union{AbstractDict, NamedTuple}) = error("intentionally unimplemented to allow development in 1.x")
431
434
432
435
"""
433
436
broadcast!(f, dest, As...)
@@ -548,17 +551,23 @@ combine_eltypes(f, A, As...) =
548
551
"""
549
552
broadcast(f, As...)
550
553
551
- Broadcasts the arrays, tuples, `Ref`s and/or scalars `As` to a
552
- container of the appropriate type and dimensions. In this context, anything
553
- that is not a subtype of `AbstractArray`, `Ref` (except for `Ptr`s) or `Tuple`
554
- is considered a scalar. The resulting container is established by
555
- the following rules:
556
-
557
- - If all the arguments are scalars, it returns a scalar.
558
- - If the arguments are tuples and zero or more scalars, it returns a tuple.
559
- - If the arguments contain at least one array or `Ref`, it returns an array
560
- (expanding singleton dimensions), and treats `Ref`s as 0-dimensional arrays,
561
- and tuples as 1-dimensional arrays.
554
+ Broadcast the function `f` over the arrays, tuples, collections, `Ref`s and/or scalars `As`.
555
+
556
+ Broadcasting applies the function `f` over the elements of the container arguments and the
557
+ scalars themselves in `As`. Singleton and missing dimensions are expanded to match the
558
+ extents of the other arguments by virtually repeating the value. By default, only a limited
559
+ number of types are considered scalars, including `Number`s, `String`s, `Symbol`s, `Type`s,
560
+ `Function`s and some common singletons like `missing` and `nothing`. All other arguments are
561
+ iterated over or indexed into elementwise.
562
+
563
+ The resulting container type is established by the following rules:
564
+
565
+ - If all the arguments are scalars or zero-dimensional arrays, it returns an unwrapped scalar.
566
+ - If at least one argument is a tuple and all others are scalars or zero-dimensional arrays,
567
+ it returns a tuple.
568
+ - All other combinations of arguments default to returning an `Array`, but
569
+ custom container types can define their own implementation and promotion-like
570
+ rules to customize the result when they appear as arguments.
562
571
563
572
A special syntax exists for broadcasting: `f.(args...)` is equivalent to
564
573
`broadcast(f, args...)`, and nested `f.(g.(args...))` calls are fused into a
0 commit comments