|
| 1 | +@testset "utils.jl" begin |
| 2 | + @testset "submat" begin |
| 3 | + |
| 4 | + @testset "PDMat" begin |
| 5 | + M = PDMat(TEST_MATRICES["Positive definite"]) |
| 6 | + M_dense = Matrix(M) |
| 7 | + |
| 8 | + subM = submat(M, [1, 3]) |
| 9 | + @test subM isa PDMat |
| 10 | + @test Matrix(subM) == M_dense[[1, 3], [1, 3]] |
| 11 | + end |
| 12 | + |
| 13 | + @testset "PDDiagMat" begin |
| 14 | + M = PDiagMat(diag(TEST_MATRICES["Positive definite"])) |
| 15 | + M_dense = Matrix(M) |
| 16 | + |
| 17 | + subM = submat(M, [1, 3]) |
| 18 | + @test subM isa PDiagMat |
| 19 | + @test Matrix(subM) == M_dense[[1, 3], [1, 3]] |
| 20 | + end |
| 21 | + |
| 22 | + @testset "PDSparseMat" begin |
| 23 | + M = PDSparseMat(sparse(TEST_MATRICES["Positive definite"])) |
| 24 | + M_dense = Matrix(M) |
| 25 | + |
| 26 | + subM = submat(M, [1, 3]) |
| 27 | + @test subM isa PDSparseMat |
| 28 | + @test Matrix(subM) == M_dense[[1, 3], [1, 3]] |
| 29 | + end |
| 30 | + |
| 31 | + @testset "ScalMat" begin |
| 32 | + M = ScalMat(3, 0.1) |
| 33 | + M_dense = Matrix(M) |
| 34 | + |
| 35 | + subM = submat(M, [1, 3]) |
| 36 | + @test subM isa ScalMat |
| 37 | + @test Matrix(subM) == M_dense[[1, 3], [1, 3]] |
| 38 | + @test_throws BoundsError submat(M, [1, 10]) |
| 39 | + end |
| 40 | + |
| 41 | + @testset "PSDMat" begin |
| 42 | + SM = TEST_MATRICES["Positive semi-definite"] |
| 43 | + pivoted = cholesky(SM, Val(true); check=false) |
| 44 | + M = PSDMat(SM, pivoted) |
| 45 | + M_dense = Matrix(M) |
| 46 | + |
| 47 | + subM = submat(M, [1, 3]) |
| 48 | + @test subM isa PSDMat |
| 49 | + @test Matrix(subM) == M_dense[[1, 3], [1, 3]] |
| 50 | + end |
| 51 | + |
| 52 | + @testset "WoodburyPDMat" begin |
| 53 | + A = randn(4, 2) |
| 54 | + D = Diagonal(randn(2).^2 .+ 1) |
| 55 | + S = Diagonal(randn(4).^2 .+ 1) |
| 56 | + x = randn(size(A, 1)) |
| 57 | + |
| 58 | + W = WoodburyPDMat(A, D, S) |
| 59 | + W_dense = PDMat(Symmetric(Matrix(W))) |
| 60 | + |
| 61 | + subW = submat(W, [1, 3]) |
| 62 | + @test subW isa WoodburyPDMat |
| 63 | + @test subW.A == W.A[[1, 3], :] |
| 64 | + @test subW.D == W.D |
| 65 | + @test subW.S == Diagonal(W.S.diag[[1, 3]]) |
| 66 | + @test Matrix(subW) == W_dense[[1, 3], [1, 3]] |
| 67 | + end |
| 68 | + end |
| 69 | +end |
0 commit comments