Skip to content

Commit 1f55352

Browse files
jishnubViralBShah
andauthored
Generic fallback for fillstored! (#1389)
Also, specialize for `Adjoint`/`Transpose` to dispatch to the methods for the parent. The following works after this: ```julia julia> U = Adjoint(UpperTriangular(zeros(2,2))) 2×2 adjoint(::UpperTriangular{Float64, Matrix{Float64}}) with eltype Float64: 0.0 ⋅ 0.0 0.0 julia> LinearAlgebra.fillstored!(U, 3) 2×2 adjoint(::UpperTriangular{Float64, Matrix{Float64}}) with eltype Float64: 3.0 ⋅ 3.0 3.0 ``` --------- Co-authored-by: Viral B. Shah <viral@juliacomputing.com>
1 parent ae12feb commit 1f55352

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/adjtrans.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,11 @@ diagview(A::Adjoint, k::Integer = 0) = _vecadjoint(diagview(parent(A), -k))
582582
triu!(A::AdjOrTransAbsMat, k::Integer = 0) = wrapperop(A)(tril!(parent(A), -k))
583583
tril!(A::AdjOrTransAbsMat, k::Integer = 0) = wrapperop(A)(triu!(parent(A), -k))
584584

585+
function fillstored!(A::AdjOrTransAbsMat, v)
586+
fillstored!(parent(A), wrapperop(A)(v))
587+
return A
588+
end
589+
585590
function fillband!(A::AdjOrTrans, v, k1, k2)
586591
fillband!(parent(A), wrapperop(A)(v), -k2, -k1)
587592
return A

src/dense.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ function fillband!(A::AbstractMatrix{T}, x, l, u) where T
235235
return A
236236
end
237237

238+
fillstored!(A::AbstractMatrix, v) = fill!(A, v)
239+
238240
diagind(m::Integer, n::Integer, k::Integer=0) = diagind(IndexLinear(), m, n, k)
239241
diagind(::IndexLinear, m::Integer, n::Integer, k::Integer=0) =
240242
k <= 0 ? range(1-k, step=m+1, length=min(m+k, n)) : range(k*m+1, step=m+1, length=min(m, n-k))

test/adjtrans.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,17 @@ end
810810
end
811811
end
812812

813+
@testset "fillstored!" begin
814+
A = rand(ComplexF64, 4, 4)
815+
U = UpperTriangular(A)
816+
@testset for (op, f) in ((Adjoint, adjoint), (Transpose, transpose))
817+
@test LinearAlgebra.fillstored!(op(A), 1) == op(fill(1, size(A)))
818+
@test LinearAlgebra.fillstored!(op(A), 2im) == op(fill(f(2im), size(A)))
819+
@test LinearAlgebra.fillstored!(op(U), 1) == op(triu(fill(1, size(U))))
820+
@test LinearAlgebra.fillstored!(op(U), 2im) == op(triu(fill(f(2im), size(U))))
821+
end
822+
end
823+
813824
@testset "lmul!/rmul! by numbers" begin
814825
@testset "$(eltype(A))" for A in (rand(4, 4), rand(ComplexF64,4,4),
815826
fill([1 2; 3 4], 4, 4),

0 commit comments

Comments
 (0)