def METHOD_NAME(x, index, dim_size, reduce):
    if reduce == 'min' or reduce == 'max':
        reduce = f'a{aggr}'  # `amin` or `amax`
    elif reduce == 'mul':
        reduce = 'prod'
    out = x.new_zeros(dim_size, x.size(-1))
    include_self = reduce in ['sum', 'mean']
    index = index.view(-1, 1).expand(-1, x.size(-1))
    out.scatter_reduce_(0, index, x, reduce, include_self=include_self)
    return out