def _multi_dot(
    arrays: Sequence[ndarray],
    order: npt.NDArray[np.int64],
    i: int,
    j: int,
    out: ndarray | None = None,
) -> ndarray:
    """Actually do the multiplication with the given order."""
    if i == j:
        # the initial call with non-None out should never get here
        assert out is None

        return arrays[i]
    else:
        return dot(
            _multi_dot(arrays, order, i, order[i, j]),
            _multi_dot(arrays, order, order[i, j] + 1, j),
            out=out,
        )
Actually do the multiplication with the given order.
cupynumeric/linalg/linalg.py