Skip to content

Sparse matrix edge cases #9917

@karanveerm

Description

@karanveerm

Ref: #9750 (comment)
cc: @ViralBShah

There are a few edge cases where the behavior of sparse matrices is inconsistent with those of regular matrices:

julia> sparse([]) # works fine
0x1 sparse matrix with 0 Any entries:
julia> sparse([]') # should work fine, but doesn't
ERROR: MethodError: `zero` has no method matching zero(::Type{Any})
julia> full(sparse([]))
ERROR: MethodError: `zero` has no method matching zero(::Type{Any})

julia> bVec= []; bSparse = sparse(bVec);
julia> bVec[:1] # this error makes sense
ERROR: BoundsError: attempt to access 0-element Array{Any,1} at index [1]
 in getindex at ./array.jl:260
julia> bSparse[:1] # DivideError makes no sense- we aren't performing divison
ERROR: DivideError: integer division error
 in getindex at sparse/sparsematrix.jl:879

julia> bSparse[2:1] # this should really throw an error
0x1 sparse matrix with 0 Any entries:

julia> e=speye(100);
julia> e[-10:10] # should throw an error
21x1 sparse matrix with 1 Float64 entries:
    [12,  1]  =  1.0
julia> versioninfo()
Julia Version 0.4.0-dev+2892
Commit adc1c83 (2015-01-24 19:45 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i7-4650U CPU @ 1.70GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    sparseSparse arrays

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions