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 clashes with StaticArrays #279

Closed
jishnub opened this issue Jul 11, 2023 · 1 comment · Fixed by #304
Closed

similar clashes with StaticArrays #279

jishnub opened this issue Jul 11, 2023 · 1 comment · Fixed by #304

Comments

@jishnub
Copy link
Member

jishnub commented Jul 11, 2023

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

@aplavin
Copy link
Member

aplavin commented Mar 1, 2024

I also encountered this recently! What do you think is the best approach here?

  • Add extension here to explicitly define the required methods,
  • Add extension to StaticArrays to do the same,
  • Modify StructArrays or StaticArrays similar signature,
  • Add something to already existing disambiguations (if possible)
    # mimic OffsetArrays signature
    :(Tuple{Union{Integer, AbstractUnitRange}, Vararg{Union{Integer, AbstractUnitRange}}}),
    # disambiguation with Base
    :(Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}),
    , without any extensions?

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

Successfully merging a pull request may close this issue.

2 participants