from .core import add_acast, add_acast_if_supported

try:
    import numpy as np, torch
    add_acast_if_supported(
        "torch", "numpy", "Tensor", "ndarray",
        lambda x: x.detach().cpu().numpy()
    )
    add_acast(np.ndarray, torch.Tensor, torch.from_numpy)
    add_acast(np.ndarray, float, lambda x: float(x.item()) if x.size == 1 else float(x[0]))
except ImportError:
    pass
