def _einsum(*operands: Any, **kwargs: Any) -> ArrayType:
    """Base einsum, but with pre-parse for valid characters if a string is given."""
    fn = backends.get_func("einsum", kwargs.pop("backend", "numpy"))

    if not isinstance(operands[0], str):
        return fn(*operands, **kwargs)

    einsum_str, operands = operands[0], operands[1:]

    # Do we need to temporarily map indices into [a-z,A-Z] range?
    if not parser.has_valid_einsum_chars_only(einsum_str):
        # Explicitly find output str first so as to maintain order
        if "->" not in einsum_str:
            einsum_str += "->" + parser.find_output_str(einsum_str)

        einsum_str = parser.convert_to_valid_einsum_chars(einsum_str)

    kwargs = _filter_einsum_defaults(kwargs)  # type: ignore
    return fn(einsum_str, *operands, **kwargs)
Base einsum, but with pre-parse for valid characters if a string is given.
opt_einsum/contract.py