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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations