diff --git a/Project.toml b/Project.toml index 61770c5..1036eae 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ComponentArrays" uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66" authors = ["Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com>"] -version = "0.15.27" +version = "0.15.28" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/componentarray.jl b/src/componentarray.jl index c76be2a..4236570 100644 --- a/src/componentarray.jl +++ b/src/componentarray.jl @@ -59,6 +59,13 @@ function ComponentArray(data, ax::AbstractAxis...) return LazyArray(ComponentArray(x, axs...) for x in part_data) end +# This code-path is hit for empty NamedTuples. We force a Float32 eltype here if +# length(data) == 0 +function ComponentArray(data::Vector{Any}, axes::Tuple{FlatAxis}) + length(data) == 0 && return ComponentArray(Float32[], axes) + return ComponentArray{Any,1,typeof(data),typeof(axes)}(data, axes) +end + function Adapt.adapt_structure(to, x::ComponentArray) data = Adapt.adapt(to, getdata(x)) return ComponentArray(data, getaxes(x)) diff --git a/test/runtests.jl b/test/runtests.jl index e697d1a..9bfc177 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -936,6 +936,10 @@ end @test_throws ArgumentError axpby!(2, x, 3, y) end +@testset "Empty NamedTuple" begin + @test ComponentArray(NamedTuple()) isa ComponentVector{Float32} +end + @testset "Functors" begin for carray in (ca, ca_Float32, ca_MVector, ca_SVector, ca_composed, ca2, caa) θ, re = Functors.functor(carray)