@@ -6,7 +6,7 @@ using .Base.Cartesian
6
6
using . Base: Indices, OneTo, linearindices, tail, to_shape, isoperator, promote_typejoin,
7
7
_msk_end, unsafe_bitgetindex, bitcache_chunks, bitcache_size, dumpbitcache, unalias
8
8
import . Base: broadcast, broadcast!, copy, copyto!
9
- export BroadcastStyle, broadcast_indices , broadcast_similar, broadcastable,
9
+ export BroadcastStyle, broadcast_axes , broadcast_similar, broadcastable,
10
10
broadcast_getindex, broadcast_setindex!, dotview, @__dot__
11
11
12
12
# ## Objects with customized broadcasting behavior should declare a BroadcastStyle
@@ -188,7 +188,7 @@ Base.show(io::IO, bc::Broadcasted{Style}) where {Style} = print(io, Broadcasted,
188
188
broadcast_similar(::BroadcastStyle, ::Type{ElType}, inds, As...)
189
189
190
190
Allocate an output object for [`broadcast`](@ref), appropriate for the indicated
191
- [`Broadcast.BroadcastStyle`](@ref). `ElType` and `inds` specify the desired element type and indices of the
191
+ [`Broadcast.BroadcastStyle`](@ref). `ElType` and `inds` specify the desired element type and axes of the
192
192
container. `As...` are the input arguments supplied to `broadcast`.
193
193
"""
194
194
broadcast_similar (:: DefaultArrayStyle{N} , :: Type{ElType} , inds:: Indices{N} , bc) where {N,ElType} =
@@ -201,25 +201,25 @@ broadcast_similar(::ArrayConflict, ::Type{ElType}, inds::Indices, bc) where ElTy
201
201
broadcast_similar (:: ArrayConflict , :: Type{Bool} , inds:: Indices , bc) =
202
202
similar (BitArray, inds)
203
203
204
- # # Computing the result's indices . Most types probably won't need to specialize this.
205
- broadcast_indices () = ()
206
- broadcast_indices (A:: Tuple ) = (OneTo (length (A)),)
207
- broadcast_indices (A:: Ref ) = ()
208
- broadcast_indices (A) = axes (A)
204
+ # # Computing the result's axes . Most types probably won't need to specialize this.
205
+ broadcast_axes () = ()
206
+ broadcast_axes (A:: Tuple ) = (OneTo (length (A)),)
207
+ broadcast_axes (A:: Ref ) = ()
208
+ broadcast_axes (A) = axes (A)
209
209
"""
210
- Base.broadcast_indices(::SrcStyle, A)
210
+ Base.broadcast_axes( A)
211
211
212
- Compute the indices for objects `A` with [`BroadcastStyle`](@ref) `SrcStyle `.
213
- If needed, you can specialize this method for your styles.
214
- You should only need to provide a custom implementation for non-AbstractArrayStyles .
212
+ Compute the axes for `A `.
213
+
214
+ This should only be specialized for objects that do not define axes but want to participate in broadcasting .
215
215
"""
216
- broadcast_indices
216
+ broadcast_axes
217
217
218
218
# ## End of methods that users will typically have to specialize ###
219
219
220
220
Base. axes (bc:: Broadcasted ) = _axes (bc, bc. axes)
221
221
_axes (:: Broadcasted , axes:: Tuple ) = axes
222
- _axes (bc:: Broadcasted , :: Nothing ) = combine_indices (bc. args... )
222
+ _axes (bc:: Broadcasted , :: Nothing ) = combine_axes (bc. args... )
223
223
_axes (bc:: Broadcasted{Style{Tuple}} , :: Nothing ) = (Base. OneTo (length (longest_tuple (nothing , bc. args))),)
224
224
_axes (bc:: Broadcasted{<:AbstractArrayStyle{0}} , :: Nothing ) = ()
225
225
@@ -252,10 +252,10 @@ they must provide their own `Base.axes(::Broadcasted{Style})` and
252
252
"""
253
253
@inline function instantiate (bc:: Broadcasted{Style} ) where {Style}
254
254
if bc. axes isa Nothing # Not done via dispatch to make it easier to extend instantiate(::Broadcasted{Style})
255
- axes = combine_indices (bc. args... )
255
+ axes = combine_axes (bc. args... )
256
256
else
257
257
axes = bc. axes
258
- check_broadcast_indices (axes, bc. args... )
258
+ check_broadcast_axes (axes, bc. args... )
259
259
end
260
260
return Broadcasted {Style} (bc. f, bc. args, axes)
261
261
end
@@ -411,8 +411,8 @@ One of these should be undefined (and thus return Broadcast.Unknown).""")
411
411
end
412
412
413
413
# Indices utilities
414
- combine_indices (A, B... ) = broadcast_shape (broadcast_indices (A), combine_indices (B... ))
415
- combine_indices (A) = broadcast_indices (A)
414
+ combine_axes (A, B... ) = broadcast_shape (broadcast_axes (A), combine_axes (B... ))
415
+ combine_axes (A) = broadcast_axes (A)
416
416
417
417
# shape (i.e., tuple-of-indices) inputs
418
418
broadcast_shape (shape:: Tuple ) = shape
@@ -444,11 +444,11 @@ function check_broadcast_shape(shp, Ashp::Tuple)
444
444
_bcsm (shp[1 ], Ashp[1 ]) || throw (DimensionMismatch (" array could not be broadcast to match destination" ))
445
445
check_broadcast_shape (tail (shp), tail (Ashp))
446
446
end
447
- check_broadcast_indices (shp, A) = check_broadcast_shape (shp, broadcast_indices (A))
447
+ check_broadcast_axes (shp, A) = check_broadcast_shape (shp, broadcast_axes (A))
448
448
# comparing many inputs
449
- @inline function check_broadcast_indices (shp, A, As... )
450
- check_broadcast_indices (shp, A)
451
- check_broadcast_indices (shp, As... )
449
+ @inline function check_broadcast_axes (shp, A, As... )
450
+ check_broadcast_axes (shp, A)
451
+ check_broadcast_axes (shp, As... )
452
452
end
453
453
454
454
# # Indexing manipulations
@@ -468,8 +468,8 @@ an `Int`.
468
468
Any remaining indices in `I` beyond the length of the `keep` tuple are truncated. The `keep` and `default`
469
469
tuples may be created by `newindexer(argument)`.
470
470
"""
471
- Base. @propagate_inbounds newindex (arg, I:: CartesianIndex ) = CartesianIndex (_newindex (broadcast_indices (arg), I. I))
472
- Base. @propagate_inbounds newindex (arg, I:: Int ) = CartesianIndex (_newindex (broadcast_indices (arg), (I,)))
471
+ Base. @propagate_inbounds newindex (arg, I:: CartesianIndex ) = CartesianIndex (_newindex (broadcast_axes (arg), I. I))
472
+ Base. @propagate_inbounds newindex (arg, I:: Int ) = CartesianIndex (_newindex (broadcast_axes (arg), (I,)))
473
473
Base. @propagate_inbounds _newindex (ax:: Tuple , I:: Tuple ) = (ifelse (Base. unsafe_length (ax[1 ])== 1 , ax[1 ][1 ], I[1 ]), _newindex (tail (ax), tail (I))... )
474
474
Base. @propagate_inbounds _newindex (ax:: Tuple{} , I:: Tuple ) = ()
475
475
Base. @propagate_inbounds _newindex (ax:: Tuple , I:: Tuple{} ) = (ax[1 ][1 ], _newindex (tail (ax), ())... )
@@ -484,7 +484,7 @@ Base.@propagate_inbounds _newindex(ax::Tuple{}, I::Tuple{}) = ()
484
484
485
485
# newindexer(A) generates `keep` and `Idefault` (for use by `newindex` above)
486
486
# for a particular array `A`; `shapeindexer` does so for its axes.
487
- @inline newindexer (A) = shapeindexer (broadcast_indices (A))
487
+ @inline newindexer (A) = shapeindexer (broadcast_axes (A))
488
488
@inline shapeindexer (ax) = _newindexer (ax)
489
489
@inline _newindexer (indsA:: Tuple{} ) = (), ()
490
490
@inline function _newindexer (indsA:: Tuple )
@@ -525,7 +525,7 @@ struct Extruded{T, K, D}
525
525
keeps:: K # A tuple of booleans, specifying which indices should be passed normally
526
526
defaults:: D # A tuple of integers, specifying the index to use when keeps[i] is false (as defaults[i])
527
527
end
528
- @inline broadcast_indices (b:: Extruded ) = broadcast_indices (b. x)
528
+ @inline broadcast_axes (b:: Extruded ) = broadcast_axes (b. x)
529
529
Base. @propagate_inbounds _broadcast_getindex (b:: Extruded , i) = b. x[newindex (i, b. keeps, b. defaults)]
530
530
extrude (x:: AbstractArray ) = Extruded (x, newindexer (x)... )
531
531
extrude (x) = x
@@ -1034,14 +1034,14 @@ julia> broadcast_getindex(A, [1 2 1; 1 2 2], [1, 2])
1034
1034
```
1035
1035
"""
1036
1036
broadcast_getindex (src:: AbstractArray , I:: AbstractArray... ) =
1037
- broadcast_getindex! (Base. similar (Array{eltype (src)}, combine_indices (I... )), src, I... )
1037
+ broadcast_getindex! (Base. similar (Array{eltype (src)}, combine_axes (I... )), src, I... )
1038
1038
1039
1039
@generated function broadcast_getindex! (dest:: AbstractArray , src:: AbstractArray , I:: AbstractArray... )
1040
1040
N = length (I)
1041
1041
Isplat = Expr[:(I[$ d]) for d = 1 : N]
1042
1042
quote
1043
1043
@nexprs $ N d-> (I_d = I[d])
1044
- check_broadcast_indices (Base. axes (dest), $ (Isplat... )) # unnecessary if this function is never called directly
1044
+ check_broadcast_axes (Base. axes (dest), $ (Isplat... )) # unnecessary if this function is never called directly
1045
1045
checkbounds (src, $ (Isplat... ))
1046
1046
@nexprs $ N d-> (@nexprs $ N k-> (Ibcast_d_k = Base. axes (I_k, d) == OneTo (1 )))
1047
1047
@nloops $ N i dest d-> (@nexprs $ N k-> (j_d_k = Ibcast_d_k ? 1 : i_d)) begin
@@ -1072,7 +1072,7 @@ See [`broadcast_getindex`](@ref) for examples of the treatment of `inds`.
1072
1072
quote
1073
1073
@nexprs $ N d-> (I_d = I[d])
1074
1074
checkbounds (A, $ (Isplat... ))
1075
- shape = combine_indices ($ (Isplat... ))
1075
+ shape = combine_axes ($ (Isplat... ))
1076
1076
@nextract $ N shape d-> (length (shape) < d ? OneTo (1 ) : shape[d])
1077
1077
@nexprs $ N d-> (@nexprs $ N k-> (Ibcast_d_k = Base. axes (I_k, d) == 1 : 1 ))
1078
1078
if ! isa (x, AbstractArray)
0 commit comments