Skip to content

Commit 1a1e2b7

Browse files
committed
Add comprehensive tests for SymTridiagonal with LDLtFactorization
- Test explicit LDLtFactorization with SymTridiagonal matrices - Verify default algorithm selects LDLtFactorization for SymTridiagonal - Test that factorization is cached and reused across solves - Include performance test case from issue #732
1 parent 7693f9d commit 1a1e2b7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/basictests.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,37 @@ end
275275
# ws sizes.
276276
end
277277

278+
@testset "SymTridiagonal with LDLtFactorization" begin
279+
# Test that LDLtFactorization works correctly with SymTridiagonal
280+
# and that the default algorithm correctly selects it
281+
k = 100
282+
ρ = 0.95
283+
A_tri = SymTridiagonal(ones(k) .+ ρ^2, -ρ * ones(k-1))
284+
b = rand(k)
285+
286+
# Test with explicit LDLtFactorization
287+
prob_tri = LinearProblem(A_tri, b)
288+
sol = solve(prob_tri, LDLtFactorization())
289+
@test A_tri * sol.u b
290+
291+
# Test that default algorithm uses LDLtFactorization for SymTridiagonal
292+
default_alg = LinearSolve.defaultalg(A_tri, b, OperatorAssumptions(true))
293+
@test default_alg isa DefaultLinearSolver
294+
@test default_alg.alg == LinearSolve.DefaultAlgorithmChoice.LDLtFactorization
295+
296+
# Test that the factorization is cached and reused
297+
cache = init(prob_tri, LDLtFactorization())
298+
sol1 = solve!(cache)
299+
@test A_tri * sol1.u b
300+
@test !cache.isfresh # Cache should not be fresh after first solve
301+
302+
# Solve again with same matrix to ensure cache is reused
303+
cache.b = rand(k) # Change RHS
304+
sol2 = solve!(cache)
305+
@test A_tri * sol2.u cache.b
306+
@test !cache.isfresh # Cache should still not be fresh
307+
end
308+
278309
test_algs = [
279310
LUFactorization(),
280311
QRFactorization(),

0 commit comments

Comments
 (0)