Skip to content

Commit

Permalink
Deprecate speye.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 committed Oct 27, 2017
1 parent de94506 commit 8274292
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 78 deletions.
7 changes: 7 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,13 @@ end
# deprecate bits to bitstring (#24263, #24281)
@deprecate bits bitstring

# deprecate speye
@deprecate speye(n::Integer) sparse(1.0I, n)
@deprecate speye(m::Integer, n::Integer) sparse(1.0I, m, n)
@deprecate speye(::Type{T}, n::Integer) where {T} sparse(UniformScaling(one(T)), n)
@deprecate speye(::Type{T}, m::Integer, n::Integer) where {T} sparse(UniformScaling(one(T)), m, n)
@deprecate speye(S::SparseMatrixCSC{T}) where {T} sparse(UniformScaling(one(T)), size(S)...)

# issue #24167
@deprecate EnvHash EnvDict

Expand Down
2 changes: 1 addition & 1 deletion base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ true
Similarly, if `T` is a composite type and `x` a related instance, the result of
`convert(T, x)` may alias part or all of `x`.
```jldoctest
julia> x = speye(5);
julia> x = sparse(1.0I, 5);
julia> typeof(x)
SparseMatrixCSC{Float64,Int64}
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ final residual vector `resid`.
# Examples
```jldoctest
julia> A = speye(4, 4); B = Diagonal(1:4);
julia> A = sparse(1.0I, 4); B = Diagonal(1:4);
julia> λ, ϕ = eigs(A, B, nev = 2);
Expand Down
2 changes: 1 addition & 1 deletion base/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export
Factor,
Sparse

import ..SparseArrays: AbstractSparseMatrix, SparseMatrixCSC, increment, indtype, sparse, speye,
import ..SparseArrays: AbstractSparseMatrix, SparseMatrixCSC, increment, indtype, sparse,
spzeros, nnz

#########
Expand Down
106 changes: 31 additions & 75 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ Returns the number of stored (filled) elements in a sparse array.
# Examples
```jldoctest
julia> A = speye(3)
3×3 SparseMatrixCSC{Float64,Int64} with 3 stored entries:
[1, 1] = 1.0
[2, 2] = 1.0
[3, 3] = 1.0
julia> A = sparse(I, 3)
3×3 SparseMatrixCSC{Int64,Int64} with 3 stored entries:
[1, 1] = 1
[2, 2] = 1
[3, 3] = 1
julia> nnz(A)
3
Expand All @@ -83,17 +83,17 @@ modifications to the returned vector will mutate `A` as well. See
# Examples
```jldoctest
julia> A = speye(3)
3×3 SparseMatrixCSC{Float64,Int64} with 3 stored entries:
[1, 1] = 1.0
[2, 2] = 1.0
[3, 3] = 1.0
julia> A = sparse(I, 3)
3×3 SparseMatrixCSC{Int64,Int64} with 3 stored entries:
[1, 1] = 1
[2, 2] = 1
[3, 3] = 1
julia> nonzeros(A)
3-element Array{Float64,1}:
1.0
1.0
1.0
3-element Array{Int64,1}:
1
1
1
```
"""
nonzeros(S::SparseMatrixCSC) = S.nzval
Expand All @@ -108,11 +108,11 @@ nonzero values. See also [`nonzeros`](@ref) and [`nzrange`](@ref).
# Examples
```jldoctest
julia> A = speye(3)
3×3 SparseMatrixCSC{Float64,Int64} with 3 stored entries:
[1, 1] = 1.0
[2, 2] = 1.0
[3, 3] = 1.0
julia> A = sparse(I, 3)
3×3 SparseMatrixCSC{Int64,Int64} with 3 stored entries:
[1, 1] = 1
[2, 2] = 1
[3, 3] = 1
julia> rowvals(A)
3-element Array{Int64,1}:
Expand Down Expand Up @@ -1453,8 +1453,6 @@ julia> spones(A)
[3, 3] = 1.0
[2, 4] = 1.0
```
Note the difference from [`speye`](@ref).
"""
spones(S::SparseMatrixCSC{T}) where {T} =
SparseMatrixCSC(S.m, S.n, copy(S.colptr), copy(S.rowval), ones(T, S.colptr[end]-1))
Expand Down Expand Up @@ -1487,54 +1485,12 @@ function spzeros(::Type{Tv}, ::Type{Ti}, sz::Tuple{Integer,Integer}) where {Tv,
spzeros(Tv, Ti, sz[1], sz[2])
end

speye(n::Integer) = speye(Float64, n)
speye(::Type{T}, n::Integer) where {T} = speye(T, n, n)
speye(m::Integer, n::Integer) = speye(Float64, m, n)

"""
speye(S)
Create a sparse identity matrix with the same size as `S`.
# 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> speye(A)
4×4 SparseMatrixCSC{Float64,Int64} with 4 stored entries:
[1, 1] = 1.0
[2, 2] = 1.0
[3, 3] = 1.0
[4, 4] = 1.0
```
Note the difference from [`spones`](@ref).
"""
speye(S::SparseMatrixCSC{T}) where {T} = speye(T, size(S, 1), size(S, 2))
eye(S::SparseMatrixCSC) = speye(S)

"""
speye([type,]m[,n])
Create a sparse identity matrix of size `m x m`. When `n` is supplied,
create a sparse identity matrix of size `m x n`. The type defaults to [`Float64`](@ref)
if not specified.
`sparse(I, m, n)` is equivalent to `speye(Int, m, n)`, and
`sparse(α*I, m, n)` can be used to efficiently create a sparse
multiple `α` of the identity matrix.
"""
speye(::Type{T}, m::Integer, n::Integer) where {T} = speye_scaled(T, oneunit(T), m, n)
eye(S::SparseMatrixCSC{T}) where {T} = sparse(UniformScaling{T}(one(T)), size(S)...)

function one(S::SparseMatrixCSC{T}) where T
m,n = size(S)
if m != n; throw(DimensionMismatch("multiplicative identity only defined for square matrices")); end
speye(T, m)
speye_scaled(one(T), m, m)
end

speye_scaled(diag, m::Integer, n::Integer) = speye_scaled(typeof(diag), diag, m, n)
Expand Down Expand Up @@ -3120,13 +3076,13 @@ Concatenate matrices block-diagonally. Currently only implemented for sparse mat
# Examples
```jldoctest
julia> blkdiag(speye(3), 2*speye(2))
5×5 SparseMatrixCSC{Float64,Int64} with 5 stored entries:
[1, 1] = 1.0
[2, 2] = 1.0
[3, 3] = 1.0
[4, 4] = 2.0
[5, 5] = 2.0
julia> blkdiag(sparse(I, 3), sparse(2I, 2))
5×5 SparseMatrixCSC{Int64,Int64} with 5 stored entries:
[1, 1] = 1
[2, 2] = 1
[3, 3] = 1
[4, 4] = 2
[5, 5] = 2
```
"""
function blkdiag(X::SparseMatrixCSC...)
Expand Down Expand Up @@ -3578,6 +3534,6 @@ end

## Uniform matrix arithmetic

(+)(A::SparseMatrixCSC, J::UniformScaling) = A + J.λ * speye(A)
(-)(A::SparseMatrixCSC, J::UniformScaling) = A - J.λ * speye(A)
(-)(J::UniformScaling, A::SparseMatrixCSC) = J.λ * speye(A) - A
(+)(A::SparseMatrixCSC, J::UniformScaling) = A + sparse(J, size(A)...)
(-)(A::SparseMatrixCSC, J::UniformScaling) = A - sparse(J, size(A)...)
(-)(J::UniformScaling, A::SparseMatrixCSC) = sparse(J, size(A)...) - A

0 comments on commit 8274292

Please sign in to comment.