@@ -193,10 +193,10 @@ end
193
193
end
194
194
end
195
195
196
- @testset " broadcast over combinations of scalars and sparse vectors/matrices" begin
197
- N, M, p = 10 , 12 , 0.3
196
+ @testset " broadcast[!] over combinations of scalars and sparse vectors/matrices" begin
197
+ N, M, p = 10 , 12 , 0.5
198
198
elT = Float64
199
- s = elT (2.0 )
199
+ s = Float32 (2.0 )
200
200
V = sprand (elT, N, p)
201
201
A = sprand (elT, N, M, p)
202
202
fV, fA = Array (V), Array (A)
226
226
((s, spargsl... , s, s, spargsr... ), (s, dargsl... , s, s, dargsr... )),
227
227
((spargsl... , s, s, spargsr... , s), (dargsl... , s, s, dargsr... , s)),
228
228
((spargsl... , s, s, s, spargsr... ), (dargsl... , s, s, s, dargsr... )), )
229
+ # test broadcast entry point
229
230
@test broadcast (* , sparseargs... ) == sparse (broadcast (* , denseargs... ))
230
231
@test isa (@inferred (broadcast (* , sparseargs... )), SparseMatrixCSC{elT})
232
+ # test broadcast! entry point
233
+ fX = broadcast (* , sparseargs... ); X = sparse (fX)
234
+ @test broadcast! (* , X, sparseargs... ) == sparse (broadcast! (* , fX, denseargs... ))
235
+ @test isa (@inferred (broadcast! (* , X, sparseargs... )), SparseMatrixCSC{elT})
236
+ X = sparse (fX) # reset / warmup for @allocated test
237
+ @test_broken (@allocated broadcast! (* , X, sparseargs... )) == 0
238
+ # This test (and the analog below) fails for three reasons:
239
+ # (1) In all cases, generating the closures that capture the scalar arguments
240
+ # results in allocation, not sure why.
241
+ # (2) In some cases, though _broadcast_eltype (which wraps _return_type)
242
+ # consistently provides the correct result eltype when passed the closure
243
+ # that incorporates the scalar arguments to broadcast (and, with #19667,
244
+ # is inferable, so the overall return type from broadcast is inferred),
245
+ # in some cases inference seems unable to determine the return type of
246
+ # direct calls to that closure. This issue causes variables in both the
247
+ # broadcast[!] entry points (fofzeros = f(_zeros_eltypes(args...)...)) and
248
+ # the driver routines (Cx in _map_zeropres! and _broadcast_zeropres!) to have
249
+ # inferred type Any, resulting in allocation and lackluster performance.
250
+ # (3) The sparseargs... splat in the call above allocates a bit, but of course
251
+ # that issue is negligible and perhaps could be accounted for in the test.
231
252
end
232
253
end
233
254
# test combinations at the limit of inference (eight arguments net)
239
260
((s, V, A, s, V, A, s, A), (s, fV, fA, s, fV, fA, s, fA)), # three scalars, five sparse vectors/matrices
240
261
((V, A, V, s, A, V, A, s), (fV, fA, fV, s, fA, fV, fA, s)), # two scalars, six sparse vectors/matrices
241
262
((V, A, V, A, s, V, A, V), (fV, fA, fV, fA, s, fV, fA, fV)) ) # one scalar, seven sparse vectors/matrices
263
+ # test broadcast entry point
242
264
@test broadcast (* , sparseargs... ) == sparse (broadcast (* , denseargs... ))
243
265
@test isa (@inferred (broadcast (* , sparseargs... )), SparseMatrixCSC{elT})
266
+ # test broadcast! entry point
267
+ fX = broadcast (* , sparseargs... ); X = sparse (fX)
268
+ @test broadcast! (* , X, sparseargs... ) == sparse (broadcast! (* , fX, denseargs... ))
269
+ @test isa (@inferred (broadcast! (* , X, sparseargs... )), SparseMatrixCSC{elT})
270
+ X = sparse (fX) # reset / warmup for @allocated test
271
+ @test_broken (@allocated broadcast! (* , X, sparseargs... )) == 0
272
+ # please see the note a few lines above re. this @test_broken
244
273
end
245
274
end
246
275
0 commit comments