SciML / ComponentArrays.jl

Arrays with arbitrarily nested named components.
MIT License
294 stars 35 forks source link

getting "Only homogeneous arrays are allowed" error for Vector{SVector} #239

Open tpapp opened 10 months ago

tpapp commented 10 months ago

I am new to this package and it may be possible that I am misusing it, but

using ComponentArrays, StaticArrays
a = [zeros(3) for _ in 1:5]
ComponentVector((; a))          # works fine
b = zeros(SVector{3}, 5)
ComponentArray((; b))           # errors

stacktrace:

ERROR: Only homogeneous arrays are allowed.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] make_idx(data::Vector{Float64}, x::Vector{SVector{3}}, last_val::Int64)
   @ ComponentArrays ~/.julia/packages/ComponentArrays/NoToB/src/componentarray.jl:207
 [3] make_idx(data::Vector{Float64}, nt::@NamedTuple{b::Vector{SVector{3}}}, last_val::Int64)
   @ ComponentArrays ~/.julia/packages/ComponentArrays/NoToB/src/componentarray.jl:161
 [4] make_carray_args(A::Type{Vector}, nt::@NamedTuple{b::Vector{SVector{3}}})
   @ ComponentArrays ~/.julia/packages/ComponentArrays/NoToB/src/componentarray.jl:151
 [5] make_carray_args(nt::@NamedTuple{b::Vector{SVector{3}}})
   @ ComponentArrays ~/.julia/packages/ComponentArrays/NoToB/src/componentarray.jl:144
 [6] ComponentArray(nt::@NamedTuple{b::Vector{SVector{3}}})
   @ ComponentArrays ~/.julia/packages/ComponentArrays/NoToB/src/componentarray.jl:64
 [7] top-level scope
   @ REPL[34]:1

versions:

julia> VERSION
v"1.10.0"

(jl_BH2t1B) pkg> st
Status `/tmp/jl_BH2t1B/Project.toml`
  [b0b7db55] ComponentArrays v0.15.7
  [90137ffa] StaticArrays v1.9.0
MaAl13 commented 7 months ago

Did you resolve it? I have the same problem with Sparse arrays

tpapp commented 7 months ago

No, unfortunately not. After not getting a reply here I decided not to use this package.

MaAl13 commented 7 months ago

Thanks for your response. Which alternative did you use?

jonniedie commented 7 months ago

Hey all. ComponentArrays re-form your data to a dense array under the hood so unfortunately inputting things like static arrays or sparse arrays wouldn't be very useful (although it would be useful to unpack to those types, which we don't currently do). So that's one issue here. The other is that arrays of arrays as components aren't well supported. This is mostly due to the fact that we wouldn't have any way of handling jagged arrays because the size needs to be encoded in the type domain at the outer level. I'm actually surprised that that first example works. Supporting arrays of same-sized static arrays would make sense, but they're currently unsupported. But I do agree that that error message isn't super helpful.

Right now as a workaround you could always just wrap the inner arrays in some sort of named tuple.

a = [(v=zeros(3),) for _ in 1:5]
ComponentVector((; a))