blob: 02a300fabddf048eb88f147c4281c4962ec96173 (
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
47
48
49
50
51
52
53
54
55
56
57
58
|
package com.yahoo.tensor.functions;
import com.google.common.annotations.Beta;
import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.evaluation.EvaluationContext;
import com.yahoo.tensor.evaluation.MapEvaluationContext;
import java.util.List;
/**
* A representation of a tensor function which is able to be translated to a set of primitive
* tensor functions if necessary.
* All tensor functions are immutable.
*
* @author bratseth
*/
@Beta
public abstract class TensorFunction {
/** Returns the function arguments of this node in the order they are applied */
public abstract List<TensorFunction> functionArguments();
/**
* Returns a copy of this tensor function with the arguments replaced by the given list of arguments.
*
* @throws IllegalArgumentException if the argument list has the wrong size for this function
*/
public abstract TensorFunction replaceArguments(List<TensorFunction> arguments);
/**
* Translate this function - and all of its arguments recursively -
* to a tree of primitive functions only.
*
* @return a tree of primitive functions implementing this
*/
public abstract PrimitiveTensorFunction toPrimitive();
/**
* Evaluates this tensor.
*
* @param context a context which must be passed to all nexted functions when evaluating
*/
public abstract Tensor evaluate(EvaluationContext context);
/** Evaluate with no context */
public final Tensor evaluate() { return evaluate(new MapEvaluationContext()); }
/**
* Return a string representation of this context.
*
* @param context a context which must be passed to all nexted functions when requesting the string value
*/
public abstract String toString(ToStringContext context);
@Override
public final String toString() { return toString(ToStringContext.empty()); }
}
|