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
118118_isfill (f:: Ref ) = true
119119_isfill (:: Any ) = false
120120
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} )
122133 if _iszeros (bc)
123134 return Zeros (typeof (_getindex_value (bc)), axes (bc))
124135 elseif _isones (bc)
125136 return Ones (typeof (_getindex_value (bc)), axes (bc))
126137 elseif _isfill (bc)
127138 return Fill (_getindex_value (bc), axes (bc))
128139 else
129- # fallback style
130- S = Broadcast. Broadcasted{Broadcast. DefaultArrayStyle{N}}
131- copy (convert (S, bc))
140+ _fallback_copy (bc)
132141 end
133142end
134143# make the zero-dimensional case consistent with Base
135144function Base. copy (bc:: Broadcast.Broadcasted{<:AbstractFillStyle{0}} )
136- S = Broadcast. Broadcasted{Broadcast. DefaultArrayStyle{0 }}
137- copy (convert (S, bc))
145+ _fallback_copy (bc)
138146end
139147
140148# some cases that preserve 0d
Original file line number Diff line number Diff line change @@ -1210,6 +1210,11 @@ end
12101210 F = Fill (1 , 2 )
12111211 @test g .(F, " a" ) === f .(F)
12121212 end
1213+
1214+ @testset " early binding" begin
1215+ A = ones (2 ) .+ (x -> rand ()). (Fill (2 ,2 ))
1216+ @test all (== (A[1 ]), A)
1217+ end
12131218end
12141219
12151220@testset " map" begin
You can’t perform that action at this time.
0 commit comments