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