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

similar for FieldVector converting to MVector/SizedVector #1273

Open
mattsignorelli opened this issue Aug 21, 2024 · 0 comments
Open

similar for FieldVector converting to MVector/SizedVector #1273

mattsignorelli opened this issue Aug 21, 2024 · 0 comments

Comments

@mattsignorelli
Copy link

mattsignorelli commented Aug 21, 2024

similar when called with a FieldVector should output an array type equal to the input type (with possibly different eltype if specified). However the current behavior does not do this. For immutable eltypes, it converts to an MVector:

julia> using StaticArrays

julia> mutable struct Quaternion{T <: Number} <: FieldVector{4, T}
         q0::T
         q1::T
         q2::T
         q3::T
       end

julia> q = Quaternion(1,2,3,4)
4-element Quaternion{Int64} with indices SOneTo(4):
 1
 2
 3
 4

julia> similar(q)  # This should be a `Quaternion{Int64}`
4-element MVector{4, Int64} with indices SOneTo(4):
 4472459824
          1
     563205
          1

And for mutable eltypes, a SizedVector:

julia> mutable struct MyNum{T} <: Number
       num::T
       end

julia> q = Quaternion{MyNum{Int64}}(MyNum(1),MyNum(2),MyNum(3),MyNum(4))
4-element Quaternion{MyNum{Int64}} with indices SOneTo(4):
 MyNum{Int64}(1)
 MyNum{Int64}(2)
 MyNum{Int64}(3)
 MyNum{Int64}(4)

julia> similar(q)
4-element SizedVector{4, MyNum{Int64}, Vector{MyNum{Int64}}} with indices SOneTo(4):
 #undef
 #undef
 #undef
 #undef
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

1 participant