From 665aeab129576b3d46cfaecf2ffaa7a8985f272a Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Mon, 30 Oct 2017 15:33:07 -0700 Subject: [PATCH] Deprecate fill!(A::[Diagonal|AbstractTriangular], x) = fillslots!(A, x) methods. --- NEWS.md | 3 +++ base/deprecated.jl | 4 ++++ base/linalg/bidiag.jl | 4 ---- base/linalg/diagonal.jl | 5 +++++ test/linalg/bidiag.jl | 14 +++++++++++--- test/linalg/triangular.jl | 3 --- 6 files changed, 23 insertions(+), 10 deletions(-) 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/bidiag.jl b/test/linalg/bidiag.jl index bfd745c286500..052642d314e5a 100644 --- a/test/linalg/bidiag.jl +++ b/test/linalg/bidiag.jl @@ -323,10 +323,10 @@ import Base.LinAlg: fillslots!, UnitLowerTriangular Bidiagonal(randn(3), randn(2), rand([:U,:L])), SymTridiagonal(randn(3), randn(2)), sparse(randn(3,4)), - Diagonal(randn(5)), + # Diagonal(randn(5)), # Diagonal fill! deprecated, see below sparse(rand(3)), - LowerTriangular(randn(3,3)), - UpperTriangular(randn(3,3)) + # LowerTriangular(randn(3,3)), # AbstractTriangular fill! deprecated, see below + # UpperTriangular(randn(3,3)) # AbstractTriangular fill! deprecated, see below ] for A in exotic_arrays fill!(A, 0) @@ -334,6 +334,14 @@ import Base.LinAlg: fillslots!, UnitLowerTriangular @test a == 0 end end + # Diagonal and AbstractTriangular fill! were defined as fillslots!, + # not matching the general behavior of fill!, and so have been deprecated. + # In a future dev cycle, these fill! methods should probably be reintroduced + # with behavior matching that of fill! for other structured matrix types. + # In the interm, equivalently test fillslots! below + @test iszero(fillslots!(Diagonal(fill(1, 3)), 0)) + @test iszero(fillslots!(LowerTriangular(fill(1, 3, 3)), 0)) + @test iszero(fillslots!(UpperTriangular(fill(1, 3, 3)), 0)) end let # fill!(small, x) val = randn() 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