Skip to content

SparseMatrixCSC as a general sparse container: Setindex!(…) not working for SparseMatrixCSC with vector elements (v0.7) #29034

Closed
@HTSykora

Description

@HTSykora

In my application I have a sparse matrix, but every element of this matrix is a discretised function. If I try to use SparseMatrixCSC{Array{Float64,1},Int64} as the container, setindex!(...) in 0.7 throws a stackoverflow:

julia> sa=sparse([1],[1],[Vector{Float64}(undef,3)],3,3)
3×3 SparseMatrixCSC{Array{Float64,1},Int64} with 1 stored entry:
  [1, 1]  =  [6.93279e-310, 6.93279e-310, 6.93279e-310]

julia> sa[1,1] = [1.0,2.0,3.0]
StackOverflowError:
Stacktrace:
 [1] setindex!(::SparseMatrixCSC{Array{Int64,1},Int64}, ::Array{Int64,1}, ::Int64, ::Int64) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/SparseArrays/src/sparsematrix.jl:2540 (repeats 80000 times)

This can be solved by using broadcasted setindex!(...), but it does not solve the problem adding new elements to the array:

julia> sa[1,1] .= [1.0,2.0,3.0]
3-element Array{Float64,1}:
 1.0
 2.0
 3.0

julia> sa[2,2] = [1.0,2.0,3.0]
StackOverflowError:
Stacktrace:
 [1] setindex!(::SparseMatrixCSC{Array{Float64,1},Int64}, ::Array{Float64,1}, ::Int64, ::Int64) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/SparseArrays/src/sparsematrix.jl:2540 (repeats 80000 times)

I can work around it using custom structures, but this has worked in 0.6.x.

The version producing the bug

julia> versioninfo()
Julia Version 0.7.0
Commit a4cb80f3ed (2018-08-08 06:46 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorsparseSparse arrays

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions