Skip to content

Sparse outer product fails for SparseVector with stored zero #42670

Closed
@Keno

Description

@Keno
julia> A = spzeros(Int, 4)
4-element SparseVector{Int64, Int64} with 0 stored entries

julia> A[2] = 1
1

julia> A[2] = 0
0

julia> A * sparsevec([0 0 1 1 0 0])'
ERROR: ArgumentError: Illegal buffers for SparseMatrixCSC construction 6 [1, 1, 1, 1, 1, 1, 1] [0, 139764218343329] [0, 139765420920097]
Stacktrace:
  [1] SparseMatrixCSC
    @ ~/julia/usr/share/julia/stdlib/v1.8/SparseArrays/src/sparsematrix.jl:29 [inlined]
  [2] SparseMatrixCSC(m::Int64, n::Int64, colptr::Vector{Int64}, rowval::Vector{Int64}, nzval::Vector{Int64})
    @ SparseArrays ~/julia/usr/share/julia/stdlib/v1.8/SparseArrays/src/sparsematrix.jl:44
  [3] _outer(trans::typeof(conj), x::SparseVector{Int64, Int64}, y::SparseVector{Int64, Int64})
    @ SparseArrays.HigherOrderFns ~/julia/usr/share/julia/stdlib/v1.8/SparseArrays/src/higherorderfns.jl:858
  [4] _outer
    @ ~/julia/usr/share/julia/stdlib/v1.8/SparseArrays/src/higherorderfns.jl:820 [inlined]
  [5] _copy
    @ ~/julia/usr/share/julia/stdlib/v1.8/SparseArrays/src/higherorderfns.jl:819 [inlined]
  [6] copy
    @ ~/julia/usr/share/julia/stdlib/v1.8/SparseArrays/src/higherorderfns.jl:1130 [inlined]
  [7] materialize
    @ ./broadcast.jl:860 [inlined]
  [8] broadcast(::typeof(*), ::SparseVector{Int64, Int64}, ::Adjoint{Int64, SparseVector{Int64, Int64}})
    @ Base.Broadcast ./broadcast.jl:798
  [9] *(u::SparseVector{Int64, Int64}, v::Adjoint{Int64, SparseVector{Int64, Int64}})
    @ LinearAlgebra ~/julia/usr/share/julia/stdlib/v1.8/LinearAlgebra/src/adjtrans.jl:300
 [10] top-level scope
    @ REPL[41]:1

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