Skip to content

Commit cb34d10

Browse files
Relax test tolerance for mixed precision methods
Mixed precision methods (32Mixed) use Float32 internally and have reduced accuracy compared to full Float64 precision. Changed tolerance from 1e-10 to 1e-5 for these methods in allocation tests to account for the expected precision loss. Also added proper imports for the mixed precision types. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent d6d6f02 commit cb34d10

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

test/nopre/caching_allocation_tests.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using LinearSolve, LinearAlgebra, SparseArrays, Test, StableRNGs
22
using AllocCheck
3-
using LinearSolve: AbstractDenseFactorization, AbstractSparseFactorization
3+
using LinearSolve: AbstractDenseFactorization, AbstractSparseFactorization,
4+
MKL32MixedLUFactorization, OpenBLAS32MixedLUFactorization,
5+
AppleAccelerate32MixedLUFactorization, RF32MixedLUFactorization
46
using InteractiveUtils
57

68
rng = StableRNG(123)
@@ -55,13 +57,20 @@ rng = StableRNG(123)
5557
A
5658
end
5759

60+
# Mixed precision methods need looser tolerance
61+
is_mixed_precision = alg isa Union{MKL32MixedLUFactorization,
62+
OpenBLAS32MixedLUFactorization,
63+
AppleAccelerate32MixedLUFactorization,
64+
RF32MixedLUFactorization}
65+
tol = is_mixed_precision ? 1e-5 : 1e-10
66+
5867
# Initialize the cache
5968
prob = LinearProblem(test_A, b1)
6069
cache = init(prob, alg)
6170

6271
# First solve - this will create the factorization
6372
sol1 = solve!(cache)
64-
@test norm(test_A * sol1.u - b1) < 1e-10
73+
@test norm(test_A * sol1.u - b1) < tol
6574

6675
# Define the allocation-free solve function
6776
function solve_with_new_b!(cache, new_b)
@@ -79,11 +88,11 @@ rng = StableRNG(123)
7988
# Run the allocation test
8089
try
8190
@test_nowarn solve_no_alloc!(cache, b2)
82-
@test norm(test_A * cache.u - b2) < 1e-10
91+
@test norm(test_A * cache.u - b2) < tol
8392

8493
# Test one more time with different b
8594
@test_nowarn solve_no_alloc!(cache, b3)
86-
@test norm(test_A * cache.u - b3) < 1e-10
95+
@test norm(test_A * cache.u - b3) < tol
8796
catch e
8897
# Some algorithms might still allocate in certain Julia versions
8998
@test_broken false

0 commit comments

Comments
 (0)