Skip to content

Commit

Permalink
provide enough space when sparse(Unit..Triangular(Sparse..)) (Julia…
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausC authored and Viral B. Shah committed Jan 4, 2020
1 parent 2c4db8f commit ccfc55f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions stdlib/SparseArrays/src/sparseconvert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ function _sparsem(A::AbstractTriangularSparse{Tv}) where Tv
Ti = eltype(rowval)
fnzrange = A isa Union{UpperTriangular,UnitUpperTriangular} ? nzrangeup : nzrangelo
unit = A isa Union{UnitUpperTriangular,UnitLowerTriangular}
nz = nnz(S) + n * unit
newcolptr = Vector{Ti}(undef, n+1)
newrowval = Vector{Ti}(undef, nnz(S))
newnzval = Vector{Tv}(undef, nnz(S))
newrowval = Vector{Ti}(undef, nz)
newnzval = Vector{Tv}(undef, nz)
newcolptr[1] = 1
uplo = fnzrange == nzrangeup
newk = 1
Expand Down Expand Up @@ -233,7 +234,7 @@ function _sparsem(taA::Union{Transpose{Tv,<:AbstractTriangularSparse},
uplo = A isa Union{UpperTriangular,UnitUpperTriangular}

newcolptr = Vector{Ti}(undef, n+1)
fill!(newcolptr, 1unit)
fill!(newcolptr, unit)
newcolptr[1] = 1
@inbounds for j = 1:n
for k = fnzrange(A, j)
Expand Down
3 changes: 3 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,9 @@ end
@test sparse([1,2,3,4,5]') == SparseMatrixCSC([1 2 3 4 5])
@test sparse(UpperTriangular(A')) == UpperTriangular(B')
@test sparse(Adjoint(UpperTriangular(A'))) == Adjoint(UpperTriangular(B'))
@test sparse(UnitUpperTriangular(spzeros(5,5))) == I
deepwrap(A) = (Adjoint(LowerTriangular(view(Symmetric(A), 5:7, 4:6))))
@test sparse(deepwrap(A)) == Matrix(deepwrap(B))
end

@testset "unary operations on matrices where length(nzval)>nnz" begin
Expand Down

0 comments on commit ccfc55f

Please sign in to comment.