diff --git a/NEWS.md b/NEWS.md index 1e3c1729e1659f..5a996e7e714527 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 --------------------------- diff --git a/base/deprecated.jl b/base/deprecated.jl index 5ec60233797083..0adc8eb68c8ff9 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -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 diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index 8bb0a975626b30..80225e4d328c8b 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -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