use of com.yahoo.searchlib.rankingexpression.rule.ExpressionNode in project vespa by vespa-engine.
the class GBDTForestOptimizer method findAndOptimize.
/**
* Recursively descend and optimize gbdt forest nodes.
*
* @return the resulting node, which may be the input node if no optimizations were found
*/
private ExpressionNode findAndOptimize(ExpressionNode node) {
ExpressionNode newNode = optimize(node);
//
if (!(newNode instanceof CompositeNode))
return newNode;
CompositeNode newComposite = (CompositeNode) newNode;
List<ExpressionNode> newChildren = new ArrayList<>();
for (ExpressionNode child : newComposite.children()) {
newChildren.add(findAndOptimize(child));
}
return newComposite.setChildren(newChildren);
}
use of com.yahoo.searchlib.rankingexpression.rule.ExpressionNode in project vespa by vespa-engine.
the class MacroShadower method transform.
@Override
public RankingExpression transform(RankingExpression expression, RankProfileTransformContext context) {
String name = expression.getName();
ExpressionNode node = expression.getRoot();
ExpressionNode result = transform(node, context);
return new RankingExpression(name, result);
}
use of com.yahoo.searchlib.rankingexpression.rule.ExpressionNode in project vespa by vespa-engine.
the class TensorFlowFeatureConverter method reduceBatchDimensionsAtInput.
private ExpressionNode reduceBatchDimensionsAtInput(ExpressionNode node, TensorFlowModel model, TypeContext<Reference> typeContext) {
if (node instanceof TensorFunctionNode) {
TensorFunction tensorFunction = ((TensorFunctionNode) node).function();
if (tensorFunction instanceof Rename) {
List<ExpressionNode> children = ((TensorFunctionNode) node).children();
if (children.size() == 1 && children.get(0) instanceof ReferenceNode) {
ReferenceNode referenceNode = (ReferenceNode) children.get(0);
if (model.requiredMacros().containsKey(referenceNode.getName())) {
return reduceBatchDimensionExpression(tensorFunction, typeContext);
}
}
}
}
if (node instanceof ReferenceNode) {
ReferenceNode referenceNode = (ReferenceNode) node;
if (model.requiredMacros().containsKey(referenceNode.getName())) {
return reduceBatchDimensionExpression(TensorFunctionNode.wrapArgument(node), typeContext);
}
}
if (node instanceof CompositeNode) {
List<ExpressionNode> children = ((CompositeNode) node).children();
List<ExpressionNode> transformedChildren = new ArrayList<>(children.size());
for (ExpressionNode child : children) {
transformedChildren.add(reduceBatchDimensionsAtInput(child, model, typeContext));
}
return ((CompositeNode) node).setChildren(transformedChildren);
}
return node;
}
use of com.yahoo.searchlib.rankingexpression.rule.ExpressionNode in project vespa by vespa-engine.
the class MapEvaluationTypeContext method tensorFeatureType.
/**
* There are two features which returns the (non-empty) tensor type: tensorFromLabels and tensorFromWeightedSet.
* This returns the type of those features if this is a reference to either of them, or empty otherwise.
*/
private Optional<TensorType> tensorFeatureType(Reference reference) {
if (!reference.name().equals("tensorFromLabels") && !reference.name().equals("tensorFromWeightedSet"))
return Optional.empty();
if (reference.arguments().size() != 1 && reference.arguments().size() != 2)
throw new IllegalArgumentException(reference.name() + " must have one or two arguments");
ExpressionNode arg0 = reference.arguments().expressions().get(0);
if (!(arg0 instanceof ReferenceNode) || !FeatureNames.isSimpleFeature(((ReferenceNode) arg0).reference()))
throw new IllegalArgumentException("The first argument of " + reference.name() + " must be a simple feature, not " + arg0);
String dimension;
if (reference.arguments().size() > 1) {
ExpressionNode arg1 = reference.arguments().expressions().get(1);
if ((!(arg1 instanceof ReferenceNode) || !(((ReferenceNode) arg1).reference().isIdentifier())) && (!(arg1 instanceof NameNode)))
throw new IllegalArgumentException("The second argument of " + reference.name() + " must be a dimension name, not " + arg1);
dimension = reference.arguments().expressions().get(1).toString();
} else {
// default
dimension = ((ReferenceNode) arg0).reference().arguments().expressions().get(0).toString();
}
return Optional.of(new TensorType.Builder().mapped(dimension).build());
}
use of com.yahoo.searchlib.rankingexpression.rule.ExpressionNode in project vespa by vespa-engine.
the class TensorTransformer method replaceMaxAndMinFunction.
private ExpressionNode replaceMaxAndMinFunction(FunctionNode node) {
ExpressionNode arg1 = node.children().get(0);
ExpressionNode arg2 = node.children().get(1);
TensorFunctionNode.TensorFunctionExpressionNode expression = TensorFunctionNode.wrapArgument(arg1);
Reduce.Aggregator aggregator = Reduce.Aggregator.valueOf(node.getFunction().name());
String dimension = ((ReferenceNode) arg2).getName();
return new TensorFunctionNode(new Reduce(expression, aggregator, dimension));
}
Aggregations