MCPcopy Create free account
hub / github.com/Tencent/hpc-ops / errors_to_string

Function errors_to_string

tests/utils.py:93–173  ·  view source on GitHub ↗

Convert error calculation results to a human-readable string Args: error_results: Dictionary returned by calculate_errors function precision: Number of decimal places to display, default 6 Returns: str: Formatted string with error information

(error_results, precision=6)

Source from the content-addressed store, hash-verified

91
92
93def errors_to_string(error_results, precision=6):
94 """
95 Convert error calculation results to a human-readable string
96
97 Args:
98 error_results: Dictionary returned by calculate_errors function
99 precision: Number of decimal places to display, default 6
100
101 Returns:
102 str: Formatted string with error information
103 """
104 # Create the header section
105 lines = [""]
106 lines.append("=" * 80)
107 lines.append("Error Analysis Results".center(80))
108 lines.append("=" * 80)
109 lines.append("")
110
111 # Add mean error metrics
112 lines.append("Mean Error Metrics:")
113 lines.append("-" * 40)
114 lines.append(f"Mean Absolute Error: {error_results['mean_abs_error']:.{precision}f}")
115 lines.append(f"Mean Relative Error: {error_results['mean_rel_error']:.{precision}f}")
116 lines.append("")
117
118 # Add top absolute errors section
119 lines.append(f"Top {len(error_results['top_abs_errors'])} Absolute Errors:")
120 lines.append("-" * 80)
121 # Header for the table
122 abs_header = (
123 f"Rank".ljust(6)
124 + f"Error Value".ljust(16)
125 + f"Ref Value".ljust(16)
126 + f"Real Value".ljust(16)
127 + f"Position"
128 )
129 lines.append(abs_header)
130 lines.append("-" * 80)
131
132 # Add each top absolute error
133 for i, err in enumerate(error_results["top_abs_errors"], 1):
134 line = (
135 f"{i:^6}"
136 + f"{err['error_value']:.{precision}f}".ljust(16)
137 + f"{err['ref_value']:.{precision}f}".ljust(16)
138 + f"{err['real_value']:.{precision}f}".ljust(16)
139 + f"{err['position']}"
140 )
141 lines.append(line)
142 lines.append("")
143
144 # Add top relative errors section
145 lines.append(f"Top {len(error_results['top_rel_errors'])} Relative Errors:")
146 lines.append("-" * 80)
147 # Header for the table
148 rel_header = (
149 f"Rank".ljust(6)
150 + f"Error Value".ljust(16)

Callers 1

allcloseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected