MCPcopy Index your code
hub / github.com/algorithmicsuperintelligence/optillm / normalize_matrix

Function normalize_matrix

scripts/eval_math500_benchmark.py:184–215  ·  view source on GitHub ↗

Helper function to normalize matrices and vectors.

(matrix_str: str)

Source from the content-addressed store, hash-verified

182 return entry
183
184def normalize_matrix(matrix_str: str) -> str:
185 """Helper function to normalize matrices and vectors."""
186 logger.debug(f"Normalizing matrix input: {repr(matrix_str)}")
187 try:
188 # Remove all whitespace
189 matrix_str = ''.join(matrix_str.split())
190
191 # Extract the matrix content
192 match = re.match(r'^\\begin\{pmatrix\}(.*?)\\end\{pmatrix\}$', matrix_str)
193 if not match:
194 return matrix_str
195
196 content = match.group(1)
197 rows = content.split('\\\\')
198
199 # Normalize each entry in each row
200 normalized_rows = []
201 for row in rows:
202 if '&' in row:
203 entries = [normalize_matrix_entry(entry) for entry in row.split('&')]
204 else:
205 entries = [normalize_matrix_entry(row)]
206 normalized_rows.append('&'.join(entries))
207
208 # Reconstruct the matrix
209 result = "\\begin{pmatrix}" + "\\\\".join(normalized_rows) + "\\end{pmatrix}"
210 logger.debug(f"Normalized matrix result: {repr(result)}")
211 return result
212
213 except Exception as e:
214 logger.debug(f"Failed to normalize matrix: {str(e)}")
215 return matrix_str
216
217def normalize_algebraic_expression(expr: str) -> str:
218 """Helper function to normalize algebraic expressions."""

Callers 1

normalize_answerFunction · 0.85

Calls 1

normalize_matrix_entryFunction · 0.85

Tested by

no test coverage detected