@@ -190,116 +190,7 @@ using Preferences
190190 end
191191 end
192192
193- @testset " Preference-Based Algorithm Selection Simulation" begin
194- # Simulate what should happen when preference system is fully active
195-
196- # Test different preference combinations
197- test_scenarios = [
198- (" RFLUFactorization" , " FastLUFactorization" , " RF available, FastLU fallback" ),
199- (" FastLUFactorization" , " LUFactorization" , " FastLU best, LU fallback" ),
200- (" NonExistentAlgorithm" , " FastLUFactorization" , " Invalid best, FastLU fallback" ),
201- (" NonExistentAlgorithm" , " NonExistentAlgorithm" , " Both invalid, use heuristics" )
202- ]
203-
204- A = rand (Float64, 150 , 150 ) + I (150 )
205- b = rand (Float64, 150 )
206- prob = LinearProblem (A, b)
207-
208- for (best_alg, fallback_alg, description) in test_scenarios
209- println (" Testing scenario: " , description)
210-
211- # Set preferences for this scenario
212- Preferences. set_preferences! (LinearSolve, " best_algorithm_Float64_medium" => best_alg; force = true )
213- Preferences. set_preferences! (LinearSolve, " best_always_loaded_Float64_medium" => fallback_alg; force = true )
214-
215- # Test that system remains robust
216- chosen_alg = LinearSolve. defaultalg (A, b, LinearSolve. OperatorAssumptions (true ))
217- @test isa (chosen_alg, LinearSolve. DefaultLinearSolver)
218-
219- sol = solve (prob)
220- @test sol. retcode == ReturnCode. Success
221- @test norm (A * sol. u - b) < 1e-8
222-
223- println (" Chosen algorithm: " , chosen_alg. alg)
224- end
225- end
226193
227- @testset " Size Category Boundary Verification with FastLapack" begin
228- # Test that size boundaries match LinearSolveAutotune categories exactly
229- # Use FastLapack as a test case since it's slow and normally never chosen
230-
231- # Define the correct size boundaries (matching LinearSolveAutotune)
232- size_boundaries = [
233- # (test_size, expected_category, boundary_description)
234- (15 , " tiny" , " within tiny range (≤20)" ),
235- (20 , " tiny" , " at tiny boundary (=20)" ),
236- (21 , " small" , " start of small range (=21)" ),
237- (80 , " small" , " within small range (21-100)" ),
238- (100 , " small" , " at small boundary (=100)" ),
239- (101 , " medium" , " start of medium range (=101)" ),
240- (200 , " medium" , " within medium range (101-300)" ),
241- (300 , " medium" , " at medium boundary (=300)" ),
242- (301 , " large" , " start of large range (=301)" ),
243- (500 , " large" , " within large range (301-1000)" ),
244- (1000 , " large" , " at large boundary (=1000)" ),
245- (1001 , " big" , " start of big range (>1000)" )
246- ]
247-
248- for (test_size, expected_category, description) in size_boundaries
249- println (" Testing size $(test_size) : $(description) " )
250-
251- # Clear all preferences first
252- for eltype in target_eltypes
253- for size_cat in size_categories
254- for pref_type in [" best_algorithm" , " best_always_loaded" ]
255- pref_key = " $(pref_type) _$(eltype) _$(size_cat) "
256- if Preferences. has_preference (LinearSolve, pref_key)
257- Preferences. delete_preferences! (LinearSolve, pref_key; force = true )
258- end
259- end
260- end
261- end
262-
263- # Set FastLapack as best for ONLY the expected category
264- Preferences. set_preferences! (LinearSolve, " best_algorithm_Float64_$(expected_category) " => " FastLUFactorization" ; force = true )
265- Preferences. set_preferences! (LinearSolve, " best_always_loaded_Float64_$(expected_category) " => " FastLUFactorization" ; force = true )
266-
267- # Set LUFactorization as default for all OTHER categories
268- for other_category in size_categories
269- if other_category != expected_category
270- Preferences. set_preferences! (LinearSolve, " best_algorithm_Float64_$(other_category) " => " LUFactorization" ; force = true )
271- Preferences. set_preferences! (LinearSolve, " best_always_loaded_Float64_$(other_category) " => " LUFactorization" ; force = true )
272- end
273- end
274-
275- # Create test problem of the specific size
276- A = rand (Float64, test_size, test_size) + I (test_size)
277- b = rand (Float64, test_size)
278-
279- # Check algorithm choice
280- chosen_alg = LinearSolve. defaultalg (A, b, LinearSolve. OperatorAssumptions (true ))
281-
282- if test_size <= 10
283- # Tiny override should always choose GenericLU regardless of preferences
284- @test chosen_alg. alg === LinearSolve. DefaultAlgorithmChoice. GenericLUFactorization
285- println (" ✅ Correctly overrode to GenericLU for tiny matrix (≤10)" )
286- else
287- # For larger matrices, verify the algorithm selection logic
288- @test isa (chosen_alg, LinearSolve. DefaultLinearSolver)
289- println (" ✅ Chose: $(chosen_alg. alg) for $(expected_category) category" )
290-
291- # NOTE: Since AUTOTUNE_PREFS are loaded at compile time, this test verifies
292- # the infrastructure. In a real scenario with preferences loaded at package import,
293- # the algorithm should match the preference for the correct size category.
294- end
295-
296- # Test that the problem can be solved
297- prob = LinearProblem (A, b)
298- sol = solve (prob)
299- @test sol. retcode == ReturnCode. Success
300- @test norm (A * sol. u - b) < (test_size <= 10 ? 1e-12 : 1e-8 )
301- end
302- end
303194
304195 @testset " Different Algorithm for Every Size Category Test" begin
305196 # Test with different algorithm preferences for every size category
@@ -356,7 +247,7 @@ using Preferences
356247 println (" ✅ Tiny override correctly chose GenericLU" )
357248 else
358249 # Test that it chooses the expected algorithm when preference system is active
359- @test chosen_alg. alg === expected_algorithm || isa (chosen_alg, LinearSolve . DefaultLinearSolver)
250+ @test chosen_alg. alg === expected_algorithm
360251 println (" ✅ Size $(test_size) chose: $(chosen_alg. alg) (expected: $(expected_algorithm) )" )
361252 end
362253
@@ -390,7 +281,7 @@ using Preferences
390281 @test chosen_boundary. alg === LinearSolve. DefaultAlgorithmChoice. GenericLUFactorization
391282 else
392283 # Test that it matches expected algorithm for the boundary
393- @test chosen_boundary. alg === boundary_expected || isa (chosen_boundary, LinearSolve . DefaultLinearSolver)
284+ @test chosen_boundary. alg === boundary_expected
394285 println (" Boundary $(boundary_size) ($(boundary_category) ) chose: $(chosen_boundary. alg) " )
395286 end
396287
0 commit comments