Skip to content

Commit 5857c95

Browse files
TSGutdlfivefifty
andauthored
Fix cholesky.L and bugs related to copy (#174)
* fix cholesky.L * up version * Update src/infcholesky.jl Co-authored-by: Sheehan Olver <[email protected]> * use AdjorTrans instead * consistency update --------- Co-authored-by: Sheehan Olver <[email protected]>
1 parent 49e5d4d commit 5857c95

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InfiniteLinearAlgebra"
22
uuid = "cde9dba0-b1de-11e9-2c62-0bab9446c55c"
3-
version = "0.7.5"
3+
version = "0.7.6"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/infcholesky.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ end
1818
AdaptiveCholeskyFactors(A::AbstractMatrix{T}) where T = AdaptiveCholeskyFactors(MemoryLayout(A), A)
1919
MemoryLayout(::Type{AdaptiveCholeskyFactors{T,DM,M}}) where {T,DM,M} = AdaptiveLayout{typeof(MemoryLayout(DM))}()
2020

21+
copy(A::AdaptiveCholeskyFactors) = AdaptiveCholeskyFactors(copy(A.data), copy(A.ncols))
22+
copy(A::Adjoint{T,<:AdaptiveCholeskyFactors}) where T = copy(parent(A))'
23+
copy(A::Transpose{T,<:AdaptiveCholeskyFactors}) where T = transpose(copy(parent(A)))
2124

2225
function partialcholesky!(F::AdaptiveCholeskyFactors{T,<:BandedMatrix}, n::Int) where T
2326
if n > F.ncols

test/test_infcholesky.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using InfiniteLinearAlgebra, LinearAlgebra, BandedMatrices, ArrayLayouts, LazyBandedMatrices, Test
2-
import InfiniteLinearAlgebra: SymmetricBandedLayouts
2+
import InfiniteLinearAlgebra: SymmetricBandedLayouts, AdaptiveCholeskyFactors
33

44
@testset "infinite-cholesky" begin
55
S = Symmetric(BandedMatrix(0 => 1:∞, 1=> Ones(∞)))
@@ -10,6 +10,28 @@ import InfiniteLinearAlgebra: SymmetricBandedLayouts
1010
b = [randn(10_000); zeros(∞)]
1111
@test cholesky(S) \ b qr(S) \ b S \ b
1212

13+
@testset "copying and L factor" begin
14+
z = 10_000;
15+
A = BandedMatrix(0 => -2*(0:∞)/z, 1 => Ones(∞), -1 => Ones(∞));
16+
M = Symmetric(I-A)
17+
chol = cholesky(M)
18+
19+
# test consistency
20+
@test copy(chol.factors) isa AdaptiveCholeskyFactors
21+
@test copy(chol.factors') isa Adjoint
22+
@test copy(transpose(chol.factors)) isa Transpose
23+
24+
# test copy
25+
@test (chol.factors')[1:10,1:10] == copy(chol.factors')[1:10,1:10]
26+
@test transpose(chol.factors)[1:10,1:10] == copy(chol.factors')[1:10,1:10]
27+
@test (chol.factors)[1:10,1:10] == copy(chol.factors)[1:10,1:10]
28+
29+
# test fetching L factor
30+
L = chol.L
31+
U = chol.U
32+
@test L[1:10,1:10]' == U[1:10,1:10]
33+
end
34+
1335
@testset "singularly perturbed" begin
1436
# using Symmetric(BandedMatrix(...))
1537
ε = 0.0001
@@ -45,4 +67,4 @@ import InfiniteLinearAlgebra: SymmetricBandedLayouts
4567
@test (F.U * F.U')[1:10,1:10] F.U[1:10,1:12] * F.U[1:10,1:12]'
4668
@test (F.U' * F.U)[1:10,1:10] S[1:10,1:10]
4769
end
48-
end
70+
end

0 commit comments

Comments
 (0)