from typing import Protocol, TypeVar, Any, Sequence, runtime_checkable

Tensor = TypeVar("Tensor")


@runtime_checkable
class _Backend(Protocol[Tensor]):
    name: str
    def asarray(self, x: Tensor, like: Tensor | None = None) -> Tensor: ...
    def stack(self, xs: Sequence[Tensor], axis: int = 0) -> Tensor: ...
    def median(self, x: Tensor, axis: int = 0) -> Tensor: ...
    def sort(self, x: Tensor, axis: int = 0) -> Tensor: ...
    def mean(self, x: Tensor, axis: int = 0) -> Tensor: ...
    def abs(self, x: Tensor) -> Tensor: ...
    def argsort(self, x: Tensor, axis: int = 0) -> Tensor: ...
    def take_along_axis(self, a: Tensor, indices: Tensor, axis: int = 0) -> Tensor: ...
    def sum(self, x: Tensor, axis: int | tuple[int, ...] | None = None) -> Tensor: ...
    def index_select(self, a: Tensor, axis: int, indices: Tensor) -> Tensor: ...
    def sqrt(self, x: Tensor) -> Tensor: ...
    def maximum(self, a: Tensor, b: Tensor) -> Tensor: ...
    def reshape(self, x: Tensor, newshape: tuple[int, ...]) -> Tensor: ...
    def max(self, x: Tensor, axis: int | tuple[int, ...] | None = None) -> Tensor: ...
    def minimum(self, a: Tensor, b: Tensor) -> Tensor: ...
    def copy(self, x: Tensor) -> Tensor: ...
