Skip to content

Commit 665aeab

Browse files
committed
Deprecate fill!(A::[Diagonal|AbstractTriangular], x) = fillslots!(A, x) methods.
1 parent 268f878 commit 665aeab

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ Deprecated or removed
367367
Instead, reshape the array or add trailing indices so the dimensionality and number of indices
368368
match ([#14770], [#23628]).
369369

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

base/deprecated.jl

+4
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,10 @@ end
18861886
# After deprecation is removed, enable the @testset "indexing by Bool values" in test/arrayops.jl
18871887
# Also un-comment the new definition in base/indices.jl
18881888

1889+
# deprecate odd fill! methods
1890+
@deprecate fill!(D::Diagonal, x) fillslots!(D, x)
1891+
@deprecate fill!(A::Base.LinAlg.AbstractTriangular, x) fillslots!(A, x)
1892+
18891893
function diagm(v::BitVector)
18901894
depwarn(string("diagm(v::BitVector) is deprecated, use diagm(0 => v) or ",
18911895
"BitMatrix(Diagonal(v)) instead"), :diagm)

base/linalg/bidiag.jl

-4
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

+5
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

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

test/linalg/triangular.jl

-3
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)