Skip to content

Commit 28ee87e

Browse files
authored
Overload array constructors for BunchKaufman (#1461) (#1466)
1 parent 6f73f65 commit 28ee87e

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/bunchkaufman.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ BunchKaufman{T}(B::BunchKaufman) where {T} =
217217
BunchKaufman(convert(Matrix{T}, B.LD), B.ipiv, B.uplo, B.symmetric, B.rook, B.info)
218218
Factorization{T}(B::BunchKaufman) where {T} = BunchKaufman{T}(B)
219219

220+
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
221+
AbstractArray(B::BunchKaufman) = AbstractMatrix(B)
222+
Matrix(B::BunchKaufman) = convert(Array, AbstractArray(B))
223+
Array(B::BunchKaufman) = Matrix(B)
224+
225+
220226
size(B::BunchKaufman) = size(getfield(B, :LD))
221227
size(B::BunchKaufman, d::Integer) = size(getfield(B, :LD), d)
222228
issymmetric(B::BunchKaufman) = B.symmetric

src/cholesky.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ Factorization{T}(C::CholeskyPivoted) where {T} = CholeskyPivoted{T}(C)
646646

647647
AbstractMatrix(C::Cholesky) = C.uplo == 'U' ? C.U'C.U : C.L*C.L'
648648
AbstractArray(C::Cholesky) = AbstractMatrix(C)
649-
Matrix(C::Cholesky) = Array(AbstractArray(C))
649+
Matrix(C::Cholesky) = convert(Array, AbstractArray(C))
650650
Array(C::Cholesky) = Matrix(C)
651651

652652
function AbstractMatrix(F::CholeskyPivoted)
@@ -655,7 +655,7 @@ function AbstractMatrix(F::CholeskyPivoted)
655655
U'U
656656
end
657657
AbstractArray(F::CholeskyPivoted) = AbstractMatrix(F)
658-
Matrix(F::CholeskyPivoted) = Array(AbstractArray(F))
658+
Matrix(F::CholeskyPivoted) = convert(Array, AbstractArray(F))
659659
Array(F::CholeskyPivoted) = Matrix(F)
660660

661661
copy(C::Cholesky) = Cholesky(copy(C.factors), C.uplo, C.info)

test/bunchkaufman.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,13 @@ end
259259
@test B.U * B.D * B.U' S
260260
end
261261

262+
@testset "BunchKaufman array constructors #1461" begin
263+
a = randn(5,5)
264+
A = a'a
265+
for ul in (:U, :L)
266+
B = bunchkaufman(Symmetric(A, ul))
267+
@test A Array(B) Matrix(B) AbstractArray(B) AbstractMatrix(B)
268+
end
269+
end
270+
262271
end # module TestBunchKaufman

0 commit comments

Comments
 (0)