diff --git a/NEWS.md b/NEWS.md index cdf940755907f..a188d85bf7e7e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -367,6 +367,9 @@ Deprecated or removed Instead, reshape the array or add trailing indices so the dimensionality and number of indices match ([#14770], [#23628]). + * `fill!(A::Diagonal, x)` and `fill!(A::AbstractTriangular, x)` have been deprecated + in favor of `Base.LinAlg.fillslots!(A, x)` ([#24413]). + * Using Bool values directly as indices is now deprecated and will be an error in the future. Convert them to `Int` before indexing if you intend to access index `1` for `true` and `0` for `false`. diff --git a/base/deprecated.jl b/base/deprecated.jl index 9927285ba7d26..4d613246b7cf6 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1886,6 +1886,10 @@ end # After deprecation is removed, enable the @testset "indexing by Bool values" in test/arrayops.jl # Also un-comment the new definition in base/indices.jl +# deprecate odd fill! methods +@deprecate fill!(D::Diagonal, x) fillslots!(D, x) +@deprecate fill!(A::Base.LinAlg.AbstractTriangular, x) fillslots!(A, x) + function diagm(v::BitVector) depwarn(string("diagm(v::BitVector) is deprecated, use diagm(0 => v) or ", "BitMatrix(Diagonal(v)) instead"), :diagm) diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index 4a1f05ab222ef..68d1aa076ae09 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -607,10 +607,6 @@ function fillslots!(A::SpecialArrays, x) return A end -# for historical reasons: -fill!(a::AbstractTriangular, x) = fillslots!(a, x) -fill!(D::Diagonal, x) = fillslots!(D, x) - _small_enough(A::Bidiagonal) = size(A, 1) <= 1 _small_enough(A::Tridiagonal) = size(A, 1) <= 2 _small_enough(A::SymTridiagonal) = size(A, 1) <= 2 diff --git a/base/linalg/diagonal.jl b/base/linalg/diagonal.jl index 93533a4b02f64..1582371f17a91 100644 --- a/base/linalg/diagonal.jl +++ b/base/linalg/diagonal.jl @@ -61,6 +61,11 @@ convert(::Type{Array}, D::Diagonal) = convert(Matrix, D) similar(D::Diagonal, ::Type{T}) where {T} = Diagonal(similar(D.diag, T)) similar(D::Diagonal, ::Type{T}, dims::Union{Dims{1},Dims{2}}) where {T} = spzeros(T, dims...) +Base.zeros(D::Diagonal) = Diagonal(fill!(similar(D.diag), 0)) +Base.zeros(D::Diagonal, ::Type{T}) where {T} = Diagonal(fill!(similar(D, T), 0)) +Base.zeros(D::Diagonal, ::Type{T}, dims::Dims) where {T} = fill!(similar(D, T, dims), 0) +Base.zeros(D::Diagonal, ::Type{T}, dims::Integer...) where {T} = fill!(similar(D, T, dims), 0) + copy!(D1::Diagonal, D2::Diagonal) = (copy!(D1.diag, D2.diag); D1) size(D::Diagonal) = (length(D.diag),length(D.diag)) diff --git a/test/linalg/triangular.jl b/test/linalg/triangular.jl index 862fa75f184e3..7c1d7c547e528 100644 --- a/test/linalg/triangular.jl +++ b/test/linalg/triangular.jl @@ -34,9 +34,6 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa # full! @test full!(copy(A1)) == A1 - # fill! - @test full!(fill!(copy(A1), 1)) == t1(ones(size(A1)...)) - # similar @test isa(similar(A1), t1) @test eltype(similar(A1)) == elty1