@@ -143,48 +143,45 @@ function make_carray_args(nt)
143143end
144144make_carray_args (:: Type{T} , nt) where {T} = make_carray_args (Vector{T}, nt)
145145function make_carray_args (A:: Type{<:AbstractArray} , nt)
146- data, idx = make_idx ([], nt, 0 )
146+ data, idx = build_data! ([], nt, 0 )
147147 return (A (data), Axis (idx))
148148end
149149
150150# Builds up data vector and returns appropriate AbstractAxis type for each input type
151- function make_idx (data, nt:: NamedTuple , last_val)
151+ function build_data! (data, nt:: NamedTuple , last_val)
152152 len = recursive_length (nt)
153- kvs = []
154153 lv = 0
155- for (k,v) in zip (keys (nt), values (nt))
156- (_,val) = make_idx (data, v, lv)
157- push! (kvs, k => val)
158- lv = val
154+ kvs = map (nt) do v
155+ lv = build_data! (data, v, lv)[2 ]
159156 end
160- return (data, ViewAxis (last_index (last_val) .+ (1 : len), (; kvs... ) ))
157+ return (data, ViewAxis (last_index (last_val) .+ (1 : len), kvs))
161158end
162- function make_idx (data, pair:: Pair , last_val)
163- data, ax = make_idx (data, pair. second, last_val)
159+ function build_data! (data, pair:: Pair , last_val)
160+ data, ax = build_data! (data, pair. second, last_val)
164161 return (data, ViewAxis (last_val: (last_val+ len- 1 ), Axis (pair. second)))
165162end
166- make_idx (data, x, last_val) = (
163+ build_data! (data, x, last_val) = (
167164 push! (data, x),
168165 ViewAxis (last_index (last_val) + 1 )
169166)
170- make_idx (data, x:: ComponentVector , last_val) = (
171- pushcat ! (data, x),
167+ build_data! (data, x:: ComponentVector , last_val) = (
168+ append ! (data, x),
172169 ViewAxis (
173170 last_index (last_val) .+ (1 : length (x)),
174171 getaxes (x)[1 ]
175172 )
176173)
177- function make_idx (data, x:: AbstractArray , last_val)
178- pushcat ! (data, x)
174+ function build_data! (data, x:: AbstractArray , last_val)
175+ append ! (data, x)
179176 out = last_index (last_val) .+ (1 : length (x))
180177 return (data, ViewAxis (out, ShapedAxis (size (x))))
181178end
182- function make_idx (data, x:: A , last_val) where {A<: AbstractArray{<:Union{NamedTuple, ComponentArray}} }
179+ function build_data! (data, x:: A , last_val) where {A<: AbstractArray{<:Union{NamedTuple, ComponentArray}} }
183180 len = recursive_length (x)
184181 if eltype (x) |> isconcretetype
185182 out = ()
186183 for elem in x
187- (_,out) = make_idx (data, elem, last_val)
184+ (_,out) = build_data! (data, elem, last_val)
188185 end
189186 return (
190187 data,
@@ -200,7 +197,7 @@ function make_idx(data, x::A, last_val) where {A<:AbstractArray{<:Union{NamedTup
200197 error (" Only homogeneous arrays of inner ComponentArrays are allowed." )
201198 end
202199end
203- function make_idx (data, x:: A , last_val) where {A<: AbstractArray{<:AbstractArray} }
200+ function build_data! (data, x:: A , last_val) where {A<: AbstractArray{<:AbstractArray} }
204201 error (" ComponentArrays cannot currently contain arrays of arrays as elements. This one contains: \n $x \n " )
205202end
206203
209206_maybe_add_field (x, pair) = haskey (x, pair. first) ? _update_field (x, pair) : _add_field (x, pair)
210207function _add_field (x, pair)
211208 data = copy (getdata (x))
212- new_data, new_ax = make_idx (data, pair. second, length (data))
209+ new_data, new_ax = build_data! (data, pair. second, length (data))
213210 new_ax = Axis (NamedTuple {tuple(pair.first)} (tuple (new_ax)))
214211 new_ax = merge (getaxes (x)[1 ], new_ax)
215212 return ComponentArray (new_data, new_ax)
@@ -220,8 +217,6 @@ function _update_field(x, pair)
220217 return x_copy
221218end
222219
223- pushcat! (a, b) = reduce ((x1,x2) -> push! (x1,x2), b; init= a)
224-
225220# Reshape ComponentArrays with ShapedAxis axes
226221maybe_reshape (data, :: NotShapedOrPartitionedAxis... ) = data
227222function maybe_reshape (data, axs:: AbstractAxis... )
0 commit comments