You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
end
Broadcast.materialize!(dest, bc::Broadcast.Broadcasted) basically just ends up as Base.copyto!(dest, bc::Broadcast.Broadcasted).
The text was updated successfully, but these errors were encountered:
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))
andBroadcast.materialize!(b, Broadcast.broadcasted(*, 2, a))
respectively, so those would need@interface
overloads.Broadcast.materialize(bc::Broadcast.Broadcasted)
is defined asBase.copy(instantiate(bc))
, and the implementation ofBase.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:Broadcast.materialize!(dest, bc::Broadcast.Broadcasted)
basically just ends up asBase.copyto!(dest, bc::Broadcast.Broadcasted)
.The text was updated successfully, but these errors were encountered: