JuliaArrays / JuliaArrays/StaticArrays.jl
`similar` for `FieldVector` converting to `MVector`/`SizedVector`
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the similar methods for FieldVector and compare their handling of immutable and mutable element types with MVector and SizedVector. Reproduce both examples in Julia, then add coverage showing that similar(q) retains the concrete Quaternion type, including the MyNum case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100