Skip to content

SparseMatrixCSC does not support indexing by arrays of CartesianIndex #30981

@yurivish

Description

@yurivish

With Julia 1.1:

julia> using SparseArrays

julia> let r = [1, 2, 3]
           r[findall(r .> 2)]
       end
1-element Array{Int64,1}:
 3

julia> let r = sparse([1, 2, 3])
           r[findall(r .> 2)]
       end
1-element SparseVector{Int64,Int64} with 1 stored entry:
  [1]  =  3

julia> let r = [1 2; 3 4]
           r[findall(r .> 2)]
       end
2-element Array{Int64,1}:
 3
 4

julia> let r = sparse([1 2; 3 4])
           r[findall(r .> 2)]
       end
ERROR: MethodError: no method matching isless(::CartesianIndex{2}, ::Int64)
Closest candidates are:
  isless(::Missing, ::Any) at missing.jl:70
  isless(::AbstractFloat, ::Real) at operators.jl:150
  isless(::Real, ::Real) at operators.jl:338
  ...
Stacktrace:
 [1] <(::CartesianIndex{2}, ::Int64) at ./operators.jl:260
 [2] getindex(::SparseMatrixCSC{Int64,Int64}, ::Array{CartesianIndex{2},1}) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/SparseArrays/src/sparsevector.jl:669
 [3] top-level scope at REPL[52]:2

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestssparseSparse arrays

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions