Skip to content

Commit

Permalink
added fallback for constructor for arbitrary factorization inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianAment committed May 31, 2022
1 parent 0401d6b commit b236c25
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "UpdatableCholeskyFactorizations"
uuid = "1a1c1746-0e7b-45d0-811e-72e8bb59686c"
authors = ["Sebastian Ament <[email protected]>"]
version = "1.1.0"
version = "1.1.1"

[deps]
LazyInverses = "9f18896c-49a9-43cc-8eef-c455a8a119c6"
Expand Down
8 changes: 7 additions & 1 deletion src/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function LinearAlgebra.Cholesky(F::UpdatableCholesky)
end

# converting Cholesky factorization to UpdatableCholesky
function UpdatableCholeskyFactorizations.updatable_cholesky(C::Union{Cholesky, CholeskyPivoted}, m::Int = size(C, 1); check::Bool = true)
function updatable_cholesky(C::Union{Cholesky, CholeskyPivoted}, m::Int = size(C, 1); check::Bool = true)
U_full = zeros(eltype(C), m, m) # in principle, could do this in place
n = size(C, 1)
U = C.U
Expand All @@ -53,6 +53,12 @@ function UpdatableCholeskyFactorizations.updatable_cholesky(C::Union{Cholesky, C
UpdatableCholesky(U_full, n, C.info)
end

# fall-back for arbitrary factorization object
function updatable_cholesky(F::Factorization, m::Int = size(F, 1); check::Bool = true)
updatable_cholesky(Hermitian(Matrix(F)), m, check = check)
end


function Base.getproperty(F::UpdatableCholesky, s::Symbol)
if s == :U
U = @view F.U_full[1:F.n, 1:F.n]
Expand Down
4 changes: 4 additions & 0 deletions test/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ using Test
@test size(C2) == size(C)

# conversion from cholesky type
# TODO: test for CholeskyPivoted
UC2 = updatable_cholesky(C2)
@test UC2 isa UpdatableCholesky
@test UC2.U C2.U

# testing constructor with arbitrary factorization input
@test Matrix(updatable_cholesky(qr(A))) A

# adding rows and columns
for i in 1:n
ai = @view A_full[1:n+i, n+i]
Expand Down

0 comments on commit b236c25

Please sign in to comment.