Created
August 15, 2017 19:12
-
-
Save quinnj/fa95879c1ff047def57f9a10b26c4a8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Base.selectorbytes(A::Array{T, N}) -> Array{UInt8, N} | |
For an Array with `isbits` Union elements, return the "selector bytes" that indicate the | |
index of the type for each array element, i.e. the type of `A[1]` is | |
`Base.uniontypes(eltype(A))[Base.selectorbytes(A)[1] + 1]`. | |
**NOTE**: The actual array selector bytes are returned, meaning if individual elements | |
are modified, the original array will reflect those changes. Setting selector bytes to | |
invalid or out-of-bounds type indexes may corrupt the original array. | |
""" | |
function selectorbytes(a::Array{T, N}) where {T, N} | |
isbitsunion(T) || return UInt8[] | |
return unsafe_wrap(Array{UInt8, N}, convert(Ptr{UInt8}, pointer(a)) + length(a) * elsize(a), size(a)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment