Search in sources :

Example 6 with ArithmeticNode

use of com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode in project vespa by vespa-engine.

the class EvaluationTestCase method testProgrammaticBuildingAndPrecedence.

@Test
public void testProgrammaticBuildingAndPrecedence() {
    RankingExpression standardPrecedence = new RankingExpression(new ArithmeticNode(constant(2), ArithmeticOperator.PLUS, new ArithmeticNode(constant(3), ArithmeticOperator.MULTIPLY, constant(4))));
    RankingExpression oppositePrecedence = new RankingExpression(new ArithmeticNode(new ArithmeticNode(constant(2), ArithmeticOperator.PLUS, constant(3)), ArithmeticOperator.MULTIPLY, constant(4)));
    assertEquals(14.0, standardPrecedence.evaluate(null).asDouble(), tolerance);
    assertEquals(20.0, oppositePrecedence.evaluate(null).asDouble(), tolerance);
    assertEquals("2.0 + 3.0 * 4.0", standardPrecedence.toString());
    assertEquals("(2.0 + 3.0) * 4.0", oppositePrecedence.toString());
}
Also used : ArithmeticNode(com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode) RankingExpression(com.yahoo.searchlib.rankingexpression.RankingExpression) Test(org.junit.Test)

Aggregations

ArithmeticNode (com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode)6 ExpressionNode (com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)4 DoubleValue (com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue)3 ArithmeticOperator (com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator)3 ConstantNode (com.yahoo.searchlib.rankingexpression.rule.ConstantNode)3 ReferenceNode (com.yahoo.searchlib.rankingexpression.rule.ReferenceNode)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 RankingExpression (com.yahoo.searchlib.rankingexpression.RankingExpression)1 Value (com.yahoo.searchlib.rankingexpression.evaluation.Value)1 OrderedTensorType (com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType)1 TensorFunctionNode (com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode)1 TensorType (com.yahoo.tensor.TensorType)1 Reduce (com.yahoo.tensor.functions.Reduce)1