use of com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator 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.ArithmeticOperator 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;
}
use of com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator in project vespa by vespa-engine.
the class Reshape method unrollTensorExpression.
private static ExpressionNode unrollTensorExpression(TensorType type) {
if (type.rank() == 0) {
return new ConstantNode(DoubleValue.zero);
}
List<ExpressionNode> children = new ArrayList<>();
List<ArithmeticOperator> operators = new ArrayList<>();
int size = 1;
for (int i = type.dimensions().size() - 1; i >= 0; --i) {
TensorType.Dimension dimension = type.dimensions().get(i);
children.add(0, new ReferenceNode(dimension.name()));
if (size > 1) {
operators.add(0, ArithmeticOperator.MULTIPLY);
children.add(0, new ConstantNode(new DoubleValue(size)));
}
size *= TensorConverter.dimensionSize(dimension);
if (i > 0) {
operators.add(0, ArithmeticOperator.PLUS);
}
}
return new ArithmeticNode(children, operators);
}
Aggregations