private static void reduce(IndexedTensor argument, ValueAggregator aggregator, DirectIndexedAddress address, int[] reduce, int reduceIndex) {
        int currentIndex = reduce[reduceIndex];
        int dimSize = Convert.safe2Int(argument.dimensionSizes().size(currentIndex));
        if (reduceIndex + 1  < reduce.length) {
            int nextDimension = reduceIndex + 1;
            for (int i = 0; i < dimSize; i++) {
                address.setIndex(currentIndex, i);
                reduce(argument, aggregator, address, reduce, nextDimension);
            }
        } else {
            address.setIndex(currentIndex, 0);
            long increment = address.getStride(currentIndex);
            long directIndex = address.getDirectIndex();
            for (int i = 0; i < dimSize; i++) {
                aggregator.aggregate(argument.get(directIndex + i * increment));
            }
        }
    }
Creates a reduce function.

@param argument the tensor to reduce
@param aggregator the aggregator function to use
@param dimensions the list of dimensions to remove. If an empty list is given, all dimensions are reduced,
                  producing a dimensionless tensor (a scalar).
@throws IllegalArgumentException if any of the tensor dimensions are not present in the input tensor
vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java