Skip to content

Commit

Permalink
use spdiagm instead
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Aug 20, 2017
1 parent bcbda77 commit 7a11787
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ Deprecated or removed

* `Base.SparseArrays.SpDiagIterator` has been removed ([#23261]).

* `diagm(A::SparseMatrixCSC)` has been deprecated in favor of
`spdiagm(sparsevec(A))` ([#23341]).

Command-line option changes
---------------------------

Expand Down
2 changes: 1 addition & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ export hex2num
# deprecations for filter[!] with 2-arg functions are in associative.jl

# PR 23341
@deprecate diagm(A::SparseMatrixCSC) diagm(sparsevec(A))
@deprecate diagm(A::SparseMatrixCSC) spdiagm(sparsevec(A))

# END 0.7 deprecations

Expand Down
27 changes: 0 additions & 27 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2004,30 +2004,3 @@ function fill!(A::Union{SparseVector, SparseMatrixCSC}, x)
end
return A
end

function diagm(v::SparseVector{Tv,Ti}) where {Tv,Ti}
n = length(v)
numnz = nnz(v)
colptr = Vector{Ti}(n+1)
rowval = Vector{Ti}(numnz)
nzval = Vector{Tv}(numnz)

copy!(rowval, 1, v.nzind, 1, numnz)
copy!(nzval, 1, v.nzval, 1, numnz)
colptr[1] = 1
ptr = 1
col = 1
while col <= n && ptr <= numnz
while rowval[ptr] > col
colptr[col+1] = colptr[col]
col += 1
end
colptr[col+1] = colptr[col] + 1
ptr += 1
col += 1
end
if col <= n
colptr[(col+1):(n+1)] = colptr[col]
end
return SparseMatrixCSC(n, n, colptr, rowval, nzval)
end

0 comments on commit 7a11787

Please sign in to comment.