Skip to content

Commit

Permalink
Merge pull request #21657 from iamnapo/napo/0I_zeroinsert
Browse files Browse the repository at this point in the history
Fixed zero insertion when concatenate sparse matrices with 0*I
  • Loading branch information
Sacha0 authored May 3, 2017
2 parents 70db8be + 45dc18d commit 0155f51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,9 @@ speye_scaled(diag, m::Integer, n::Integer) = speye_scaled(typeof(diag), diag, m,

function speye_scaled(T, diag, m::Integer, n::Integer)
((m < 0) || (n < 0)) && throw(ArgumentError("invalid array dimensions"))
if iszero(diag)
return SparseMatrixCSC(m, n, ones(Int, n+1), Vector{Int}(0), Vector{T}(0))
end
nnz = min(m,n)
colptr = Vector{Int}(1+n)
colptr[1:nnz+1] = 1:nnz+1
Expand Down
5 changes: 5 additions & 0 deletions test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ do33 = ones(3)
end

@testset "concatenation tests" begin
sp33 = speye(3, 3)

@testset "horizontal concatenation" begin
@test all([se33 se33] == sparse([1, 2, 3, 1, 2, 3], [1, 2, 3, 4, 5, 6], ones(6)))
@test length(([sp33 0I]).nzval) == 3
end

@testset "vertical concatenation" begin
@test all([se33; se33] == sparse([1, 4, 2, 5, 3, 6], [1, 1, 2, 2, 3, 3], ones(6)))
se33_32bit = convert(SparseMatrixCSC{Float32,Int32}, se33)
@test all([se33; se33_32bit] == sparse([1, 4, 2, 5, 3, 6], [1, 1, 2, 2, 3, 3], ones(6)))
@test length(([sp33; 0I]).nzval) == 3
end

se44 = speye(4)
Expand All @@ -62,6 +66,7 @@ end
se77 = speye(7)
@testset "h+v concatenation" begin
@test all([se44 sz42 sz41; sz34 se33] == se77)
@test length(([sp33 0I; 1I 0I]).nzval) == 6
end

@testset "blkdiag concatenation" begin
Expand Down

0 comments on commit 0155f51

Please sign in to comment.