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

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

Closed
HTSykora opened this issue Sep 4, 2018 · 3 comments · Fixed by #29331
Labels
bug Indicates an unexpected problem or unintended behavior sparse Sparse arrays

Comments

@HTSykora
Copy link

HTSykora commented Sep 4, 2018

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)
@HTSykora
Copy link
Author

HTSykora commented Sep 4, 2018

On discourse Sukera pointed out, that the issue originates from the following lines:

setindex!(A::SparseMatrixCSC{Tv}, B::AbstractVecOrMat, I::Integer, J::Integer) where {Tv} = setindex!(A, convert(Tv, B), I, J)

@HTSykora HTSykora closed this as completed Sep 4, 2018
@fredrikekre fredrikekre reopened this Sep 4, 2018
@HTSykora
Copy link
Author

HTSykora commented Sep 4, 2018

Sorry, accidently closed it...

@Seelengrab
Copy link
Contributor

To mirror my thinking on discourse on here:

What I think is happening is an endless convert loop, as the B being put in is already a Tv, but is also an Array{Float64,1} and thus gets caught by the same setindex! again and again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior sparse Sparse arrays
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants