def einsum_dispatcher(*args, **kwargs):
    """Dispatcher for handling einsum.

    einsum can either take string as first argument, in which case backend
    should be inferred from second argument. Or it can take an array as first
    argument, which should be used to infer backend.
    """
    if isinstance(args[0], str):
        return args[1]
    return args[0]