Open charleskawczynski opened 3 months ago
From Base.Broadcast
:
# Performance optimization: broadcast!(identity, dest, A) is equivalent to copyto!(dest, A) if indices match
if bc.f === identity && bc.args isa Tuple{AbstractArray} # only a single input argument to broadcast!
A = bc.args[1]
if axes(dest) == axes(A)
return copyto!(dest, A)
end
end
We can easily specialize on
@. x = y
wheretypeof(x) == typeof(y)
to dispatch into thecopyto!(::Field, ::Field)
method, which is ~2x faster. There aren't many cases where we do this, butBase
andCUDA
do this-- it's still probably worth it.