Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tpapp opened this issue Jan 8, 2024 · 4 comments
Open

Comments

@tpapp
Copy link

tpapp commented Jan 8, 2024

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
Copy link

MaAl13 commented Apr 2, 2024

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

@tpapp
Copy link
Author

tpapp commented Apr 3, 2024

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

@MaAl13
Copy link

MaAl13 commented Apr 3, 2024

Thanks for your response. Which alternative did you use?

@jonniedie
Copy link
Owner

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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants