@@ -179,10 +179,10 @@ end
179
179
end
180
180
end
181
181
182
- @testset " broadcast over combinations of scalars and sparse vectors/matrices" begin
183
- N, M, p = 10 , 12 , 0.3
182
+ @testset " broadcast[!] over combinations of scalars and sparse vectors/matrices" begin
183
+ N, M, p = 10 , 12 , 0.5
184
184
elT = Float64
185
- s = elT (2.0 )
185
+ s = Float32 (2.0 )
186
186
V = sprand (elT, N, p)
187
187
A = sprand (elT, N, M, p)
188
188
fV, fA = Array (V), Array (A)
212
212
((s, spargsl... , s, s, spargsr... ), (s, dargsl... , s, s, dargsr... )),
213
213
((spargsl... , s, s, spargsr... , s), (dargsl... , s, s, dargsr... , s)),
214
214
((spargsl... , s, s, s, spargsr... ), (dargsl... , s, s, s, dargsr... )), )
215
+ # test broadcast entry point
215
216
@test broadcast (* , sparseargs... ) == sparse (broadcast (* , denseargs... ))
216
217
@test isa (@inferred (broadcast (* , sparseargs... )), SparseMatrixCSC{elT})
218
+ # test broadcast! entry point
219
+ fX = broadcast (* , sparseargs... ); X = sparse (fX)
220
+ @test broadcast! (* , X, sparseargs... ) == sparse (broadcast! (* , fX, denseargs... ))
221
+ @test isa (@inferred (broadcast! (* , X, sparseargs... )), SparseMatrixCSC{elT})
222
+ X = sparse (fX) # reset / warmup for @allocated test
223
+ @test_broken (@allocated broadcast! (* , X, sparseargs... )) == 0
224
+ # This test (and the analog below) fails for three reasons:
225
+ # (1) In all cases, generating the closures that capture the scalar arguments
226
+ # results in allocation, not sure why.
227
+ # (2) In some cases, though _broadcast_eltype (which wraps _return_type)
228
+ # consistently provides the correct result eltype when passed the closure
229
+ # that incorporates the scalar arguments to broadcast (and, with #19667,
230
+ # is inferable, so the overall return type from broadcast is inferred),
231
+ # in some cases inference seems unable to determine the return type of
232
+ # direct calls to that closure. This issue causes variables in in both the
233
+ # broadcast[!] entry points (fofzeros = f(_zeros_eltypes(args...)...)) and
234
+ # the driver routines (Cx in _map_zeropres! and _broadcast_zeroprs!) to have
235
+ # inferred type Any, resulting in allocation and lackluster performance.
236
+ # (3) The sparseargs... splat in the call above allocates a bit, but of course
237
+ # that issue is negligible and perhaps could be accounted for in the test.
217
238
end
218
239
end
219
240
# test combinations at the limit of inference (eight arguments net)
225
246
((s, V, A, s, V, A, s, A), (s, fV, fA, s, fV, fA, s, fA)), # three scalars, five sparse vectors/matrices
226
247
((V, A, V, s, A, V, A, s), (fV, fA, fV, s, fA, fV, fA, s)), # two scalars, six sparse vectors/matrices
227
248
((V, A, V, A, s, V, A, V), (fV, fA, fV, fA, s, fV, fA, fV)) ) # one scalar, seven sparse vectors/matrices
249
+ # test broadcast entry point
228
250
@test broadcast (* , sparseargs... ) == sparse (broadcast (* , denseargs... ))
229
251
@test isa (@inferred (broadcast (* , sparseargs... )), SparseMatrixCSC{elT})
252
+ # test broadcast! entry point
253
+ fX = broadcast (* , sparseargs... ); X = sparse (fX)
254
+ @test broadcast! (* , X, sparseargs... ) == sparse (broadcast! (* , fX, denseargs... ))
255
+ @test isa (@inferred (broadcast! (* , X, sparseargs... )), SparseMatrixCSC{elT})
256
+ X = sparse (fX) # reset / warmup for @allocated test
257
+ @test_broken (@allocated broadcast! (* , X, sparseargs... )) == 0
258
+ # please see the note a few lines above re. this @test_broken
230
259
end
231
260
end
232
261
0 commit comments