Skip to content

scale!!(::SparseVector, ::SparseVector, x) results in StackOverflowError #19

Description

@abraemer

By chance I found that trying to use KrylovKit.exponentiate where the vector is a SparseArrays.SparseVector results in a StackOverflowError due to an endless recursive call. I tracked the error to a call of scale!!(v1, v2, x) where both v1 and v2 are SparseArrays.SparseVectors. It appears to be some unfortunate combination of VectorInterface.jl and broadcasting rules in SparseArrays.jl that leads to the infinite recursion. I am totally unfamiliar with VectorInterface.jl so I didn't attempt to search for a fix so far.

MWE:

using VectorInterface, SparseArrays
scale!!(spzeros(5), spzeros(5), 1) # StackOverflowError

Stacktrace:

      [1] broadcast!
        @ ./broadcast.jl:844 [inlined]
      [2] copyto!
        @ ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/SparseArrays/src/higherorderfns.jl:1175 [inlined]
      [3] materialize!
        @ ./broadcast.jl:878 [inlined]
      [4] materialize!(dest::SparseVector{…}, bc::Base.Broadcast.Broadcasted{…})
        @ Base.Broadcast ./broadcast.jl:875
--- the above 4 lines are repeated 43644 more times ---
 [174581] broadcast!
        @ ./broadcast.jl:844 [inlined]
 [174582] copyto!
        @ ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/SparseArrays/src/higherorderfns.jl:1175 [inlined]
 [174583] materialize!
        @ ./broadcast.jl:878 [inlined]
 [174584] materialize!
        @ ./broadcast.jl:875 [inlined]
 [174585] scale!
        @ ~/.julia/packages/VectorInterface/1L754/src/abstractarray.jl:46 [inlined]
 [174586] scale!!(y::SparseVector{Float64, Int64}, x::SparseVector{Float64, Int64}, α::Int64)
        @ VectorInterface ~/.julia/packages/VectorInterface/1L754/src/abstractarray.jl:60
versioninfo

Julia Version 1.11.1
Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 4800H with Radeon Graphics
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver2)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)

Pkg.status()

(jl_MdwVUn) pkg> st
Status `/tmp/jl_MdwVUn/Project.toml`
  [409d34a3] VectorInterface v0.4.6
  [2f01184e] SparseArrays v1.11.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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