Skip to content

Commit b051d6d

Browse files
committed
Deprecate zeros(D::Diagonal[, opts...]) methods.
1 parent 06a6afb commit b051d6d

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ Deprecated or removed
401401
* `eye` has been deprecated in favor of `I` and `Matrix` constructors. Please see the
402402
deprecation warnings for replacement details ([#24438]).
403403

404+
* `zeros(D::Diagonal[, opts...])` has been deprecated ([#24654]).
405+
404406
* Using Bool values directly as indices is now deprecated and will be an error in the future. Convert
405407
them to `Int` before indexing if you intend to access index `1` for `true` and `0` for `false`.
406408

base/deprecated.jl

+6
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,12 @@ function spdiagm(x, d, m::Integer, n::Integer)
17831783
return sparse(I, J, V, m, n)
17841784
end
17851785

1786+
# deprecate zeros(D::Diagonal[, opts...])
1787+
@deprecate zeros(D::Diagonal) Diagonal(fill!(similar(D.diag), 0))
1788+
@deprecate zeros(D::Diagonal, ::Type{T}) where {T} Diagonal(fill!(similar(D.diag, T), 0))
1789+
@deprecate zeros(D::Diagonal, ::Type{T}, dims::Dims) where {T} fill!(similar(D, T, dims), 0)
1790+
@deprecate zeros(D::Diagonal, ::Type{T}, dims::Integer...) where {T} fill!(similar(D, T, dims), 0)
1791+
17861792
# PR #23690
17871793
# `SSHCredentials` and `UserPasswordCredentials` constructors using `prompt_if_incorrect`
17881794
# are deprecated in base/libgit2/types.jl.

base/linalg/diagonal.jl

-5
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ convert(::Type{Array}, D::Diagonal) = convert(Matrix, D)
6161
similar(D::Diagonal, ::Type{T}) where {T} = Diagonal(similar(D.diag, T))
6262
similar(D::Diagonal, ::Type{T}, dims::Union{Dims{1},Dims{2}}) where {T} = spzeros(T, dims...)
6363

64-
Base.zeros(D::Diagonal) = Diagonal(fill!(similar(D.diag), 0))
65-
Base.zeros(D::Diagonal, ::Type{T}) where {T} = Diagonal(fill!(similar(D, T), 0))
66-
Base.zeros(D::Diagonal, ::Type{T}, dims::Dims) where {T} = fill!(similar(D, T, dims), 0)
67-
Base.zeros(D::Diagonal, ::Type{T}, dims::Integer...) where {T} = fill!(similar(D, T, dims), 0)
68-
6964
copy!(D1::Diagonal, D2::Diagonal) = (copy!(D1.diag, D2.diag); D1)
7065

7166
size(D::Diagonal) = (length(D.diag),length(D.diag))

test/linalg/diagonal.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ srand(1)
107107
target = scale!(Uc, inv.(D.diag))
108108
@test A_rdiv_B!(Uc, D) target atol=atol_three
109109
@test_throws DimensionMismatch A_rdiv_B!(Matrix{elty}(I, n-1, n-1), D)
110-
@test_throws SingularException A_rdiv_B!(Uc, zeros(D))
110+
@test_throws SingularException A_rdiv_B!(Uc, Diagonal(fill!(similar(D.diag), 0)))
111111
@test A_rdiv_Bt!(Uc, D) target atol=atol_three
112112
@test A_rdiv_Bc!(Uc, conj(D)) target atol=atol_three
113113
@test A_ldiv_B!(D, Matrix{eltype(D)}(I, size(D))) D \ Matrix{eltype(D)}(I, size(D)) atol=atol_three
@@ -188,11 +188,11 @@ srand(1)
188188
@testset "triu/tril" begin
189189
@test istriu(D)
190190
@test istril(D)
191-
@test triu(D,1) == zeros(D)
191+
@test iszero(triu(D,1))
192192
@test triu(D,0) == D
193193
@test triu(D,-1) == D
194194
@test tril(D,1) == D
195-
@test tril(D,-1) == zeros(D)
195+
@test iszero(tril(D,-1))
196196
@test tril(D,0) == D
197197
@test_throws ArgumentError tril(D, -n - 2)
198198
@test_throws ArgumentError tril(D, n)

0 commit comments

Comments
 (0)