-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Support broadcast calls in @interface, for example, @interface SparseArrayInterface 2 .* a and @interface SparseArrayInterface b .= 2 .* a.
I believe those lower to Broadcast.materialize(Broadcast.broadcasted(*, 2, a)) and Broadcast.materialize!(b, Broadcast.broadcasted(*, 2, a)) respectively, so those would need @interface overloads.
Broadcast.materialize(bc::Broadcast.Broadcasted) is defined as Base.copy(instantiate(bc)), and the implementation of Base.copy(::Broadcast.Broadcasted) gets a bit tricky because of the logic around how to instantiate the output when it can't easily be inferred from the inputs (https://github.com/JuliaLang/julia/blob/v1.11.2/base/broadcast.jl#L888-L915). But maybe we can assume types are inferrable/concrete for the time being to simplify things, in which case it can just be something like:
Base.copy(bc::Broadcast.Broadcasted)
T = combine_eltypes(bc.f, bc.args)
dest = similar(bc, T)
copyto!(dest, bc)
return dest
endBroadcast.materialize!(dest, bc::Broadcast.Broadcasted) basically just ends up as Base.copyto!(dest, bc::Broadcast.Broadcasted).