@Override
    protected TensorFunction<Reference> lazyGetFunction() {
        if ( ! allInputTypesPresent(1)) return null;

        TensorFunction<Reference> inputFunction = inputs.get(0).function().get();
        if (preOperator != null) {
            inputFunction = new com.yahoo.tensor.functions.Map<>(inputFunction, preOperator);
        }
        TensorFunction<Reference> output = new com.yahoo.tensor.functions.Reduce<>(inputFunction, aggregator, reduceDimensions);
        if (shouldKeepDimensions()) {
            // multiply with a generated tensor created from the reduced dimensions
            TensorType.Builder typeBuilder = new TensorType.Builder(resultValueType());
            for (String name : reduceDimensions) {
                typeBuilder.indexed(name, 1);
            }
            TensorType generatedType = typeBuilder.build();
            ExpressionNode generatedExpression = new ConstantNode(new DoubleValue(1));
            Generate<Reference> generatedFunction = new Generate<>(generatedType,
                    new GeneratorLambdaFunctionNode(generatedType, generatedExpression).asLongListToDoubleOperator());
            output = new com.yahoo.tensor.functions.Join<>(output, generatedFunction, ScalarFunctions.multiply());
        }
        if (postOperator != null) {
            output = new com.yahoo.tensor.functions.Map<>(output, postOperator);
        }
        return output;
    }
ONNX Reduce[Sum/Mean/etc] operation
model-integration/src/main/java/ai/vespa/rankingexpression/importer/operations/Reduce.java