Skip to content

Commit b7e4811

Browse files
authored
Inline get_ith (#177)
We add `@inline` to the `get_ith` function. This avoids dynamic function calls when accessing elements of a `StructArray`. This allows accessing elements of `StructArray`s in GPU kernels.
1 parent c9b7622 commit b7e4811

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/structarray.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,12 @@ to
325325
map(c -> c[I...], Tuple(cols))
326326
```
327327
"""
328-
get_ith(cols::NamedTuple, I...) = get_ith(Tuple(cols), I...)
329-
function get_ith(cols::Tuple, I...)
328+
@inline get_ith(cols::NamedTuple, I...) = get_ith(Tuple(cols), I...)
329+
@inline function get_ith(cols::Tuple, I...)
330330
@inbounds r = first(cols)[I...]
331331
return (r, get_ith(Base.tail(cols), I...)...)
332332
end
333-
get_ith(::Tuple{}, I...) = ()
333+
@inline get_ith(::Tuple{}, I...) = ()
334334

335335
Base.@propagate_inbounds function Base.getindex(x::StructArray{T, <:Any, <:Any, CartesianIndex{N}}, I::Vararg{Int, N}) where {T, N}
336336
cols = components(x)

0 commit comments

Comments
 (0)