--- Final Solver (used for performance test) ---
import numpy as np
from typing import Any

class Solver:
    def __init__(self):
        """Pre-allocate buffers for reuse across calls."""
        pass
    
    def solve(self, problem: dict[str, Any]) -> dict[str, list]:
        """
        Solve Euclidean projection onto the probability simplex.
        Optimized numpy implementation.
        """
        y = np.asarray(problem.get("y"), dtype=np.float64).ravel()
        n = len(y)
        
        # Sort y in descending order - use np.flip(np.sort(y)) for efficiency
        sorted_y = np.flip(np.sort(y))
        
        # Compute cumulative sum minus 1
        cumsum_y = np.cumsum(sorted_y) - 1.0
        
        # Compute threshold: sorted_y[i] > cumsum_y[i] / (i+1)
        indices = np.arange(1, n + 1, dtype=np.float64)
        rho = np.where(sorted_y > cumsum_y / indices)[0][-1]
        theta = cumsum_y[rho] / (rho + 1)
        
        # Project onto simplex
        x = np.maximum(y - theta, 0.0)
        return {"solution": x}
--- 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: 6.9896s
Total Solver Time:   6.7444s
Raw Speedup:         1.0364 x
Final Reward (Score): 1.0364
---------------------------
..

==================================== 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 361.75s (0:06:01) =========================
