def METHOD_NAME(
    source: Tensor,
    *,
    mode: str,
    num_pieces: int,
    out_dim: Optional[Dim] = None,
) -> Tensor:
    """
    Combination of :class:`SplitDimsLayer` applied to the feature dim
    and :class:`ReduceLayer` applied to the resulting feature dim.
    This can e.g. be used to do maxout.
    :param source:
    :param mode: "sum" or "max" or "mean"
    :param num_pieces: how many elements to reduce. The output dimension will be input.dim // num_pieces.
    :param out_dim:
    :return: out, with feature_dim set to new dim
    """
    assert source.feature_dim
    parts_dim = Dim(num_pieces, name="readout-parts")
    if not out_dim:
        out_dim = source.feature_dim // parts_dim
    out = rf.split_dims(source, axis=source.feature_dim, dims=(out_dim, parts_dim))
    out = reduce(out, mode=mode, axis=parts_dim)
    out.feature_dim = out_dim
    return out