FillArrays.jl icon indicating copy to clipboard operation
FillArrays.jl copied to clipboard

Collision of LazyArrays and FillArrays broadcasting

Open mcabbott opened this issue 4 years ago • 1 comments
trafficstars

This came up here: https://discourse.julialang.org/t/preventing-collect-on-broadcasting-expressions/57996

julia> using LazyArrays, FillArrays

julia> BroadcastArray(+, fill(1,2), 3)
2-element BroadcastVector{Int64, typeof(+), Tuple{Vector{Int64}, Int64}}:
 4
 4

julia> broadcast(+, Fill(1,2), 3)
2-element Fill{Int64, 1, Tuple{Base.OneTo{Int64}}} = 4

julia> BroadcastArray(+, Fill(1,2), 3)
ERROR: type Fill has no field f
Stacktrace:
 [1] getproperty(x::Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}, f::Symbol)
   @ Base ./Base.jl:33
 [2] call(#unused#::ArrayLayouts.FillLayout, a::Fill{Int64, 1, Tuple{Base.OneTo{Int64}}})
   @ LazyArrays ~/.julia/packages/LazyArrays/MAEFm/src/lazyapplying.jl:21
 [3] call(a::Fill{Int64, 1, Tuple{Base.OneTo{Int64}}})
   @ LazyArrays ~/.julia/packages/LazyArrays/MAEFm/src/lazyapplying.jl:22
 [4] BroadcastArray(A::Fill{Int64, 1, Tuple{Base.OneTo{Int64}}})
   @ LazyArrays ~/.julia/packages/LazyArrays/MAEFm/src/lazybroadcasting.jl:46
 [5] BroadcastArray(f::Function, A::Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}, As::Int64)
   @ LazyArrays ~/.julia/packages/LazyArrays/MAEFm/src/lazybroadcasting.jl:33
 [6] top-level scope
   @ REPL[66]:1

mcabbott avatar Mar 27 '21 23:03 mcabbott

This is really a problem in LazyArrays.jl: in

https://github.com/JuliaArrays/LazyArrays.jl/blob/30929f3d8b87ddf8582cfd69e2e67d77082e113a/src/lazybroadcasting.jl#L58

We call broadcasted but forget that it might return something other than a Broadcasted.

dlfivefifty avatar Mar 30 '21 01:03 dlfivefifty