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

class Solver:
    def __init__(self):
        # Pre-compile the numba function with typical float64 data.
        # This compilation does not count toward runtime.
        a = np.random.randn(100).astype(np.float64)
        b = np.random.randn(100).astype(np.float64)
        self._outer_fast(a, b)
        
        # Also compile float32 version
        af = a.astype(np.float32)
        bf = b.astype(np.float32)
        self._outer_fast_f32(af, bf)
    
    @staticmethod
    @njit(fastmath=True, boundscheck=False)
    def _outer_fast(a, b):
        n = len(a)
        result = np.empty((n, n), dtype=np.float64)
        for i in range(n):
            ai = a[i]
            for j in range(n):
                result[i, j] = ai * b[j]
        return result
    
    @staticmethod
    @njit(fastmath=True, boundscheck=False)
    def _outer_fast_f32(a, b):
        n = len(a)
        result = np.empty((n, n), dtype=np.float32)
        for i in range(n):
            ai = a[i]
            for j in range(n):
                result[i, j] = ai * b[j]
        return result
    
    def solve(self, problem, **kwargs) -> Any:
        vec1, vec2 = problem
        
        vec1 = np.asarray(vec1)
        vec2 = np.asarray(vec2)
        
        # Handle empty arrays
        if vec1.size == 0 or vec2.size == 0:
            return np.outer(vec1, vec2)
        
        # If lengths differ, fall back to np.outer (though spec says equal length)
        if len(vec1) != len(vec2):
            return np.outer(vec1, vec2)
        
        # For very small vectors, broadcasting may have lower overhead
        if len(vec1) < 50:
            if vec1.dtype == np.float32 and vec2.dtype == np.float32:
                return (vec1[:, None] * vec2[None, :]).astype(np.float32)
            else:
                v1 = vec1.astype(np.float64)
                v2 = vec2.astype(np.float64)
                return v1[:, None] * v2[None, :]
        
        # Determine compute dtype
        if vec1.dtype == np.float32 and vec2.dtype == np.float32:
            # Both float32: compute in float32 for speed and memory
            return self._outer_fast_f32(vec1, vec2)
        elif vec1.dtype.kind in ('f', 'i', 'u') and vec2.dtype.kind in ('f', 'i', 'u'):
            # Float or integer: convert to float64 for precision
            v1 = vec1.astype(np.float64, copy=False)
            v2 = vec2.astype(np.float64, copy=False)
            return self._outer_fast(v1, v2)
        else:
            # Fallback for complex or other dtypes
            return np.outer(vec1, vec2)
--- 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.4824s
Total Solver Time:   41.6373s
Raw Speedup:         0.1557 x
Final Reward (Score): 1.0000
---------------------------
.F

=================================== FAILURES ===================================
_____________________________ test_solver_speedup ______________________________

performance_results = {'raw_speedup': 0.15568725549582674, 'speedup': 1.0, 'validity': True}

    def test_solver_speedup(performance_results):
        """Checks if the solver effectively optimized the code."""
>       assert performance_results["raw_speedup"] > 1.0, \
            f"Solver was not faster than baseline (Speedup: {performance_results['raw_speedup']:.2f}x)"
E       AssertionError: Solver was not faster than baseline (Speedup: 0.16x)
E       assert 0.15568725549582674 > 1.0

/tests/test_outputs.py:205: AssertionError
==================================== PASSES ====================================
=========================== short test summary info ============================
PASSED ../tests/test_outputs.py::test_solver_exists
PASSED ../tests/test_outputs.py::test_solver_validity
FAILED ../tests/test_outputs.py::test_solver_speedup - AssertionError: Solver...
=================== 1 failed, 2 passed in 706.63s (0:11:46) ====================
