@@ -78,7 +78,7 @@ function checkzerobands(dest, f, A::AbstractMatrix)
78
78
l, u = bandwidths (A)
79
79
80
80
if (l,u) ≠ (d_l,d_u)
81
- for j = 1 : n
81
+ for j = rowsupport (A)
82
82
for k = max (1 ,j- u) : min (j- d_u- 1 ,m)
83
83
iszero (f (A[k,j])) || throw (BandError (dest,j- k))
84
84
end
@@ -93,21 +93,12 @@ function _banded_broadcast!(dest::AbstractMatrix, f, src::AbstractMatrix{T}, _1,
93
93
z = f (zero (T))
94
94
iszero (z) || checkbroadcastband (dest, size (src), bandwidths (broadcasted (f, src)))
95
95
m,n = size (dest)
96
+ m == n == 0 && return dest
96
97
97
98
d_l, d_u = bandwidths (dest)
98
99
s_l, s_u = bandwidths (src)
99
- if d_l < min (s_l,m- 1 )
100
- # check zeros
101
- for j = 1 : n, k = max (1 ,j+ d_l+ 1 ): min (j+ s_l,j+ d_l,m)
102
- iszero (f (inbands_getindex (src, k, j))) || throw (BandError (dest))
103
- end
104
- end
105
- if d_u < min (s_u,n- 1 )
106
- # check zeros
107
- for j = 1 : n, k = max (1 ,j- d_u,j- s_u): min (j- d_u- 1 ,m)
108
- iszero (f (inbands_getindex (src, k, j))) || throw (BandError (dest))
109
- end
110
- end
100
+
101
+ checkzerobands (dest, f, src)
111
102
112
103
_banded_broadcast_anylayout! (dest, src, f, z, (s_l, s_u), (d_l, d_u), m)
113
104
@@ -252,13 +243,15 @@ end
252
243
min_su_du = min (s_u, d_u)
253
244
min_sl_dl = min (s_l, d_l)
254
245
for j = rowsupport (dest)
255
- for k = max (1 ,j- d_u): min (j- s_u- 1 ,m)
246
+ # if s_u < d_u, set extra bands in dest above the diagonal to zero
247
+ for k = max (1 ,j- d_u): min (j+ min (d_l, - (s_u+ 1 )),m)
256
248
inbands_setindex! (dest, z, k, j)
257
249
end
258
250
259
251
_banded_broadcast_loop_overlap! (dest, src, f, (min_sl_dl, min_su_du), m, j)
260
252
261
- for k = max (1 ,j+ s_l+ 1 ): min (j+ d_l,m)
253
+ # if s_l < d_l, set extra bands in dest below the diagonal to zero
254
+ for k = max (1 ,j+ max (s_l+ 1 , - d_u)): min (j+ d_l,m)
262
255
inbands_setindex! (dest, z, k, j)
263
256
end
264
257
end
@@ -276,12 +269,17 @@ function _banded_broadcast!(dest::AbstractMatrix, f, (src,x)::Tuple{AbstractMatr
276
269
z = f (zero (T), x)
277
270
iszero (z) || checkbroadcastband (dest, size (src), bandwidths (broadcasted (f, src,x)))
278
271
m,n = size (dest)
272
+ m == n == 0 && return dest
273
+
274
+ f_x = Base. Fix2 (f, x)
275
+
276
+ # if dest has fewer bands (either above or below the diagonal) than dest,
277
+ # then f.(x, dest) must be zero in these bands
278
+ checkzerobands (dest, f_x, src)
279
279
280
280
d_l, d_u = bandwidths (dest)
281
281
s_l, s_u = bandwidths (src)
282
- (d_l ≥ min (s_l,m- 1 ) && d_u ≥ min (s_u,n- 1 )) || throw (BandError (dest))
283
282
284
- f_x = Base. Fix2 (f, x)
285
283
_banded_broadcast_anylayout! (dest, src, f_x, z, (s_l, s_u), (d_l, d_u), m)
286
284
287
285
dest
@@ -291,12 +289,19 @@ function _banded_broadcast!(dest::AbstractMatrix, f, (x,src)::Tuple{Number,Abstr
291
289
z = f (x, zero (T))
292
290
iszero (z) || checkbroadcastband (dest, size (src), bandwidths (broadcasted (f, x,src)))
293
291
m,n = size (dest)
292
+ m == n == 0 && return dest
293
+
294
+ f_x = Base. Fix1 (f, x)
295
+
296
+ # if dest has fewer bands (either above or below the diagonal) than dest,
297
+ # then f.(x, src) must be zero in these bands
298
+ checkzerobands (dest, f_x, src)
294
299
295
300
d_l, d_u = bandwidths (dest)
296
301
s_l, s_u = bandwidths (src)
297
- (d_l ≥ min (s_l,m- 1 ) && d_u ≥ min (s_u,n- 1 )) || throw (BandError (dest))
298
302
299
- f_x = Base. Fix1 (f, x)
303
+ checkzerobands (dest, f, src)
304
+
300
305
_banded_broadcast_anylayout! (dest, src, f_x, z, (s_l, s_u), (d_l, d_u), m)
301
306
302
307
dest
0 commit comments