File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -118,23 +118,31 @@ _isfill(f::Number) = true
118
118
_isfill (f:: Ref ) = true
119
119
_isfill (:: Any ) = false
120
120
121
- function Base. copy (bc:: Broadcast.Broadcasted{<:AbstractFillStyle{N}} ) where {N}
121
+ _broadcast_maybecopy (bc:: Broadcast.Broadcasted{<:AbstractFillStyle} ) = copy (bc)
122
+ _broadcast_maybecopy (x) = x
123
+
124
+ function _fallback_copy (bc)
125
+ # treat the fill components
126
+ bc2 = Base. broadcasted (bc. f, map (_broadcast_maybecopy, bc. args)... )
127
+ # fallback style
128
+ S = Broadcast. Broadcasted{Broadcast. DefaultArrayStyle{ndims (bc)}}
129
+ copy (convert (S, bc2))
130
+ end
131
+
132
+ function Base. copy (bc:: Broadcast.Broadcasted{<:AbstractFillStyle} )
122
133
if _iszeros (bc)
123
134
return Zeros (typeof (_getindex_value (bc)), axes (bc))
124
135
elseif _isones (bc)
125
136
return Ones (typeof (_getindex_value (bc)), axes (bc))
126
137
elseif _isfill (bc)
127
138
return Fill (_getindex_value (bc), axes (bc))
128
139
else
129
- # fallback style
130
- S = Broadcast. Broadcasted{Broadcast. DefaultArrayStyle{N}}
131
- copy (convert (S, bc))
140
+ _fallback_copy (bc)
132
141
end
133
142
end
134
143
# make the zero-dimensional case consistent with Base
135
144
function Base. copy (bc:: Broadcast.Broadcasted{<:AbstractFillStyle{0}} )
136
- S = Broadcast. Broadcasted{Broadcast. DefaultArrayStyle{0 }}
137
- copy (convert (S, bc))
145
+ _fallback_copy (bc)
138
146
end
139
147
140
148
# some cases that preserve 0d
Original file line number Diff line number Diff line change @@ -1239,6 +1239,11 @@ end
1239
1239
F = Fill (1 , 2 )
1240
1240
@test g .(F, " a" ) === f .(F)
1241
1241
end
1242
+
1243
+ @testset " early binding" begin
1244
+ A = ones (2 ) .+ (x -> rand ()). (Fill (2 ,2 ))
1245
+ @test all (== (A[1 ]), A)
1246
+ end
1242
1247
end
1243
1248
1244
1249
@testset " map" begin
You can’t perform that action at this time.
0 commit comments