--- Final Solver (used for performance test) ---
import sys
sys.path.insert(0, '/app')
import numpy as np
import numba
from typing import Any

# Try to import compiled extension
try:
    import _simplex_module
    _HAS_CEXT = True
except ImportError:
    _HAS_CEXT = False

@numba.njit(fastmath=True)
def solve_newton(y_data, n, max_iter=30):
    t = 0.0
    for i in range(n):
        t += y_data[i]
    t = t / n - 1.0 / n
    
    for _ in range(max_iter):
        s = 0.0
        count = 0
        for i in range(n):
            if y_data[i] > t:
                s += y_data[i]
                count += 1
        if count == 0:
            break
        t_new = (s - 1.0) / count
        if abs(t_new - t) < 1e-12:
            t = t_new
            break
        t = t_new
    
    res = np.empty(n, dtype=np.float64)
    for i in range(n):
        v = y_data[i] - t
        res[i] = v if v > 0.0 else 0.0
    return res

class Solver:
    def __init__(self):
        # Trigger JIT compilation
        arr = np.array([1.0, 1.2])
        if _HAS_CEXT:
            _ = np.array(_simplex_module.project_simplex(arr))
        solve_newton(arr, 2)
    
    def solve(self, problem, **kwargs) -> Any:
        y = problem.get("y")
        
        if _HAS_CEXT:
            # C extension path - works with lists and arrays
            # Fast for small n, let C extension handle all sizes since it
            # directly processes lists
            x = np.array(_simplex_module.project_simplex(y))
            return {"solution": x}
        
        # Fallback to numpy path
        arr = np.asarray(y, dtype=np.float64).ravel()
        n = arr.size
        sorted_y = np.sort(arr)[::-1]
        cumsum_y = np.cumsum(sorted_y) - 1.0
        ar = np.arange(1, n + 1, dtype=np.float64)
        div = cumsum_y / ar
        mask = sorted_y > div
        rho = np.count_nonzero(mask) - 1
        theta = cumsum_y[rho] / (rho + 1)
        arr -= theta
        arr[arr < 0] = 0.0
        return {"solution": arr}
--- End Solver ---
Running performance test...
============================= test session starts ==============================
platform linux -- Python 3.12.13, pytest-9.0.2, pluggy-1.6.0
rootdir: /tests
plugins: anyio-4.13.0, jaxtyping-0.3.9
collected 3 items

../tests/test_outputs.py .
--- Performance Summary ---
Validity: True
Total Baseline Time: 7.5353s
Total Solver Time:   6.9246s
Raw Speedup:         1.0882 x
Final Reward (Score): 1.0882
---------------------------
..

==================================== PASSES ====================================
=========================== short test summary info ============================
PASSED ../tests/test_outputs.py::test_solver_exists
PASSED ../tests/test_outputs.py::test_solver_validity
PASSED ../tests/test_outputs.py::test_solver_speedup
======================== 3 passed in 365.05s (0:06:05) =========================
