Skip to content

Commit b6a2394

Browse files
authored
Merge pull request #24413 from Sacha0/depoddfillbang
deprecate fill!(A::[Diagonal|AbstractTriangular], x) = fillslots!(A, x) methods
2 parents 4b06266 + 665aeab commit b6a2394

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ Deprecated or removed
370370
Instead, reshape the array or add trailing indices so the dimensionality and number of indices
371371
match ([#14770], [#23628]).
372372

373+
* `fill!(A::Diagonal, x)` and `fill!(A::AbstractTriangular, x)` have been deprecated
374+
in favor of `Base.LinAlg.fillslots!(A, x)` ([#24413]).
375+
373376
* Using Bool values directly as indices is now deprecated and will be an error in the future. Convert
374377
them to `Int` before indexing if you intend to access index `1` for `true` and `0` for `false`.
375378

base/deprecated.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,10 @@ end
18811881
# After deprecation is removed, enable the @testset "indexing by Bool values" in test/arrayops.jl
18821882
# Also un-comment the new definition in base/indices.jl
18831883

1884+
# deprecate odd fill! methods
1885+
@deprecate fill!(D::Diagonal, x) fillslots!(D, x)
1886+
@deprecate fill!(A::Base.LinAlg.AbstractTriangular, x) fillslots!(A, x)
1887+
18841888
function diagm(v::BitVector)
18851889
depwarn(string("diagm(v::BitVector) is deprecated, use diagm(0 => v) or ",
18861890
"BitMatrix(Diagonal(v)) instead"), :diagm)

base/linalg/bidiag.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,6 @@ function fillslots!(A::SpecialArrays, x)
607607
return A
608608
end
609609

610-
# for historical reasons:
611-
fill!(a::AbstractTriangular, x) = fillslots!(a, x)
612-
fill!(D::Diagonal, x) = fillslots!(D, x)
613-
614610
_small_enough(A::Bidiagonal) = size(A, 1) <= 1
615611
_small_enough(A::Tridiagonal) = size(A, 1) <= 2
616612
_small_enough(A::SymTridiagonal) = size(A, 1) <= 2

base/linalg/diagonal.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ 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+
6469
copy!(D1::Diagonal, D2::Diagonal) = (copy!(D1.diag, D2.diag); D1)
6570

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

test/linalg/bidiag.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,25 @@ import Base.LinAlg: fillslots!, UnitLowerTriangular
324324
Bidiagonal(randn(3), randn(2), rand([:U,:L])),
325325
SymTridiagonal(randn(3), randn(2)),
326326
sparse(randn(3,4)),
327-
Diagonal(randn(5)),
327+
# Diagonal(randn(5)), # Diagonal fill! deprecated, see below
328328
sparse(rand(3)),
329-
LowerTriangular(randn(3,3)),
330-
UpperTriangular(randn(3,3))
329+
# LowerTriangular(randn(3,3)), # AbstractTriangular fill! deprecated, see below
330+
# UpperTriangular(randn(3,3)) # AbstractTriangular fill! deprecated, see below
331331
]
332332
for A in exotic_arrays
333333
fill!(A, 0)
334334
for a in A
335335
@test a == 0
336336
end
337337
end
338+
# Diagonal and AbstractTriangular fill! were defined as fillslots!,
339+
# not matching the general behavior of fill!, and so have been deprecated.
340+
# In a future dev cycle, these fill! methods should probably be reintroduced
341+
# with behavior matching that of fill! for other structured matrix types.
342+
# In the interm, equivalently test fillslots! below
343+
@test iszero(fillslots!(Diagonal(fill(1, 3)), 0))
344+
@test iszero(fillslots!(LowerTriangular(fill(1, 3, 3)), 0))
345+
@test iszero(fillslots!(UpperTriangular(fill(1, 3, 3)), 0))
338346
end
339347
let # fill!(small, x)
340348
val = randn()

test/linalg/triangular.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
3434
# full!
3535
@test full!(copy(A1)) == A1
3636

37-
# fill!
38-
@test full!(fill!(copy(A1), 1)) == t1(ones(size(A1)...))
39-
4037
# similar
4138
@test isa(similar(A1), t1)
4239
@test eltype(similar(A1)) == elty1

0 commit comments

Comments
 (0)