Search in sources :

Example 1 with ReferenceNode

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

the class MacroShadower method transformFunctionNode.

private ExpressionNode transformFunctionNode(FunctionNode function, RankProfileTransformContext context) {
    String name = function.getFunction().toString();
    RankProfile.Macro macro = context.rankProfile().getMacros().get(name);
    if (macro == null) {
        return transformChildren(function, context);
    }
    int functionArity = function.getFunction().arity();
    int macroArity = macro.getFormalParams() != null ? macro.getFormalParams().size() : 0;
    if (functionArity != macroArity) {
        return transformChildren(function, context);
    }
    ReferenceNode node = new ReferenceNode(name, function.children(), null);
    return transformChildren(node, context);
}
Also used : ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) RankProfile(com.yahoo.searchdefinition.RankProfile)

Example 2 with ReferenceNode

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

the class ConstantTensorTransformer method transformConstantReference.

private ExpressionNode transformConstantReference(ReferenceNode node, RankProfileTransformContext context) {
    Value value = context.constants().get(node.getName());
    if (value == null || value.type().rank() == 0) {
        return node;
    }
    TensorValue tensorValue = (TensorValue) value;
    String featureName = CONSTANT + "(" + node.getName() + ")";
    String tensorType = tensorValue.asTensor().type().toString();
    context.rankPropertiesOutput().put(featureName + ".value", tensorValue.toString());
    context.rankPropertiesOutput().put(featureName + ".type", tensorType);
    // TODO: This allows us to reference constant "a" as "a" instead of "constant(a)", but we shouldn't allow that
    return new ReferenceNode(CONSTANT, Arrays.asList(new NameNode(node.getName())), null);
}
Also used : TensorValue(com.yahoo.searchlib.rankingexpression.evaluation.TensorValue) NameNode(com.yahoo.searchlib.rankingexpression.rule.NameNode) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) TensorValue(com.yahoo.searchlib.rankingexpression.evaluation.TensorValue) Value(com.yahoo.searchlib.rankingexpression.evaluation.Value)

Example 3 with ReferenceNode

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

the class TensorFlowOperation method function.

/**
 * Returns the Vespa tensor function implementing all operations from this node with inputs
 */
public Optional<TensorFunction> function() {
    if (function == null) {
        if (isConstant()) {
            ExpressionNode constant = new ReferenceNode(Reference.simple("constant", vespaName()));
            function = new TensorFunctionNode.TensorFunctionExpressionNode(constant);
        } else if (outputs.size() > 1) {
            macro = lazyGetFunction();
            function = new VariableTensor(macroName(), type.type());
        } else {
            function = lazyGetFunction();
        }
    }
    return Optional.ofNullable(function);
}
Also used : VariableTensor(com.yahoo.tensor.evaluation.VariableTensor) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) TensorFunctionNode(com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)

Example 4 with ReferenceNode

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

the class ReferenceTestCase method testToString.

@Test
public void testToString() {
    assertEquals("foo(arg_1)", new Reference("foo", new Arguments(new ReferenceNode("arg_1")), null).toString());
    assertEquals("foo(arg_1).out", new Reference("foo", new Arguments(new ReferenceNode("arg_1")), "out").toString());
    assertEquals("foo(arg_1).out", new Reference("foo", new Arguments(new NameNode("arg_1")), "out").toString());
    assertEquals("foo", new Reference("foo", new Arguments(), null).toString());
}
Also used : NameNode(com.yahoo.searchlib.rankingexpression.rule.NameNode) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) Arguments(com.yahoo.searchlib.rankingexpression.rule.Arguments) Test(org.junit.Test)

Example 5 with ReferenceNode

use of com.yahoo.searchlib.rankingexpression.rule.ReferenceNode 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;
}
Also used : CompositeNode(com.yahoo.searchlib.rankingexpression.rule.CompositeNode) TensorFunctionNode(com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode) TensorFunction(com.yahoo.tensor.functions.TensorFunction) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) ArrayList(java.util.ArrayList) Rename(com.yahoo.tensor.functions.Rename)

Aggregations

ReferenceNode (com.yahoo.searchlib.rankingexpression.rule.ReferenceNode)12 ExpressionNode (com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)6 NameNode (com.yahoo.searchlib.rankingexpression.rule.NameNode)4 TensorFunctionNode (com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Arguments (com.yahoo.searchlib.rankingexpression.rule.Arguments)2 ArithmeticNode (com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode)2 CompositeNode (com.yahoo.searchlib.rankingexpression.rule.CompositeNode)2 TensorType (com.yahoo.tensor.TensorType)2 Reduce (com.yahoo.tensor.functions.Reduce)2 RankProfile (com.yahoo.searchdefinition.RankProfile)1 DoubleValue (com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue)1 TensorValue (com.yahoo.searchlib.rankingexpression.evaluation.TensorValue)1 Value (com.yahoo.searchlib.rankingexpression.evaluation.Value)1 OrderedTensorType (com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType)1 ParseException (com.yahoo.searchlib.rankingexpression.parser.ParseException)1 RankingExpressionParser (com.yahoo.searchlib.rankingexpression.parser.RankingExpressionParser)1 TokenMgrError (com.yahoo.searchlib.rankingexpression.parser.TokenMgrError)1 ArithmeticOperator (com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator)1