@@ -47,29 +47,8 @@ def compare(candidate: Pack, golden: Pack, tol: Tolerance) -> typing.Tuple[Error
4747
4848 def raise_err_with_max_diagnostics (msg : str ):
4949 # Find maximum errors across ALL files for diagnostics
50- max_abs_info , max_rel_info = find_maximum_errors (candidate , golden )
51-
52- diagnostic_msg = ""
53- if max_abs_info :
54- max_abs_filepath , max_abs_valIndex , max_abs_gVal , max_abs_cVal , max_abs_error , max_abs_rel_error = max_abs_info
55- rel_error_str = f"{ max_abs_rel_error :.2E} " if not math .isnan (max_abs_rel_error ) else "NaN"
56- diagnostic_msg += f"\n \n Diagnostics - Maximum absolute error across ALL files:\n " \
57- f" - File: { max_abs_filepath } \n " \
58- f" - Variable n°{ max_abs_valIndex + 1 } \n " \
59- f" - Candidate: { max_abs_cVal } \n " \
60- f" - Golden: { max_abs_gVal } \n " \
61- f" - Absolute Error: { max_abs_error :.2E} \n " \
62- f" - Relative Error: { rel_error_str } "
63-
64- if max_rel_info :
65- max_rel_filepath , max_rel_valIndex , max_rel_gVal , max_rel_cVal , max_rel_error , max_rel_abs_error = max_rel_info
66- diagnostic_msg += f"\n \n Diagnostics - Maximum relative error across ALL files:\n " \
67- f" - File: { max_rel_filepath } \n " \
68- f" - Variable n°{ max_rel_valIndex + 1 } \n " \
69- f" - Candidate: { max_rel_cVal } \n " \
70- f" - Golden: { max_rel_gVal } \n " \
71- f" - Relative Error: { max_rel_error :.2E} \n " \
72- f" - Absolute Error: { max_rel_abs_error :.2E} "
50+ max_errors = find_maximum_errors (candidate , golden )
51+ diagnostic_msg = format_diagnostic_message (max_errors )
7352
7453 return None , f"""\
7554 Variable n°{ valIndex + 1 } (1-indexed) in { gFilepath } { msg } :
@@ -90,6 +69,35 @@ def raise_err_with_max_diagnostics(msg: str):
9069 return avg_err .get (), None
9170
9271
72+ def format_diagnostic_message (max_errors : typing .Tuple [typing .Optional [typing .Tuple [str , int , float , float , float , float ]], typing .Optional [typing .Tuple [str , int , float , float , float , float ]]]) -> str :
73+ """Format the diagnostic message showing maximum errors."""
74+ max_abs_info , max_rel_info = max_errors
75+ diagnostic_msg = ""
76+
77+ if max_abs_info :
78+ filepath , var_idx , golden_val , candidate_val , abs_error , rel_error = max_abs_info
79+ rel_error_str = f"{ rel_error :.2E} " if not math .isnan (rel_error ) else "NaN"
80+ diagnostic_msg += f"\n \n Diagnostics - Maximum absolute error across ALL files:\n " \
81+ f" - File: { filepath } \n " \
82+ f" - Variable n°{ var_idx + 1 } \n " \
83+ f" - Candidate: { candidate_val } \n " \
84+ f" - Golden: { golden_val } \n " \
85+ f" - Absolute Error: { abs_error :.2E} \n " \
86+ f" - Relative Error: { rel_error_str } "
87+
88+ if max_rel_info :
89+ filepath , var_idx , golden_val , candidate_val , rel_error , abs_error = max_rel_info
90+ diagnostic_msg += f"\n \n Diagnostics - Maximum relative error across ALL files:\n " \
91+ f" - File: { filepath } \n " \
92+ f" - Variable n°{ var_idx + 1 } \n " \
93+ f" - Candidate: { candidate_val } \n " \
94+ f" - Golden: { golden_val } \n " \
95+ f" - Relative Error: { rel_error :.2E} \n " \
96+ f" - Absolute Error: { abs_error :.2E} "
97+
98+ return diagnostic_msg
99+
100+
93101def find_maximum_errors (candidate : Pack , golden : Pack ) -> typing .Tuple [typing .Optional [typing .Tuple [str , int , float , float , float , float ]], typing .Optional [typing .Tuple [str , int , float , float , float , float ]]]:
94102 """
95103 Scan all files to find the maximum absolute and relative errors.
0 commit comments