Extending broadcast to vector-like struct

All the broadcast! calls result in a copyto! call. It’s just that for Vector, because Julia knows the data is contiguous, a copyto!(dest, src) (or dest .= src) results in a call to memmove (which is a heavily optimized loop in libc), whereas for other AbstractArray type it falls back to a generic loop.

Of course, you can add a similar optimized copyto! method for your array. But it doesn’t matter for more general broadcast assignments, e.g. x .= x .+ 1 doesn’t use memmove even for Vector.

2 Likes