Skip to content

Commit 63c347a

Browse files
Fix arrays of arrays. See #116
1 parent 8ae5933 commit 63c347a

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/axis.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
abstract type AbstractAxis{IdxMap} end
22

33
@inline indexmap(::AbstractAxis{IdxMap}) where IdxMap = IdxMap
4+
@inline indexmap(ax::AbstractUnitRange) = ax
45
@inline indexmap(::Type{<:AbstractAxis{IdxMap}}) where IdxMap = IdxMap
56

67

src/componentarray.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ function ComponentArray(data, ax::AbstractAxis...)
5454
part_axs = filter_by_type(PartitionedAxis, ax...)
5555
part_data = partition(data, size.(part_axs)...)
5656
axs = Axis.(ax)
57-
return LazyArray(ComponentArray(x, axs) for x in part_data)
57+
# return [ComponentArray(x, axs...) for x in part_data]
58+
return LazyArray(ComponentArray(x, axs...) for x in part_data)
5859
end
5960

6061
# Entry from NamedTuple, Dict, or kwargs
@@ -184,9 +185,10 @@ function make_idx(data, x::AbstractArray, last_val)
184185
out = last_index(last_val) .+ (1:length(x))
185186
return (data, ViewAxis(out, ShapedAxis(size(x))))
186187
end
187-
function make_idx(data, x::A, last_val) where {A<:AbstractArray{<:Union{NamedTuple, ComponentArray}}}
188+
function make_idx(data, x::A, last_val) where {A<:AbstractArray{<:Union{NamedTuple, AbstractArray}}}
188189
len = recursive_length(x)
189-
if eltype(x) |> isconcretetype
190+
elem_len = len ÷ length(x)
191+
if eltype(x) |> isconcretetype && all(elem -> recursive_length(elem) == elem_len, x)
190192
out = ()
191193
for elem in x
192194
_, out = make_idx(data, elem, last_val)
@@ -196,18 +198,18 @@ function make_idx(data, x::A, last_val) where {A<:AbstractArray{<:Union{NamedTup
196198
ViewAxis(
197199
last_index(last_val) .+ (1:len),
198200
PartitionedAxis(
199-
len ÷ length(x),
200-
indexmap(out)
201+
elem_len,
202+
indexmap(out),
201203
)
202204
)
203205
)
204206
else
205-
error("Only homogeneous arrays of inner ComponentArrays are allowed.")
207+
error("Only homogeneous arrays are allowed.")
206208
end
207209
end
208-
function make_idx(data, x::A, last_val) where {A<:AbstractArray{<:AbstractArray}}
209-
error("ComponentArrays cannot currently contain arrays of arrays as elements. This one contains: \n $x\n")
210-
end
210+
# function make_idx(data, x::A, last_val) where {A<:AbstractArray{<:AbstractArray}}
211+
# error("ComponentArrays cannot currently contain arrays of arrays as elements. This one contains: \n $x\n")
212+
# end
211213

212214

213215
#TODO: Make all internal function names start with underscores

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ end
123123
# Issue #116
124124
# Part 2: Arrays of arrays
125125
@test_throws Exception ComponentVector(a = [[3], [4, 5]], b = 1)
126+
127+
x = ComponentVector(a = [[3, 3], [4, 5]], b = 1)
128+
@test x.a[1] == [3, 3]
129+
@test x.b == 1
126130

127131
# empty components
128132
for T in [Int64, Int32, Float64, Float32, ComplexF64, ComplexF32]

0 commit comments

Comments
 (0)