use of com.yahoo.tensor.functions.Reduce in project vespa by vespa-engine.
the class RankingExpressionTestCase method testProgrammaticBuilding.
@Test
public void testProgrammaticBuilding() throws ParseException {
ReferenceNode input = new ReferenceNode("input");
ReferenceNode constant = new ReferenceNode("constant");
ArithmeticNode product = new ArithmeticNode(input, ArithmeticOperator.MULTIPLY, constant);
Reduce sum = new Reduce(new TensorFunctionNode.TensorFunctionExpressionNode(product), Reduce.Aggregator.sum);
RankingExpression expression = new RankingExpression(new TensorFunctionNode(sum));
RankingExpression expected = new RankingExpression("sum(input * constant)");
assertEquals(expected.toString(), expression.toString());
}
use of com.yahoo.tensor.functions.Reduce in project vespa by vespa-engine.
the class TensorFunctionBenchmark method dotProduct.
private double dotProduct(Tensor tensor, List<Tensor> tensors) {
double largest = Double.MIN_VALUE;
TensorFunction dotProductFunction = new Reduce(new Join(new ConstantTensor(tensor), new VariableTensor("argument"), (a, b) -> a * b), Reduce.Aggregator.sum).toPrimitive();
MapEvaluationContext context = new MapEvaluationContext();
for (Tensor tensorElement : tensors) {
// tensors.size() = 1 for larger tensor
context.put("argument", tensorElement);
double dotProduct = dotProductFunction.evaluate(context).asDouble();
if (dotProduct > largest) {
largest = dotProduct;
}
}
return largest;
}
use of com.yahoo.tensor.functions.Reduce in project vespa by vespa-engine.
the class TensorTestCase method dotProduct.
private double dotProduct(Tensor tensor, List<Tensor> tensors) {
double sum = 0;
TensorFunction dotProductFunction = new Reduce(new Join(new ConstantTensor(tensor), new VariableTensor("argument"), (a, b) -> a * b), Reduce.Aggregator.sum).toPrimitive();
MapEvaluationContext context = new MapEvaluationContext();
for (Tensor tensorElement : tensors) {
// tensors.size() = 1 for larger tensor
context.put("argument", tensorElement);
// System.out.println("Dot product of " + tensor + " and " + tensorElement + ": " + dotProductFunction.evaluate(context).asDouble());
sum += dotProductFunction.evaluate(context).asDouble();
}
return sum;
}
Aggregations