@@ -266,28 +266,22 @@ of the `Broadcasted` object empty (populated with `nothing`). If they do so, how
266
266
they must provide their own `Base.axes(::Broadcasted{Style})` and
267
267
`Base.getindex(::Broadcasted{Style}, I::Union{Int,CartesianIndex})` methods as appropriate.
268
268
"""
269
- @inline instantiate (bc:: Broadcasted{Style} ) where {Style} = _instantiate (bc)
270
-
271
- _instantiate (bc) = bc
272
-
273
- @inline function _instantiate (bc:: Broadcasted{Style,Nothing,Nothing} ) where {Style}
274
- args = map (instantiate, bc. args)
275
- axes = combine_indices (args... )
276
- @inline _newindexer (arg) = newindexer (axes, arg)
277
- indexing = map (_newindexer, args)
278
- return Broadcasted {Style} (bc. f, args, axes, indexing)
279
- end
280
-
281
- @inline function _instantiate (bc:: Broadcasted{Style,<:Any,Nothing} ) where {Style}
282
- args = map (instantiate, bc. args)
283
- axes = broadcast_shape (bc. axes, combine_indices (args... ))
284
- @inline _newindexer (arg) = newindexer (axes, arg)
285
- indexing = map (_newindexer, args)
269
+ @inline function instantiate (bc:: Broadcasted{Style} ) where {Style}
270
+ args = instantiate (bc. args)
271
+ if bc. axes isa Nothing
272
+ axes = combine_indices (args... )
273
+ else
274
+ axes = broadcast_shape (bc. axes, combine_indices (args... ))
275
+ end
276
+ indexing = map_newindexer (axes, args)
286
277
return Broadcasted {Style} (bc. f, args, axes, indexing)
287
278
end
288
279
289
280
instantiate (bc:: Broadcasted{<:Union{AbstractArrayStyle{0}, Style{Tuple}}} ) = bc
290
281
282
+ @inline instantiate (args:: Tuple ) = (instantiate (args[1 ]), instantiate (Base. tail (args))... )
283
+ instantiate (args:: Tuple{} ) = ()
284
+
291
285
# # Flattening
292
286
293
287
"""
516
510
end
517
511
518
512
# Equivalent to map(x->newindexer(shape, x), As) (but see #17126)
519
- map_newindexer (shape, :: Tuple{} ) = (), ()
520
- @inline function map_newindexer (shape, As)
521
- A1 = As[1 ]
522
- keeps, Idefaults = map_newindexer (shape, tail (As))
523
- keep, Idefault = newindexer (shape, A1)
524
- (keep, keeps... ), (Idefault, Idefaults... )
525
- end
526
- @inline function map_newindexer (shape, A, Bs)
527
- keeps, Idefaults = map_newindexer (shape, Bs)
528
- keep, Idefault = newindexer (shape, A)
529
- (keep, keeps... ), (Idefault, Idefaults... )
530
- end
513
+ map_newindexer (shape, :: Tuple{} ) = ()
514
+ @inline map_newindexer (shape, As) = (newindexer (shape, As[1 ]), map_newindexer (shape, tail (As))... )
531
515
532
516
@inline function Base. getindex (bc:: Broadcasted , I)
533
517
@boundscheck checkbounds (bc, I)
802
786
# LHS and RHS will always match. This is not true in general, but with the `.op=`
803
787
# syntax it's fairly common for an argument to be `===` a source.
804
788
broadcast_unalias (dest, src) = dest === src ? src : unalias (dest, src)
805
- map_broadcasted_args (f, bc:: Broadcasted ) = typeof (bc)(bc. f, map (arg-> map_broadcasted_args (f, arg), bc. args), bc. axes, bc. indexing)
789
+ @inline map_broadcasted_args (f, bc:: Broadcasted ) = typeof (bc)(bc. f, map (arg-> map_broadcasted_args (f, arg), bc. args), bc. axes, bc. indexing)
806
790
map_broadcasted_args (f, arg) = f (arg)
807
791
808
792
# Specialize this method if all you want to do is specialize on typeof(dest)
0 commit comments