@@ -267,7 +267,7 @@ 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
269
@inline function instantiate (bc:: Broadcasted{Style} ) where {Style}
270
- args = instantiate (bc. args)
270
+ args = instantiate_args (bc. args)
271
271
if bc. axes isa Nothing
272
272
axes = combine_indices (args... )
273
273
else
279
279
280
280
instantiate (bc:: Broadcasted{<:Union{AbstractArrayStyle{0}, Style{Tuple}}} ) = bc
281
281
282
- @inline instantiate (args:: Tuple ) = (instantiate (args[1 ]), instantiate (Base. tail (args))... )
283
- instantiate (args:: Tuple{} ) = ()
282
+ @inline instantiate_args (args:: Tuple ) = (instantiate (args[1 ]), instantiate_args (Base. tail (args))... )
283
+ instantiate_args (args:: Tuple{} ) = ()
284
284
285
285
# # Flattening
286
286
@@ -526,38 +526,37 @@ Base.@propagate_inbounds Base.getindex(bc::Broadcasted{Nothing}, I) =
526
526
Base. @propagate_inbounds _broadcast_getindex (:: Base.RefValue{Type{T}} , I) where {T} = T
527
527
Base. @propagate_inbounds _broadcast_getindex (A:: Tuple{Any} , I) = A[1 ]
528
528
Base. @propagate_inbounds _broadcast_getindex (A:: Tuple , I) = A[I[1 ]]
529
- Base. @propagate_inbounds _broadcast_getindex (A, I) = _broadcast_getindex (combine_styles (A), A, I)
530
- Base. @propagate_inbounds _broadcast_getindex (:: AbstractArrayStyle{0} , A, I) = A[]
531
- Base. @propagate_inbounds _broadcast_getindex (:: Any , A, I) = A[I]
529
+ Base. @propagate_inbounds _broadcast_getindex (A:: Ref , I) = A[]
530
+ Base. @propagate_inbounds _broadcast_getindex (A, I) = A[I]
532
531
533
532
# For Broadcasted
534
- Base. @propagate_inbounds _broadcast_getindex (bc:: Broadcasted , I) = _broadcast_getindex_bc (bc, I, bc. indexing)
533
+ Base. @propagate_inbounds function _broadcast_getindex (bc:: Broadcasted , I)
534
+ bc. indexing isa Nothing && throw (ArgumentError (" a Broadcasted{$Style } wrapper skipped instantiation but has not defined _broadcast_getindex" ))
535
+ args = _getindex (bc. args, I, bc. indexing)
536
+ return _broadcast_getindex_evalf (bc. f, args... )
537
+ end
535
538
536
539
Base. @propagate_inbounds _broadcast_getindex (bc:: Broadcasted{<:Union{Style{Tuple}, AbstractArrayStyle{0}}} , I) =
537
540
_broadcast_getindex_evalf (bc. f, _getindex (bc. args, I)... )
538
541
539
542
# Utilities for _broadcast_getindex
540
543
# For most styles
541
- Base. @propagate_inbounds _getidx (arg, I, keep_default) = _broadcast_getindex (arg, newindex (I, keep_default... ))
542
- Base. @propagate_inbounds _getindex (args:: Tuple , I, indexing:: Tuple ) =
543
- (_getidx (args[1 ], I, indexing[1 ]), _getindex (tail (args), I, tail (indexing))... )
544
- Base. @propagate_inbounds _getindex (args:: Tuple{Any} , I, indexing:: Tuple{Any} ) =
545
- (_getidx (args[1 ], I, indexing[1 ]),)
546
- Base. @propagate_inbounds _getindex (args:: Tuple{} , I, :: Tuple ) = ()
547
- Base. @propagate_inbounds _getindex (args:: Tuple{} , I, :: Tuple{Any} ) = ()
544
+ Base. @propagate_inbounds _getindex (args:: Tuple , I, indexing) =
545
+ (_broadcast_getindex (args[1 ], newindex (I, indexing[1 ][1 ], indexing[1 ][2 ])), _getindex (tail (args), I, tail (indexing))... )
546
+ Base. @propagate_inbounds _getindex (args:: Tuple{Any} , I, indexing) =
547
+ (_broadcast_getindex (args[1 ], newindex (I, indexing[1 ][1 ], indexing[1 ][2 ])),)
548
+ Base. @propagate_inbounds _getindex (args:: Tuple{Any,Any} , I, indexing) =
549
+ (_broadcast_getindex (args[1 ], newindex (I, indexing[1 ][1 ], indexing[1 ][2 ])),
550
+ _broadcast_getindex (args[2 ], newindex (I, indexing[2 ][1 ], indexing[2 ][2 ])))
551
+ Base. @propagate_inbounds _getindex (args:: Tuple{} , I, indexing) = ()
548
552
# For styles skipping reindexers
549
553
Base. @propagate_inbounds _getindex (args:: Tuple , I) = (_broadcast_getindex (args[1 ], I), _getindex (tail (args), I)... )
550
554
Base. @propagate_inbounds _getindex (args:: Tuple{Any} , I) = (_broadcast_getindex (args[1 ], I),)
555
+ Base. @propagate_inbounds _getindex (args:: Tuple{Any,Any} , I) =
556
+ (_broadcast_getindex (args[1 ], I), _broadcast_getindex (args[2 ], I))
551
557
Base. @propagate_inbounds _getindex (args:: Tuple{} , I) = ()
552
558
553
559
554
- Base. @propagate_inbounds function _broadcast_getindex_bc (bc:: Broadcasted{Style} , I, indexing) where {Style}
555
- args = _getindex (bc. args, I, indexing)
556
- return _broadcast_getindex_evalf (bc. f, args... )
557
- end
558
- _broadcast_getindex_bc (bc:: Broadcasted{Style} , I, :: Nothing ) where {Style} =
559
- throw (ArgumentError (" a Broadcasted{$Style } wrapper skipped instantiation but has not defined _broadcast_getindex" ))
560
-
561
560
"""
562
561
broadcastable(x)
563
562
786
785
# LHS and RHS will always match. This is not true in general, but with the `.op=`
787
786
# syntax it's fairly common for an argument to be `===` a source.
788
787
broadcast_unalias (dest, src) = dest === src ? src : unalias (dest, src)
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)
790
- map_broadcasted_args (f, arg) = f (arg)
788
+
789
+ @inline map_broadcast_unalias (dest, bc:: Broadcasted ) = typeof (bc)(bc. f, map_broadcast_unalias_args (dest, bc. args), bc. axes, bc. indexing)
790
+ map_broadcast_unalias (dest, x) = broadcast_unalias (dest, x)
791
+
792
+ @inline map_broadcast_unalias_args (dest, args:: Tuple ) = (map_broadcast_unalias (dest, args[1 ]), map_broadcast_unalias_args (dest, tail (args))... )
793
+ map_broadcast_unalias_args (dest, args:: Tuple{Any} ) = (map_broadcast_unalias (dest, args[1 ]),)
794
+ map_broadcast_unalias_args (dest, args:: Tuple{} ) = ()
791
795
792
796
# Specialize this method if all you want to do is specialize on typeof(dest)
793
797
@inline function copyto! (dest:: AbstractArray , bc:: Broadcasted{Nothing} )
@@ -799,7 +803,7 @@ map_broadcasted_args(f, arg) = f(arg)
799
803
return copyto! (dest, A)
800
804
end
801
805
end
802
- bc′ = map_broadcasted_args (arg -> broadcast_unalias ( dest, arg) , bc)
806
+ bc′ = map_broadcast_unalias ( dest, bc)
803
807
@simd for I in CartesianIndices (axes (bc′))
804
808
@inbounds dest[I] = bc′[I]
805
809
end
0 commit comments