Repository: dask/dask
File: dask/array/einsumfuncs.py (Python)

Code before:
    inputs, outputs, ops = parse_einsum_input(operands)
    subscripts = "->".join((inputs, outputs))

    # Infer the output dtype from operands
    if dtype is None:
        dtype = np.result_type(*[o.dtype for o in ops])

    if optimize is not False:
        # Avoid computation of dask arrays within np.einsum_path
        # by passing in small numpy arrays broadcasted
        # up to the right shape
        fake_ops = [np.broadcast_to(o.dtype.type(0), shape=o.shape) for o in ops]
        optimize, _ = np.einsum_path(subscripts, *fake_ops, optimize=optimize)

    inputs = [tuple(i) for i in inputs.split(",")]

    # Set of all indices
    all_inds = {a for i in inputs for a in i}

    # Which indices are contracted?
    contract_inds = all_inds - set(outputs)
    ncontract_inds = len(contract_inds)

    if len(inputs) > 1 and len(outputs) > 0:
        # Calculate the increase in chunk size compared to the largest input chunk
        max_chunk_sizes, max_chunk_size_inuput = [], 1
        for op, input in zip(ops, inputs):
            max_chunk_size_inuput = max(
                reduce(mul, map(max, op.chunks)), max_chunk_size_inuput
            )
            max_chunk_sizes.extend(
                max(op.chunks[i])
                for i, inp in enumerate(input)
                if inp not in contract_inds
            )

        max_chunk_size_output = reduce(mul, max_chunk_sizes)
        factor = max_chunk_size_output / (
            max_chunk_size_inuput * config.get("array.chunk-size-tolerance")
        )

        # Rechunk inputs to make input chunks smaller to avoid an increase in
        # output chunks
        new_ops = []
        for op, input in zip(ops, inputs):
            changeable_dimensions = {ctr for ctr, i in enumerate(input) if i in outputs}
            f = max(factor ** (len(changeable_dimensions) / len(outputs)), 1)
            result = _calculate_new_chunksizes(
                op.chunks,
                list(op.chunks),
                changeable_dimensions,

Review comment (suggestion):
nit (it looks like this typo is already on main)
```suggestion
        max_chunk_sizes, max_chunk_size_input = [], 1
```

Code after:
    inputs, outputs, ops = parse_einsum_input(operands)
    subscripts = "->".join((inputs, outputs))

    # Infer the output dtype from operands
    if dtype is None:
        dtype = np.result_type(*[o.dtype for o in ops])

    if optimize is not False:
        # Avoid computation of dask arrays within np.einsum_path
        # by passing in small numpy arrays broadcasted
        # up to the right shape
        fake_ops = [np.broadcast_to(o.dtype.type(0), shape=o.shape) for o in ops]
        optimize, _ = np.einsum_path(subscripts, *fake_ops, optimize=optimize)

    inputs = [tuple(i) for i in inputs.split(",")]

    # Set of all indices
    all_inds = {a for i in inputs for a in i}

    # Which indices are contracted?
    contract_inds = all_inds - set(outputs)
    ncontract_inds = len(contract_inds)

    if len(inputs) > 1 and len(outputs) > 0:
        # Calculate the increase in chunk size compared to the largest input chunk
        max_chunk_sizes, max_chunk_size_input = [], 1
        for op, input in zip(ops, inputs):
            max_chunk_size_input = max(
                reduce(mul, map(max, op.chunks)), max_chunk_size_input
            )
            max_chunk_sizes.extend(
                max(op.chunks[i])
                for i, inp in enumerate(input)
                if inp not in contract_inds
            )

        max_chunk_size_output = reduce(mul, max_chunk_sizes)
        factor = max_chunk_size_output / (
            max_chunk_size_input * config.get("array.chunk-size-tolerance")
        )

        # Rechunk inputs to make input chunks smaller to avoid an increase in
        # output chunks
        new_ops = []
        for op, input in zip(ops, inputs):
            changeable_dimensions = {ctr for ctr, i in enumerate(input) if i in outputs}
            f = max(factor ** (len(changeable_dimensions) / len(outputs)), 1)
            result = _calculate_new_chunksizes(
                op.chunks,
                list(op.chunks),
                changeable_dimensions,