Skip to content

Commit e0b70ac

Browse files
author
Pietro Vertechi
authored
minor refactor and version bump (#198)
1 parent 0db2c4f commit e0b70ac

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StructArrays"
22
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
3-
version = "0.6.0"
3+
version = "0.6.1"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/structarray.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,24 @@ struct StructArray{T, N, C<:Tup, I} <: AbstractArray{T, N}
2525
end
2626
end
2727

28-
# common type used for indexing
28+
# compute optimal type to use for indexing as a function of component types
2929
index_type(::Type{NamedTuple{names, types}}) where {names, types} = index_type(types)
3030
index_type(::Type{Tuple{}}) = Int
3131
function index_type(::Type{T}) where {T<:Tuple}
3232
S, U = tuple_type_head(T), tuple_type_tail(T)
33-
IndexStyle(S) isa IndexCartesian ? CartesianIndex{ndims(S)} : index_type(U)
33+
return _index_type(S, U)
3434
end
3535
# Julia v1.7.0-beta3 doesn't seem to specialize `index_type` as defined above
3636
# for tuple types with "many" elements (three or four, depending on the concrete
3737
# types). However, we can help the compiler for homogeneous types by defining
3838
# the specialization below.
39-
function index_type(::Type{<:NTuple{N, S}}) where {N, S}
40-
if IndexStyle(S) isa IndexCartesian
41-
return CartesianIndex{ndims(S)}
42-
else
43-
return Int
44-
end
45-
end
46-
39+
index_type(::Type{NTuple{N, S}}) where {N, S} = _index_type(S)
4740
index_type(::Type{StructArray{T, N, C, I}}) where {T, N, C, I} = I
4841

42+
function _index_type(::Type{S}, ::Type{U}=Tuple{}) where {S, U}
43+
return IndexStyle(S) isa IndexCartesian ? CartesianIndex{ndims(S)} : index_type(U)
44+
end
45+
4946
array_types(::Type{StructArray{T, N, C, I}}) where {T, N, C, I} = array_types(C)
5047
array_types(::Type{NamedTuple{names, types}}) where {names, types} = types
5148
array_types(::Type{TT}) where {TT<:Tuple} = TT

0 commit comments

Comments
 (0)