@@ -162,6 +162,32 @@ BroadcastStyle(a::AbstractArrayStyle{N}, ::DefaultArrayStyle{N}) where N = a
162
162
BroadcastStyle (a:: AbstractArrayStyle{M} , :: DefaultArrayStyle{N} ) where {M,N} =
163
163
typeof (a)(_max (Val (M),Val (N)))
164
164
165
+ # FIXME
166
+ # The following definitions are necessary to limit SparseArray broadcasting to "plain Arrays"
167
+ # (see https://github.com/JuliaLang/julia/pull/23939#pullrequestreview-72075382).
168
+ # They should be deleted once the sparse broadcast infrastucture is capable of handling
169
+ # arbitrary AbstractArrays.
170
+ struct VectorStyle <: AbstractArrayStyle{1} end
171
+ struct MatrixStyle <: AbstractArrayStyle{2} end
172
+ const VMStyle = Union{VectorStyle,MatrixStyle}
173
+ # These lose to DefaultArrayStyle
174
+ VectorStyle (:: Val{N} ) where N = DefaultArrayStyle {N} ()
175
+ MatrixStyle (:: Val{N} ) where N = DefaultArrayStyle {N} ()
176
+
177
+ BroadcastStyle (:: Type{<:Vector} ) = VectorStyle ()
178
+ BroadcastStyle (:: Type{<:Matrix} ) = MatrixStyle ()
179
+
180
+ BroadcastStyle (:: MatrixStyle , :: VectorStyle ) = MatrixStyle ()
181
+ BroadcastStyle (a:: AbstractArrayStyle{Any} , :: VectorStyle ) = a
182
+ BroadcastStyle (a:: AbstractArrayStyle{Any} , :: MatrixStyle ) = a
183
+ BroadcastStyle (a:: AbstractArrayStyle{N} , :: VectorStyle ) where N = typeof (a)(_max (Val (N), Val (1 )))
184
+ BroadcastStyle (a:: AbstractArrayStyle{N} , :: MatrixStyle ) where N = typeof (a)(_max (Val (N), Val (2 )))
185
+ BroadcastStyle (:: VectorStyle , :: DefaultArrayStyle{N} ) where N = DefaultArrayStyle (_max (Val (N), Val (1 )))
186
+ BroadcastStyle (:: MatrixStyle , :: DefaultArrayStyle{N} ) where N = DefaultArrayStyle (_max (Val (N), Val (2 )))
187
+ # to avoid the VectorStyle(::Val) constructor we also need the following
188
+ BroadcastStyle (:: VectorStyle , :: MatrixStyle ) = MatrixStyle ()
189
+ # end FIXME
190
+
165
191
# # Allocating the output container
166
192
"""
167
193
broadcast_similar(f, ::BroadcastStyle, ::Type{ElType}, inds, As...)
@@ -181,6 +207,17 @@ broadcast_similar(f, ::ArrayConflict, ::Type{ElType}, inds::Indices, As...) wher
181
207
broadcast_similar (f, :: ArrayConflict , :: Type{Bool} , inds:: Indices , As... ) =
182
208
similar (BitArray, inds)
183
209
210
+ # FIXME : delete when we get rid of VectorStyle and MatrixStyle
211
+ broadcast_similar (f, :: VectorStyle , :: Type{ElType} , inds:: Indices{1} , As... ) where ElType =
212
+ similar (Vector{ElType}, inds)
213
+ broadcast_similar (f, :: MatrixStyle , :: Type{ElType} , inds:: Indices{2} , As... ) where ElType =
214
+ similar (Matrix{ElType}, inds)
215
+ broadcast_similar (f, :: VectorStyle , :: Type{Bool} , inds:: Indices{1} , As... ) =
216
+ similar (BitArray, inds)
217
+ broadcast_similar (f, :: MatrixStyle , :: Type{Bool} , inds:: Indices{2} , As... ) =
218
+ similar (BitArray, inds)
219
+ # end FIXME
220
+
184
221
# # Computing the result's indices. Most types probably won't need to specialize this.
185
222
broadcast_indices () = ()
186
223
broadcast_indices (:: Type{T} ) where T = ()
@@ -582,7 +619,7 @@ Nullable{Complex{Float64}}()
582
619
broadcast (f, s, combine_eltypes (f, A, Bs... ), combine_indices (A, Bs... ),
583
620
A, Bs... )
584
621
585
- const NonleafHandlingTypes = Union{DefaultArrayStyle,ArrayConflict}
622
+ const NonleafHandlingTypes = Union{DefaultArrayStyle,ArrayConflict,VectorStyle,MatrixStyle }
586
623
587
624
@inline function broadcast (f, s:: NonleafHandlingTypes , :: Type{ElType} , inds:: Indices , As... ) where ElType
588
625
if ! Base. _isleaftype (ElType)
0 commit comments