"""Global seed utilities for reproducibility."""

import random
import numpy as np
import torch


def set_global_seed(seed: int = 42):
    """Set random seeds for Python, NumPy, and PyTorch (CPU + CUDA)."""
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    if torch.cuda.is_available():
        torch.cuda.manual_seed_all(seed)
    torch.backends.cudnn.benchmark = False
    torch.backends.cudnn.deterministic = True
    try:
        torch.set_float32_matmul_precision("high")
    except Exception:
        pass
