JuliaArrays / FillArrays.jl

Julia package for lazily representing matrices filled with a single entry

Home Page:https://juliaarrays.github.io/FillArrays.jl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Collision of LazyArrays and FillArrays broadcasting

mcabbott opened this issue · comments

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

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.