If I define MyArray <: DenseArray <: AbstractArray
, are there important indexing methods and stuff that I should be defining to make this thing perform well? Suppose it's basically just wrapping a normal dense array.
Fundamentally, all one really needs to define is
1) size(::MyArray)
2) getindex(A, ::Vararg{Int})
3) setindex!(::MyArray, ::Any, ::Vararg{Int})
but are there cases where e.g. for broadcasting or something like that, that I'm leaving a lot of performance on the table if I don't do something special?
For instance, I noticed that UnsafeArrays.jl defines its own specialized methods for copyto!
: https://github.com/JuliaArrays/UnsafeArrays.jl/blob/main/src/unsafe_array.jl#L114-L146
It's not clear to me what the advantage of doing that was, e.g. I could imagine that maybe there's somethign about broadcast that would make it better to have you own copyto!
implementation, but I can also imagine that this code is just unnecessary dead weight
I found these to be necessary for performance when wrapping StrideArrays coming out of Bumper: https://github.com/ericphanson/AllocArrays.jl/blob/main/src/AllocArray.jl#L74-L98
Last updated: Nov 22 2024 at 04:41 UTC