Skip to content

Incorrect conversion from band matrix to sparse matrix #482

@andreasvarga

Description

@andreasvarga

The following illustrates the issue:

julia> sparse(BandedMatrix(1=>1:3))
4×4 SparseMatrixCSC{Int64, Int64} with 4 stored entries:
 0  1  ⋅  ⋅
 ⋅  ⋅  2  ⋅
 ⋅  ⋅  ⋅  3
 ⋅  ⋅  ⋅  ⋅

The expected result is

julia> sparse(Matrix(BandedMatrix(1=>1:3)))
4×4 SparseMatrixCSC{Int64, Int64} with 3 stored entries:
 ⋅  1  ⋅  ⋅
 ⋅  ⋅  2  ⋅
 ⋅  ⋅  ⋅  3
 ⋅  ⋅  ⋅  ⋅

Similarly:

julia> a = BandedMatrix(1=>1:3,-1=>3:5)
4×4 BandedMatrix{Int64} with bandwidths (1, 1):
 0  1  ⋅  ⋅
 3  0  2  ⋅
 ⋅  4  0  3
 ⋅  ⋅  5  0

julia> sparse(a)
4×4 SparseMatrixCSC{Int64, Int64} with 10 stored entries:
 0  1  ⋅  ⋅
 3  0  2  ⋅
 ⋅  4  0  3
 ⋅  ⋅  5  0

julia> sparse(Matrix(a))
4×4 SparseMatrixCSC{Int64, Int64} with 6 stored entries:
 ⋅  1  ⋅  ⋅
 3  ⋅  2  ⋅
 ⋅  4  ⋅  3
 ⋅  ⋅  5  ⋅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions