summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java
blob: 8ade181bdb7269eb754e4e63dda49027a6693ef6 (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 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.tensor.evaluation;

import com.google.common.annotations.Beta;
import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.functions.PrimitiveTensorFunction;
import com.yahoo.tensor.functions.TensorFunction;
import com.yahoo.tensor.functions.ToStringContext;

import java.util.Collections;
import java.util.List;

/**
 * A tensor variable name which resolves to a tensor in the context at evaluation time
 * 
 * @author bratseth
 */
@Beta
public class VariableTensor extends PrimitiveTensorFunction {

    private final String name;
    
    public VariableTensor(String name) {
        this.name = name;
    }
    
    @Override
    public List<TensorFunction> functionArguments() { return Collections.emptyList(); }

    @Override
    public TensorFunction replaceArguments(List<TensorFunction> arguments) { return this; }

    @Override
    public PrimitiveTensorFunction toPrimitive() { return this; }

    @Override
    public Tensor evaluate(EvaluationContext context) {
        return ((MapEvaluationContext)context).get(name);
    }

    @Override
    public String toString(ToStringContext context) {
        return name;
    }

}