@@ -10,9 +10,12 @@ module Broadcast
1010using . Base. Cartesian
1111using . Base: Indices, OneTo, tail, to_shape, isoperator, promote_typejoin,
1212 _msk_end, unsafe_bitgetindex, bitcache_chunks, bitcache_size, dumpbitcache, unalias
13- import . Base: copy, copyto!
13+ import . Base: copy, copyto!, axes
1414export broadcast, broadcast!, BroadcastStyle, broadcast_axes, broadcastable, dotview, @__dot__
1515
16+ # # Computing the result's axes: deprecated name
17+ const broadcast_axes = axes
18+
1619# ## Objects with customized broadcasting behavior should declare a BroadcastStyle
1720
1821"""
@@ -200,16 +203,6 @@ Base.similar(bc::Broadcasted{ArrayConflict}, ::Type{ElType}) where ElType =
200203Base. similar (bc:: Broadcasted{ArrayConflict} , :: Type{Bool} ) =
201204 similar (BitArray, axes (bc))
202205
203- # # Computing the result's axes. Most types probably won't need to specialize this.
204- """
205- Base.broadcast_axes(A)
206-
207- Compute the axes for `A`.
208-
209- This should only be specialized for objects that do not define [`axes`](@ref) but want to participate in broadcasting.
210- """
211- @inline broadcast_axes (A) = axes (A)
212-
213206@inline Base. axes (bc:: Broadcasted ) = _axes (bc, bc. axes)
214207_axes (:: Broadcasted , axes:: Tuple ) = axes
215208@inline _axes (bc:: Broadcasted , :: Nothing ) = combine_axes (bc. args... )
@@ -425,8 +418,8 @@ One of these should be undefined (and thus return Broadcast.Unknown).""")
425418end
426419
427420# Indices utilities
428- @inline combine_axes (A, B... ) = broadcast_shape (broadcast_axes (A), combine_axes (B... ))
429- combine_axes (A) = broadcast_axes (A)
421+ @inline combine_axes (A, B... ) = broadcast_shape (axes (A), combine_axes (B... ))
422+ combine_axes (A) = axes (A)
430423
431424# shape (i.e., tuple-of-indices) inputs
432425broadcast_shape (shape:: Tuple ) = shape
@@ -458,7 +451,7 @@ function check_broadcast_shape(shp, Ashp::Tuple)
458451 _bcsm (shp[1 ], Ashp[1 ]) || throw (DimensionMismatch (" array could not be broadcast to match destination" ))
459452 check_broadcast_shape (tail (shp), tail (Ashp))
460453end
461- check_broadcast_axes (shp, A) = check_broadcast_shape (shp, broadcast_axes (A))
454+ check_broadcast_axes (shp, A) = check_broadcast_shape (shp, axes (A))
462455# comparing many inputs
463456@inline function check_broadcast_axes (shp, A, As... )
464457 check_broadcast_axes (shp, A)
@@ -482,8 +475,8 @@ an `Int`.
482475 Any remaining indices in `I` beyond the length of the `keep` tuple are truncated. The `keep` and `default`
483476 tuples may be created by `newindexer(argument)`.
484477"""
485- Base. @propagate_inbounds newindex (arg, I:: CartesianIndex ) = CartesianIndex (_newindex (broadcast_axes (arg), I. I))
486- Base. @propagate_inbounds newindex (arg, I:: Integer ) = CartesianIndex (_newindex (broadcast_axes (arg), (I,)))
478+ Base. @propagate_inbounds newindex (arg, I:: CartesianIndex ) = CartesianIndex (_newindex (axes (arg), I. I))
479+ Base. @propagate_inbounds newindex (arg, I:: Integer ) = CartesianIndex (_newindex (axes (arg), (I,)))
487480Base. @propagate_inbounds _newindex (ax:: Tuple , I:: Tuple ) = (ifelse (Base. unsafe_length (ax[1 ])== 1 , ax[1 ][1 ], I[1 ]), _newindex (tail (ax), tail (I))... )
488481Base. @propagate_inbounds _newindex (ax:: Tuple{} , I:: Tuple ) = ()
489482Base. @propagate_inbounds _newindex (ax:: Tuple , I:: Tuple{} ) = (ax[1 ][1 ], _newindex (tail (ax), ())... )
@@ -499,7 +492,7 @@ Base.@propagate_inbounds _newindex(ax::Tuple{}, I::Tuple{}) = ()
499492
500493# newindexer(A) generates `keep` and `Idefault` (for use by `newindex` above)
501494# for a particular array `A`; `shapeindexer` does so for its axes.
502- @inline newindexer (A) = shapeindexer (broadcast_axes (A))
495+ @inline newindexer (A) = shapeindexer (axes (A))
503496@inline shapeindexer (ax) = _newindexer (ax)
504497@inline _newindexer (indsA:: Tuple{} ) = (), ()
505498@inline function _newindexer (indsA:: Tuple )
@@ -542,7 +535,7 @@ struct Extruded{T, K, D}
542535 keeps:: K # A tuple of booleans, specifying which indices should be passed normally
543536 defaults:: D # A tuple of integers, specifying the index to use when keeps[i] is false (as defaults[i])
544537end
545- @inline broadcast_axes (b:: Extruded ) = broadcast_axes (b. x)
538+ @inline axes (b:: Extruded ) = axes (b. x)
546539Base. @propagate_inbounds _broadcast_getindex (b:: Extruded , i) = b. x[newindex (i, b. keeps, b. defaults)]
547540extrude (x:: AbstractArray ) = Extruded (x, newindexer (x)... )
548541extrude (x) = x
@@ -948,10 +941,10 @@ end
948941# # Tuple methods
949942
950943@inline function copy (bc:: Broadcasted{Style{Tuple}} )
951- axes = broadcast_axes (bc)
952- length (axes ) == 1 || throw (DimensionMismatch (" tuple only supports one dimension" ))
953- N = Val ( length (axes [1 ]) )
954- return ntuple (k -> @inbounds (_broadcast_getindex (bc, k)), N )
944+ dim = axes (bc)
945+ length (dim ) == 1 || throw (DimensionMismatch (" tuple only supports one dimension" ))
946+ N = length (dim [1 ])
947+ return ntuple (k -> @inbounds (_broadcast_getindex (bc, k)), Val (N) )
955948end
956949
957950# # scalar-range broadcast operations ##
0 commit comments