blob: 4ac7b21ba9092feac009e5ac892c1c4b7723e0ae (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.tensor.functions;
import com.google.common.annotations.Beta;
import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.evaluation.EvaluationContext;
import java.util.Collections;
import java.util.List;
/**
* A function which returns a constant tensor.
*
* @author bratseth
*/
@Beta
public class ConstantTensor extends PrimitiveTensorFunction {
private final Tensor constant;
public ConstantTensor(String tensorString) {
this.constant = Tensor.from(tensorString);
}
public ConstantTensor(Tensor tensor) {
this.constant = tensor;
}
@Override
public List<TensorFunction> functionArguments() { return Collections.emptyList(); }
@Override
public TensorFunction replaceArguments(List<TensorFunction> arguments) {
if ( arguments.size() != 1)
throw new IllegalArgumentException("ConstantTensor must have 0 arguments, got " + arguments.size());
return this;
}
@Override
public PrimitiveTensorFunction toPrimitive() { return this; }
@Override
public Tensor evaluate(EvaluationContext context) { return constant; }
@Override
public String toString(ToStringContext context) { return constant.toString(); }
}
|