import einx._src.adapter as adapter
from .._util import _to_tensor


def einsum_from_tinygrad(tinygrad):
    def to_tensor(*args):
        to_tensor_one = _to_tensor(tinygrad.Tensor, forward=[tinygrad.Tensor], convert=["numpy", "scalar"])
        return [to_tensor_one(arg) for arg in args]

    return adapter.einsum_from_numpy(tinygrad.Tensor.einsum, to_tensor=to_tensor, multiply=adapter.classical_from_tinygrad.ops(tinygrad).multiply)
