Skip to content

Commit 2fb0e56

Browse files
GiggleLiuRogerluo
authored and
Rogerluo
committed
fix-diag to sparse conversion (#21)
* fix-diag to sparse conversion * fix * fix typo
1 parent ad75099 commit 2fb0e56

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/conversions.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ function SparseMatrixCSC(M::PermMatrix)
1919
SparseMatrixCSC(n, n, collect(1:n+1), order, M.vals[order])
2020
end
2121

22+
function SparseMatrixCSC(D::Diagonal{T}) where T
23+
m = length(D.diag)
24+
return SparseMatrixCSC(m, m, Vector(1:(m+1)), Vector(1:m), Vector{T}(D.diag))
25+
end
26+
2227
SparseMatrixCSC{Tv, Ti}(M::PermMatrix{Tv, Ti}) where {Tv, Ti} = SparseMatrixCSC(M)
2328
SparseMatrixCSC(coo::SparseMatrixCOO) = sparse(coo.is, coo.js, coo.vs, coo.m, coo.n)
2429

0 commit comments

Comments
 (0)