aboutsummaryrefslogtreecommitdiffstats
path: root/model-integration/src/main/java/ai/vespa/rankingexpression/importer/operations/Map.java
blob: 6f6819b96255a52b584d2031a7d8de01a2ff4944 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.rankingexpression.importer.operations;

import ai.vespa.rankingexpression.importer.OrderedTensorType;
import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.tensor.functions.TensorFunction;

import java.util.List;
import java.util.Optional;
import java.util.function.DoubleUnaryOperator;

public class Map extends IntermediateOperation {

    private final DoubleUnaryOperator operator;

    public Map(String modelName, String nodeName, List<IntermediateOperation> inputs, DoubleUnaryOperator operator) {
        super(modelName, nodeName, inputs);
        this.operator = operator;
    }

    @Override
    protected OrderedTensorType lazyGetType() {
        if (!allInputTypesPresent(1)) {
            return null;
        }
        return inputs.get(0).type().get();
    }

    @Override
    protected TensorFunction<Reference> lazyGetFunction() {
        if (!allInputFunctionsPresent(1)) {
            return null;
        }
        Optional<TensorFunction<Reference>> input = inputs.get(0).function();
        return new com.yahoo.tensor.functions.Map<>(input.get(), operator);
    }

    @Override
    public Map withInputs(List<IntermediateOperation> inputs) {
        return new Map(modelName(), name(), inputs, operator);
    }

    @Override
    public String operationName() { return "Map"; }

}