Skip to content

Commit

Permalink
at-deprecate spones(A) fillstored!(copy(A), 1) [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Dec 15, 2017
1 parent bc2e1ab commit bb8f554
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 38 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ Deprecated or removed
have been deprecated in favor of `spdiagm(d => x)` and `spdiagm(d[1] => x[1], d[2] => x[2], ...)`
respectively. The new `spdiagm` implementation now always returns a square matrix ([#23757]).

* `spones(A::AbstractSparseArray)` has been deprecated in favor of
`LinAlg.fillstored!(copy(A), 1)` ([#25037]).

* Constructors for `LibGit2.UserPasswordCredentials` and `LibGit2.SSHCredentials` which take a
`prompt_if_incorrect` argument are deprecated. Instead, prompting behavior is controlled using
the `allow_prompt` keyword in the `LibGit2.CredentialPayload` constructor ([#23690]).
Expand Down
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,12 @@ end
# PR #25030
@eval LinAlg @deprecate fillslots! fillstored! false

# PR #TBD
@eval SparseArrays @deprecate spones(A::SparseMatrixCSC{T}) where {T} fillstored!(copy(A), one(T))
@eval SparseArrays @deprecate spones(A::SparseVector{T}) where {T} fillstored!(copy(A), one(T))
using .SparseArrays.spones
export spones

function diagm(v::BitVector)
depwarn(string("diagm(v::BitVector) is deprecated, use diagm(0 => v) or ",
"BitMatrix(Diagonal(v)) instead"), :diagm)
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,6 @@ export
sparse,
sparsevec,
spdiagm,
spones,
sprand,
sprandn,
spzeros,
Expand Down
4 changes: 2 additions & 2 deletions base/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module SparseArrays

using Base: ReshapedArray, promote_op, setindex_shape_check, to_shape, tail
using Base.Sort: Forward
using Base.LinAlg: AbstractTriangular, PosDefException
using Base.LinAlg: AbstractTriangular, PosDefException, fillstored!

import Base: +, -, *, \, /, &, |, xor, ==
import Base: A_mul_B!, Ac_mul_B, Ac_mul_B!, At_mul_B, At_mul_B!
Expand All @@ -31,7 +31,7 @@ import Base: @get!, acos, acosd, acot, acotd, acsch, asech, asin, asind, asinh,

export AbstractSparseArray, AbstractSparseMatrix, AbstractSparseVector,
SparseMatrixCSC, SparseVector, blkdiag, droptol!, dropzeros!, dropzeros,
issparse, nonzeros, nzrange, rowvals, sparse, sparsevec, spdiagm, spones,
issparse, nonzeros, nzrange, rowvals, sparse, sparsevec, spdiagm,
sprand, sprandn, spzeros, nnz, permute

include("abstractsparse.jl")
Expand Down
26 changes: 1 addition & 25 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1431,31 +1431,7 @@ julia> sprandn(rng, 2, 2, 0.75)
sprandn(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat) = sprand(r,m,n,density,randn,Float64)
sprandn(m::Integer, n::Integer, density::AbstractFloat) = sprandn(GLOBAL_RNG,m,n,density)

"""
spones(S)
Create a sparse array with the same structure as that of `S`, but with every nonzero
element having the value `1.0`.
# Examples
```jldoctest
julia> A = sparse([1,2,3,4],[2,4,3,1],[5.,4.,3.,2.])
4×4 SparseMatrixCSC{Float64,Int64} with 4 stored entries:
[4, 1] = 2.0
[1, 2] = 5.0
[3, 3] = 3.0
[2, 4] = 4.0
julia> spones(A)
4×4 SparseMatrixCSC{Float64,Int64} with 4 stored entries:
[4, 1] = 1.0
[1, 2] = 1.0
[3, 3] = 1.0
[2, 4] = 1.0
```
"""
spones(S::SparseMatrixCSC{T}) where {T} =
SparseMatrixCSC(S.m, S.n, copy(S.colptr), copy(S.rowval), ones(T, S.colptr[end]-1))
LinAlg.fillstored!(S::SparseMatrixCSC, x) = (fill!(view(S.nzval, 1:(S.colptr[S.n + 1] - 1)), x); S)

"""
spzeros([type,]m[,n])
Expand Down
3 changes: 1 addition & 2 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ spzeros(len::Integer) = spzeros(Float64, len)
spzeros(::Type{T}, len::Integer) where {T} = SparseVector(len, Int[], T[])
spzeros(::Type{Tv}, ::Type{Ti}, len::Integer) where {Tv,Ti<:Integer} = SparseVector(len, Ti[], Tv[])

# Construction of same structure, but with all ones
spones(x::SparseVector{T}) where {T} = SparseVector(x.n, copy(x.nzind), ones(T, length(x.nzval)))
LinAlg.fillstored!(x::SparseVector, y) = (fill!(x.nzval, y); x)

### Construction from lists of indices and values

Expand Down
1 change: 0 additions & 1 deletion doc/src/manual/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,6 @@ section of the standard library reference.
| Sparse | Dense | Description |
|:-------------------------- |:---------------------- |:--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`spzeros(m,n)`](@ref) | [`zeros(m,n)`](@ref) | Creates a *m*-by-*n* matrix of zeros. ([`spzeros(m,n)`](@ref) is empty.) |
| [`spones(S)`](@ref) | [`ones(m,n)`](@ref) | Creates a matrix filled with ones. Unlike the dense version, [`spones`](@ref) has the same sparsity pattern as *S*. |
| [`sparse(I, n, n)`](@ref) | [`Matrix(I,n,n)`](@ref)| Creates a *n*-by-*n* identity matrix. |
| [`Array(S)`](@ref) | [`sparse(A)`](@ref) | Interconverts between dense and sparse formats. |
| [`sprand(m,n,d)`](@ref) | [`rand(m,n)`](@ref) | Creates a *m*-by-*n* random matrix (of density *d*) with iid non-zero elements distributed uniformly on the half-open interval ``[0, 1)``. |
Expand Down
1 change: 0 additions & 1 deletion doc/src/stdlib/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ Base.SparseArrays.sparsevec
Base.SparseArrays.issparse
Base.SparseArrays.nnz
Base.SparseArrays.spzeros
Base.SparseArrays.spones
Base.SparseArrays.spdiagm
Base.SparseArrays.sprand
Base.SparseArrays.sprandn
Expand Down
6 changes: 3 additions & 3 deletions test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1739,8 +1739,8 @@ end
end
end

@testset "spones" begin
@test spones(sparse(2.0I, 5, 5)) == Matrix(I, 5, 5)
@testset "fillstored!" begin
@test LinAlg.fillstored!(sparse(2.0I, 5, 5), 1) == Matrix(I, 5, 5)
end

@testset "factorization" begin
Expand Down Expand Up @@ -2016,7 +2016,7 @@ end
sprand(5, 5, 1/5)
end
A = max.(A, A')
A = spones(A)
LinAlg.fillstored!(A, 1)
B = A[5:-1:1, 5:-1:1]
@test issymmetric(B)
end
Expand Down
5 changes: 2 additions & 3 deletions test/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@ end
@test exact_equal(sparsevec(d), SparseVector(3, [1, 2, 3], [0.0, 1.0, 2.0]))
end
end
@testset "spones" begin
# copies structure, but replaces nzvals with ones
@testset "fillstored!" begin
x = SparseVector(8, [2, 3, 6], [12.0, 18.0, 25.0])
y = spones(x)
y = LinAlg.fillstored!(copy(x), 1)
@test (x .!= 0) == (y .!= 0)
@test y == SparseVector(8, [2, 3, 6], [1.0, 1.0, 1.0])
end
Expand Down

0 comments on commit bb8f554

Please sign in to comment.