Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is Vector{Union{T, Missing}} double the size of Vector{T}?

Is it right or there is a problem with Base.summarysize or ?

julia> x = rand(Int8, 100);

julia> Base.summarysize(x)
140

julia> x = allowmissing(x);

julia> Base.summarysize(x)
240

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It adds one single byte per element in this case:

Julia can now also store "isbits Union" values inline in an Array, as opposed to requiring an indirection box. The optimization is accomplished by storing an extra "type tag array" of bytes, one byte per array element, alongside the bytes of the actual array data.
https://docs.julialang.org/en/v1/devdocs/isbitsunionarrays/

For example consider the case with an Int16:

julia> x = rand(Int16, 100);

julia> Base.summarysize(x)
240

julia> x = allowmissing(x);

julia> Base.summarysize(x)
340

where
340 = (2+1)*100 + 40

  • 2 bytes: the size of Int16
  • 1 byte: extra-byte (the type tag)
  • 40 bytes: meta-data (with the shape, offset…) independent of the array’s size

Note that using less than a byte for the type tag would result that the elements are no longer aligned at bytes boundaries.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading