def unwrap_fcs()

in src/lighteval/metrics/utils/math_comparison.py [0:0]


def unwrap_fcs(expr: Basic | MatrixBase) -> Basic | MatrixBase:
    """Unwrap function calls to their arguments."""
    if not isinstance(expr, Basic):
        return expr

    if hasattr(expr, "func") and isinstance(expr.func, UndefinedFunction):
        func_name = expr.func.__name__
        unwrapped_args = [str(unwrap_fcs(arg)) for arg in expr.args]
        return Symbol(f"{func_name}_{'_'.join(unwrapped_args)}")

    try:
        new_args = [unwrap_fcs(arg) for arg in expr.args]
        if new_args:
            return expr.func(*new_args)
    except TimeoutError:
        raise
    except Exception:  # noqa: E722
        pass

    return expr