-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
By default, new AbstractArray subtypes fall back to the fully generic sizeof(::Any) implementation that simply gives the size of their fields. Given that we know more about what an AbstractArray is — and given that we have a default write implementation, it seems like we should be able to do a better job of getting closer to the docstring of sizeof:
Size, in bytes, of the canonical binary representation of the given
DataTypeT, if any. Size, in bytes, of objectobjif it is notDataType.
For example:
julia> write(IOBuffer(), rand(5,5))
200
julia> sizeof(rand(5,5))
200
julia> write(IOBuffer(), rand(5,5)')
200
julia> sizeof(rand(5,5)')
8Even the "compressed" representations by default write their whole contents:
julia> using LinearAlgebra
julia> write(IOBuffer(), Diagonal(rand(5)))
200
julia> sizeof(Diagonal(rand(5)))
8So it'd seem like a sizeof(A::AbstractArray) = length(A) * sizeof(eltype(A)) definition would be better all around. If your array has a specialized canonical representation, then you define sizeof to match when you implement write.