@@ -89,8 +89,23 @@ size(a::Array{<:Any,N}) where {N} = (@_inline_meta; ntuple(M -> size(a, M), Val{
89
89
90
90
asize_from (a:: Array , n) = n > ndims (a) ? () : (arraysize (a,n), asize_from (a, n+ 1 )... )
91
91
92
+ function isbitsunion (U:: Union )
93
+ for u in Base. uniontypes (U)
94
+ isbits (u) || return false
95
+ end
96
+ return true
97
+ end
98
+ isbitsunion (T) = false
99
+ function bitsunionsize (U:: Union )
100
+ sz = 0
101
+ for u in Base. uniontypes (U)
102
+ sz = max (sz, sizeof (u))
103
+ end
104
+ return sz
105
+ end
106
+
92
107
length (a:: Array ) = arraylen (a)
93
- elsize (a:: Array{T} ) where {T} = isbits (T) ? sizeof (T) : sizeof (Ptr)
108
+ elsize (a:: Array{T} ) where {T} = isbits (T) ? sizeof (T) : ( isbitsunion (T) ? bitsunionsize (T) : sizeof (Ptr) )
94
109
sizeof (a:: Array ) = Core. sizeof (a)
95
110
96
111
function isassigned (a:: Array , i:: Int... )
@@ -100,6 +115,12 @@ function isassigned(a::Array, i::Int...)
100
115
ccall (:jl_array_isassigned , Cint, (Any, UInt), a, ii) == 1
101
116
end
102
117
118
+ # # Union isbits selector bytes
119
+ function selectorbytes (a:: Array{T, N} ) where {T, N}
120
+ isbitsunion (T) || return UInt8[]
121
+ return unsafe_wrap (Array{UInt8, N}, convert (Ptr{UInt8}, pointer (a)) + length (a) * elsize (T), size (a))
122
+ end
123
+
103
124
# # copy ##
104
125
105
126
function unsafe_copy! (dest:: Ptr{T} , src:: Ptr{T} , n) where T
0 commit comments