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

Error when using map on FieldVector of Vector #1276

Open
mattsignorelli opened this issue Sep 16, 2024 · 1 comment
Open

Error when using map on FieldVector of Vector #1276

mattsignorelli opened this issue Sep 16, 2024 · 1 comment

Comments

@mattsignorelli
Copy link

Consider the struct

struct Coords{T} <: FieldVector{3, T}
  x::Vector{T}
  y::Vector{T}
  z::Vector{T}
end

This is a "structure of arrays" layout of memory. For example we would store two coordinates (1,2,3) and (4,5,6) as

julia> c = Coords([1,4],[2,5],[3,6])
3-element Coords{Int64} with indices SOneTo(3):
 [1, 4]
 [2, 5]
 [3, 6]

Now say we'd like to get the first coordinate alone, as a vector/Svector. We would do:

julia> map(t->t[1], c)
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Vector{Int64}

Closest candidates are:
  convert(::Type{Array{T, N}}, ::SizedArray{S, T, N, N, Array{T, N}}) where {S, T, N}
   @ StaticArrays ~/.julia/packages/StaticArrays/MSJcA/src/SizedArray.jl:88
  convert(::Type{Array{T, N}}, ::SizedArray{S, T, N, M, TData} where {M, TData<:AbstractArray{T, M}}) where {T, S, N}
   @ StaticArrays ~/.julia/packages/StaticArrays/MSJcA/src/SizedArray.jl:82
  convert(::Type{T}, ::AbstractArray) where T<:Array
   @ Base array.jl:665
  ...

Throws an error. However, this works completely fine for regular vectors:

julia> map(t->t[1], [c...])
3-element Vector{Int64}:
 1
 2
 3
@martinholters
Copy link
Collaborator

Shouldn't the supertype be Fieldvector{3, Vector{T}}? Don't know whether that makes a difference.

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

2 participants