Skip to content

Conversation

@andreasnoack
Copy link
Member

@andreasnoack andreasnoack commented Jun 28, 2017

As part of adding tests, I've also cleaned up the signatures of bkfact similarly to the changes we have made for cholfact. That should actually go in a separate PR so I'll open that shortly.

I've also wrapped the LAPACK routine for extracting the factors when using rook pivoting but I realized that they were only added in LAPACK 3.7.0 so we'll have to wait until we bump OpenBLAS before we can enable that functionality. For now, the call to those routines are commented out and an error is thrown.

Fixes JuliaLang/LinearAlgebra.jl#441

Update: The printing looks like

julia> A = [1 2 3; 2 1 2; 3 2 1]
3×3 Array{Int64,2}:
 1  2  3
 2  1  2
 3  2  1

julia> F = bkfact(Symmetric(A, :L))
Base.LinAlg.BunchKaufman{Float64,Array{Float64,2}}
D factor:
3×3 Tridiagonal{Float64}:
 1.0  3.0    
 3.0  1.0   0.0
     0.0  -1.0
L factor:
3×3 Base.LinAlg.UnitLowerTriangular{Float64,Array{Float64,2}}:
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.5  0.5  1.0
permutation:
3-element Array{Int64,1}:
 1
 3
 2
successful: true


@testset "(Automatic) Bunch-Kaufman factor of indefinite matrix" begin
bc1 = factorize(asym)
# check thactor factorize gives a Bunch-Kaufman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check that ?

@kshyatt kshyatt added display and printing Aesthetics and correctness of printed representations of objects. linear algebra Linear algebra labels Jun 28, 2017
LUD, od = LAPACK.syconv!(B.uplo, copy(B.LD), B.ipiv)
end
if d == :D
D = diagm(diag(LUD))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth returning D as a SymTridiagonal to save space?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe a general Tridiagonal if there's no such thing as HermTridiagonal...

getindex(B::BunchKaufman, d::Symbol)
Extract the factors of the Bunch-Kaufman factorization `B`. The factorization can take the
two forms `L*D*L.'` or `U*D*U.'` where `L` is a `UnitLowerTriangular` matrix, `U` is a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also a hermitian version where it's L*D*L' right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and it is also tested. I'll add it to the docstring.

return eye(T, n)[:,invperm(B[:p])]
elseif d == :L || d == :U || d == :D
if B.rook
# syconvf_rook just added to LAPACK 3.7.0. Uncomment and remove error when we distribute LAPACK 3.7.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p = T[1:maxi;]
uploL = uplo == 'L'
i = uploL ? 1 : maxi
# if uplo == 'U' we construct the permution backwards
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permutation

- `:p`: permutation vector
- `:P`: permutation matrix
```jldoctest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Examples
```jldoctest

symmetric or Hermitian matrix with 1x1 or 2x2 blocks. The argument `d` can be
- `:D`: the block diagonal matrix
- `:L`: the lower triangular factor (if factorization is `L*D*L.'`)
- `:U`: the lower triangular factor (if factorization is `U*D*U.'`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes more sense to list ' form before .' form

function Base.show(io::IO, mime::MIME{Symbol("text/plain")}, B::BunchKaufman)
println(io, summary(B))
print(io, "successful: $(issuccess(B))")
println(io, "D factor:")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test the show method and/or fix the relevant doctest

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've adjusted the doctest

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's an existing one that was showing the raw fields of a BunchKaufman, came up in one of Kristoffer's recent pr's - this will make it fail in a different way

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I've fixed that one as well.

@andreasnoack andreasnoack force-pushed the anj/bkfact branch 2 times, most recently from b3228a9 to fe131e4 Compare July 2, 2017 01:13
2.0 -1.0 -3.0
-4.0 -3.0 5.0
julia> B = [1.5 2 -4; 2 -1 -3; -4 -3 5]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unintentionally duplicated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed

@andreasnoack andreasnoack merged commit 709d65e into master Jul 3, 2017
@andreasnoack andreasnoack deleted the anj/bkfact branch July 3, 2017 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

display and printing Aesthetics and correctness of printed representations of objects. linear algebra Linear algebra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Printing for BunchKaufman factorizations could be better

4 participants