Search in sources :

Example 6 with ExpressionNode

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

the class ConstantDereferencer method transformArguments.

private ExpressionNode transformArguments(ReferenceNode node, TransformContext context) {
    List<ExpressionNode> arguments = node.getArguments().expressions();
    List<ExpressionNode> transformedArguments = new ArrayList<>(arguments.size());
    for (ExpressionNode argument : arguments) transformedArguments.add(transform(argument, context));
    return node.setArguments(transformedArguments);
}
Also used : ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) ArrayList(java.util.ArrayList)

Example 7 with ExpressionNode

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

the class Simplifier method transformArithmetic.

private ExpressionNode transformArithmetic(ArithmeticNode node) {
    if (node.children().size() > 1) {
        List<ExpressionNode> children = new ArrayList<>(node.children());
        List<ArithmeticOperator> operators = new ArrayList<>(node.operators());
        for (ArithmeticOperator operator : ArithmeticOperator.operatorsByPrecedence) transform(operator, children, operators);
        node = new ArithmeticNode(children, operators);
    }
    if (isConstant(node))
        return new ConstantNode(node.evaluate(null));
    else if (// disregarding the /0 case
    allMultiplicationOrDivision(node) && hasZero(node))
        return new ConstantNode(new DoubleValue(0));
    else
        return node;
}
Also used : ArithmeticNode(com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode) ConstantNode(com.yahoo.searchlib.rankingexpression.rule.ConstantNode) DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) ArrayList(java.util.ArrayList) ArithmeticOperator(com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator)

Example 8 with ExpressionNode

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

the class ExpressionTransformer method transformChildren.

/**
 * Utility method which calls transform on each child of the given node and return the resulting transformed
 * composite
 */
protected CompositeNode transformChildren(CompositeNode node, CONTEXT context) {
    List<ExpressionNode> children = node.children();
    List<ExpressionNode> transformedChildren = new ArrayList<>(children.size());
    for (ExpressionNode child : children) transformedChildren.add(transform(child, context));
    return node.setChildren(transformedChildren);
}
Also used : ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) ArrayList(java.util.ArrayList)

Example 9 with ExpressionNode

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

the class Mean method lazyGetFunction.

// todo: optimization: if keepDims and one reduce dimension that has size 1: same as identity.
@Override
protected TensorFunction lazyGetFunction() {
    if (!allInputTypesPresent(2)) {
        return null;
    }
    TensorFunction inputFunction = inputs.get(0).function().get();
    TensorFunction output = new Reduce(inputFunction, Reduce.Aggregator.avg, reduceDimensions);
    if (shouldKeepDimensions()) {
        // multiply with a generated tensor created from the reduced dimensions
        TensorType.Builder typeBuilder = new TensorType.Builder();
        for (String name : reduceDimensions) {
            typeBuilder.indexed(name, 1);
        }
        TensorType generatedType = typeBuilder.build();
        ExpressionNode generatedExpression = new ConstantNode(new DoubleValue(1));
        Generate generatedFunction = new Generate(generatedType, new GeneratorLambdaFunctionNode(generatedType, generatedExpression).asLongListToDoubleOperator());
        output = new com.yahoo.tensor.functions.Join(output, generatedFunction, ScalarFunctions.multiply());
    }
    return output;
}
Also used : GeneratorLambdaFunctionNode(com.yahoo.searchlib.rankingexpression.rule.GeneratorLambdaFunctionNode) OrderedTensorType(com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType) TensorType(com.yahoo.tensor.TensorType) Reduce(com.yahoo.tensor.functions.Reduce) ConstantNode(com.yahoo.searchlib.rankingexpression.rule.ConstantNode) TensorFunction(com.yahoo.tensor.functions.TensorFunction) DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) Generate(com.yahoo.tensor.functions.Generate)

Example 10 with ExpressionNode

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

the class GBDTForestOptimizer method optimize.

/**
 * Optimize the given node, if it is the root of a gdbt forest. Otherwise do nothing and return false
 */
private boolean optimize(ExpressionNode node, List<Double> forest) {
    if (node instanceof GBDTNode) {
        addTo(forest, (GBDTNode) node);
        currentTreesOptimized++;
        return true;
    }
    if (!(node instanceof ArithmeticNode)) {
        return false;
    }
    ArithmeticNode aNode = (ArithmeticNode) node;
    for (ArithmeticOperator op : aNode.operators()) {
        if (op != ArithmeticOperator.PLUS) {
            return false;
        }
    }
    for (ExpressionNode child : aNode.children()) {
        if (!optimize(child, forest)) {
            return false;
        }
    }
    return true;
}
Also used : ArithmeticNode(com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) ArithmeticOperator(com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator)

Aggregations

ExpressionNode (com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)21 TensorType (com.yahoo.tensor.TensorType)8 ArrayList (java.util.ArrayList)7 DoubleValue (com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue)6 ConstantNode (com.yahoo.searchlib.rankingexpression.rule.ConstantNode)6 ReferenceNode (com.yahoo.searchlib.rankingexpression.rule.ReferenceNode)6 TensorFunctionNode (com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode)5 OrderedTensorType (com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType)4 ArithmeticNode (com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode)4 CompositeNode (com.yahoo.searchlib.rankingexpression.rule.CompositeNode)4 GeneratorLambdaFunctionNode (com.yahoo.searchlib.rankingexpression.rule.GeneratorLambdaFunctionNode)4 Generate (com.yahoo.tensor.functions.Generate)4 ArithmeticOperator (com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator)3 Reduce (com.yahoo.tensor.functions.Reduce)3 TensorFunction (com.yahoo.tensor.functions.TensorFunction)3 RankingExpression (com.yahoo.searchlib.rankingexpression.RankingExpression)2 RankProfile (com.yahoo.searchdefinition.RankProfile)1 Reference (com.yahoo.searchlib.rankingexpression.Reference)1 Value (com.yahoo.searchlib.rankingexpression.evaluation.Value)1 ComparisonNode (com.yahoo.searchlib.rankingexpression.rule.ComparisonNode)1