Skip to content

similar clashes with StaticArrays #279

Closed
@jishnub

Description

@jishnub
julia> v = StructArray{Complex{Int}}((SA[1,2], SA[1,2]))
2-element StructArray(::SVector{2, Int64}, ::SVector{2, Int64}) with eltype Complex{Int64} with indices SOneTo(2):
 1 + 1im
 2 + 2im

julia> similar(v)
ERROR: MethodError: similar(::StructVector{Complex{Int64}, @NamedTuple{re::SVector{2, Int64}, im::SVector{2, Int64}}, Int64}, ::Type{Complex{Int64}}, ::Tuple{SOneTo{2}}) is ambiguous.

Candidates:
  similar(s::StructArray, S::Type, sz::Tuple{Union{Integer, AbstractUnitRange}, Vararg{Union{Integer, AbstractUnitRange}}})
    @ StructArrays ~/.julia/packages/StructArrays/dNQpc/src/structarray.jl:297
  similar(A::AbstractArray, ::Type{T}, shape::Union{Tuple{SOneTo, Vararg{Union{Integer, Base.OneTo, SOneTo}}}, Tuple{Union{Integer, Base.OneTo}, SOneTo, Vararg{Union{Integer, Base.OneTo, SOneTo}}}, Tuple{Union{Integer, Base.OneTo}, Union{Integer, Base.OneTo}, SOneTo, Vararg{Union{Integer, Base.OneTo, SOneTo}}}}) where T
    @ StaticArrays ~/.julia/packages/StaticArrays/80e5O/src/abstractarray.jl:149

Possible fix, define
  similar(::StructArray, ::Type{T}, ::Union{Tuple{SOneTo, Vararg{Union{Integer, Base.OneTo, SOneTo}}}, Tuple{Union{Integer, Base.OneTo}, SOneTo, Vararg{Union{Integer, Base.OneTo, SOneTo}}}, Tuple{Union{Integer, Base.OneTo}, Union{Integer, Base.OneTo}, SOneTo, Vararg{Union{Integer, Base.OneTo, SOneTo}}}}) where T

Stacktrace:
 [1] similar(a::StructVector{Complex{Int64}, @NamedTuple{re::SVector{2, Int64}, im::SVector{2, Int64}}, Int64}, ::Type{Complex{Int64}})
   @ Base ~/julia/base/abstractarray.jl:827
 [2] similar(a::StructVector{Complex{Int64}, @NamedTuple{re::SVector{2, Int64}, im::SVector{2, Int64}}, Int64})
   @ Base ~/julia/base/abstractarray.jl:826
 [3] top-level scope
   @ REPL[6]:1

Perhaps an extension may help here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions