Skip to content

setindex isn't compatible with ArrayInterfaceCore setindex #1039

@nhz2

Description

@nhz2
julia> using StaticArrays

julia> import ArrayInterfaceCore

julia> a = @SMatrix ones(2, 2);

julia> setindex(a,0.0,1,1)
ERROR: MethodError: setindex(::SMatrix{2, 2, Float64, 4}, ::Float64, ::Int64, ::Int64) is ambiguous. Candidates:
  setindex(a::StaticArray, x, inds...) in StaticArrays at /home/nathan/.julia/packages/StaticArrays/6D1fn/src/deque.jl:198
  setindex(x::AbstractMatrix, v, i::Int64, j::Int64) in ArrayInterfaceCore at /home/nathan/.julia/packages/ArrayInterfaceCore/wwYvJ/src/ArrayInterfaceCore.jl:129
Possible fix, define
  setindex(::StaticArray{S, T, 2} where {T, S<:Tuple}, ::Any, ::Int64, ::Int64)
Stacktrace:
 [1] top-level scope
   @ REPL[12]:1

Here are links to the code referenced in the error:

@propagate_inbounds setindex(a::StaticArray, x, inds...) = setindex(a, x, LinearIndices(a)[inds...])

https://github.com/JuliaArrays/ArrayInterface.jl/blob/b1ce7bb443eb82fc281be2989ee2fa5e364fe1d9/lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl#L129-L132

Would adding the following code solve the issue?

@propagate_inbounds setindex(a::StaticMatrix, x,  i::Int, j::Int) = setindex(a, x, LinearIndices(a)[i,j])

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