Skip to content

Commit a8ae9da

Browse files
Merge pull request #307 from SciML/ap/upstream_patch
fix: component array of empty namedtuple
2 parents 72b5049 + 8f8d465 commit a8ae9da

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ComponentArrays"
22
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
33
authors = ["Jonnie Diegelman <[email protected]>"]
4-
version = "0.15.27"
4+
version = "0.15.28"
55

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

src/componentarray.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ function ComponentArray(data, ax::AbstractAxis...)
5959
return LazyArray(ComponentArray(x, axs...) for x in part_data)
6060
end
6161

62+
# This code-path is hit for empty NamedTuples. We force a Float32 eltype here if
63+
# length(data) == 0
64+
function ComponentArray(data::Vector{Any}, axes::Tuple{FlatAxis})
65+
length(data) == 0 && return ComponentArray(Float32[], axes)
66+
return ComponentArray{Any,1,typeof(data),typeof(axes)}(data, axes)
67+
end
68+
6269
function Adapt.adapt_structure(to, x::ComponentArray)
6370
data = Adapt.adapt(to, getdata(x))
6471
return ComponentArray(data, getaxes(x))

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,10 @@ end
936936
@test_throws ArgumentError axpby!(2, x, 3, y)
937937
end
938938

939+
@testset "Empty NamedTuple" begin
940+
@test ComponentArray(NamedTuple()) isa ComponentVector{Float32}
941+
end
942+
939943
@testset "Functors" begin
940944
for carray in (ca, ca_Float32, ca_MVector, ca_SVector, ca_composed, ca2, caa)
941945
θ, re = Functors.functor(carray)

0 commit comments

Comments
 (0)