From 1ebc0cb951bdedbf1a077b9d4503e574c331b5e7 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 1 Sep 2025 15:38:41 -0400 Subject: [PATCH 1/2] Generic fallback for `fillstored!` (#1389) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/adjtrans.jl | 5 +++++ src/dense.jl | 2 ++ test/adjtrans.jl | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/adjtrans.jl b/src/adjtrans.jl index ee610be7..89ece72a 100644 --- a/src/adjtrans.jl +++ b/src/adjtrans.jl @@ -560,3 +560,8 @@ diagview(A::Adjoint, k::Integer = 0) = _vecadjoint(diagview(parent(A), -k)) # triu and tril triu!(A::AdjOrTransAbsMat, k::Integer = 0) = wrapperop(A)(tril!(parent(A), -k)) tril!(A::AdjOrTransAbsMat, k::Integer = 0) = wrapperop(A)(triu!(parent(A), -k)) + +function fillstored!(A::AdjOrTransAbsMat, v) + fillstored!(parent(A), wrapperop(A)(v)) + return A +end diff --git a/src/dense.jl b/src/dense.jl index 234b1022..9621e115 100644 --- a/src/dense.jl +++ b/src/dense.jl @@ -218,6 +218,8 @@ function fillband!(A::AbstractMatrix{T}, x, l, u) where T return A end +fillstored!(A::AbstractMatrix, v) = fill!(A, v) + diagind(m::Integer, n::Integer, k::Integer=0) = diagind(IndexLinear(), m, n, k) diagind(::IndexLinear, m::Integer, n::Integer, k::Integer=0) = 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)) diff --git a/test/adjtrans.jl b/test/adjtrans.jl index e5654004..371230b9 100644 --- a/test/adjtrans.jl +++ b/test/adjtrans.jl @@ -771,4 +771,15 @@ end end end +@testset "fillstored!" begin + A = rand(ComplexF64, 4, 4) + U = UpperTriangular(A) + @testset for (op, f) in ((Adjoint, adjoint), (Transpose, transpose)) + @test LinearAlgebra.fillstored!(op(A), 1) == op(fill(1, size(A))) + @test LinearAlgebra.fillstored!(op(A), 2im) == op(fill(f(2im), size(A))) + @test LinearAlgebra.fillstored!(op(U), 1) == op(triu(fill(1, size(U)))) + @test LinearAlgebra.fillstored!(op(U), 2im) == op(triu(fill(f(2im), size(U)))) + end +end + end # module TestAdjointTranspose From a2a49814d7fe033543e1453982a6441a00133bbf Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Sun, 12 Oct 2025 10:19:48 +0100 Subject: [PATCH 2/2] Overload array constructors for BunchKaufman (#1461) (#1466) --- src/bunchkaufman.jl | 6 ++++++ src/cholesky.jl | 4 ++-- test/bunchkaufman.jl | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/bunchkaufman.jl b/src/bunchkaufman.jl index a44f1a1c..07c3cdf4 100644 --- a/src/bunchkaufman.jl +++ b/src/bunchkaufman.jl @@ -215,6 +215,12 @@ BunchKaufman{T}(B::BunchKaufman) where {T} = BunchKaufman(convert(Matrix{T}, B.LD), B.ipiv, B.uplo, B.symmetric, B.rook, B.info) Factorization{T}(B::BunchKaufman) where {T} = BunchKaufman{T}(B) +AbstractMatrix(B::BunchKaufman) = B.uplo == 'U' ? B.P'B.U*B.D*B.U'B.P : B.P'B.L*B.D*B.L'B.P +AbstractArray(B::BunchKaufman) = AbstractMatrix(B) +Matrix(B::BunchKaufman) = convert(Array, AbstractArray(B)) +Array(B::BunchKaufman) = Matrix(B) + + size(B::BunchKaufman) = size(getfield(B, :LD)) size(B::BunchKaufman, d::Integer) = size(getfield(B, :LD), d) issymmetric(B::BunchKaufman) = B.symmetric diff --git a/src/cholesky.jl b/src/cholesky.jl index 2952503e..42550297 100644 --- a/src/cholesky.jl +++ b/src/cholesky.jl @@ -646,7 +646,7 @@ Factorization{T}(C::CholeskyPivoted) where {T} = CholeskyPivoted{T}(C) AbstractMatrix(C::Cholesky) = C.uplo == 'U' ? C.U'C.U : C.L*C.L' AbstractArray(C::Cholesky) = AbstractMatrix(C) -Matrix(C::Cholesky) = Array(AbstractArray(C)) +Matrix(C::Cholesky) = convert(Array, AbstractArray(C)) Array(C::Cholesky) = Matrix(C) function AbstractMatrix(F::CholeskyPivoted) @@ -655,7 +655,7 @@ function AbstractMatrix(F::CholeskyPivoted) U'U end AbstractArray(F::CholeskyPivoted) = AbstractMatrix(F) -Matrix(F::CholeskyPivoted) = Array(AbstractArray(F)) +Matrix(F::CholeskyPivoted) = convert(Array, AbstractArray(F)) Array(F::CholeskyPivoted) = Matrix(F) copy(C::Cholesky) = Cholesky(copy(C.factors), C.uplo, C.info) diff --git a/test/bunchkaufman.jl b/test/bunchkaufman.jl index cf4fa488..3e3e0d71 100644 --- a/test/bunchkaufman.jl +++ b/test/bunchkaufman.jl @@ -259,4 +259,13 @@ end @test B.U * B.D * B.U' ≈ S end +@testset "BunchKaufman array constructors #1461" begin + a = randn(5,5) + A = a'a + for ul in (:U, :L) + B = bunchkaufman(Symmetric(A, ul)) + @test A ≈ Array(B) ≈ Matrix(B) ≈ AbstractArray(B) ≈ AbstractMatrix(B) + end +end + end # module TestBunchKaufman