aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/main
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2019-06-12 20:33:45 +0200
committerGitHub <noreply@github.com>2019-06-12 20:33:45 +0200
commit6ad5df4f4a2ceebcfab47f6ae86d30dcf93efd4e (patch)
tree19bef88a22a7218c5620cc0f044c094d83379d17 /searchlib/src/main
parent9423f1774e10129522a7f2cc9995bc4778ee9da0 (diff)
Revert "Require constant() for large constants and fix a type resolving bug (#9769)"
This reverts commit cee1c3a3804d5d3c25407b3c4ac64228e9d194e3.
Diffstat (limited to 'searchlib/src/main')
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/FunctionNode.java6
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java4
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java8
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/ExpressionTransformer.java2
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/TensorMaxMinTransformer.java93
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/TransformContext.java12
6 files changed, 4 insertions, 121 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/FunctionNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/FunctionNode.java
index 2aedec2109b..c4f3a75f2f8 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/FunctionNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/FunctionNode.java
@@ -5,7 +5,6 @@ import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.searchlib.rankingexpression.evaluation.Context;
import com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue;
import com.yahoo.searchlib.rankingexpression.evaluation.Value;
-import com.yahoo.searchlib.rankingexpression.transform.TensorMaxMinTransformer;
import com.yahoo.tensor.TensorType;
import com.yahoo.tensor.evaluation.TypeContext;
import com.yahoo.tensor.functions.Join;
@@ -68,11 +67,6 @@ public final class FunctionNode extends CompositeNode {
@Override
public TensorType type(TypeContext<Reference> context) {
- // Check if this node should be interpreted as tensor reduce, as this impacts the type
- ExpressionNode thisTransformed = TensorMaxMinTransformer.transformFunctionNode(this, context);
- if (thisTransformed != this)
- return thisTransformed.type(context);
-
if (arguments.expressions().size() == 0)
return TensorType.empty;
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java
index 92c6d6f8638..28dc623be72 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java
@@ -85,9 +85,7 @@ public final class IfNode extends CompositeNode {
return trueType.dimensionwiseGeneralizationWith(falseType).orElseThrow(() ->
new IllegalArgumentException("An if expression must produce compatible types in both " +
"alternatives, but the 'true' type is " + trueType + " while the " +
- "'false' type is " + falseType +
- "\n'true' branch: " + trueExpression +
- "\n'false' branch: " + falseExpression)
+ "'false' type is " + falseType)
);
}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java
index e15ce158e83..eb8d2229a6d 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ReferenceNode.java
@@ -95,13 +95,7 @@ public final class ReferenceNode extends CompositeNode {
@Override
public TensorType type(TypeContext<Reference> context) {
- TensorType type = null;
- try {
- type = context.getType(reference);
- }
- catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(reference + " is invalid", e);
- }
+ TensorType type = context.getType(reference);
if (type == null)
throw new IllegalArgumentException("Unknown feature '" + toString() + "'");
return type;
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/ExpressionTransformer.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/ExpressionTransformer.java
index 31567ba120b..22d314bcb28 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/ExpressionTransformer.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/ExpressionTransformer.java
@@ -10,7 +10,7 @@ import java.util.List;
/**
* Superclass of expression transformers. The scope (lifetime) of a transformer instance is a single compilation
- * of all the expressions in one rank profile.
+ * of alle the expressions in one rank profile.
*
* @author bratseth
*/
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/TensorMaxMinTransformer.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/TensorMaxMinTransformer.java
deleted file mode 100644
index 979c5b0f88c..00000000000
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/TensorMaxMinTransformer.java
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.rankingexpression.transform;
-
-import com.yahoo.searchlib.rankingexpression.Reference;
-import com.yahoo.searchlib.rankingexpression.rule.CompositeNode;
-import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode;
-import com.yahoo.searchlib.rankingexpression.rule.FunctionNode;
-import com.yahoo.searchlib.rankingexpression.rule.NameNode;
-import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode;
-import com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode;
-import com.yahoo.tensor.TensorType;
-import com.yahoo.tensor.evaluation.TypeContext;
-import com.yahoo.tensor.functions.Reduce;
-
-import java.util.Optional;
-
-/**
- * Transforms min(tensor,dim) and max(tensor,dim) to
- * reduce(tensor,min/max,dim). This is necessary as the backend does
- * not recognize these forms of min and max.
- *
- * @author lesters
- */
-public class TensorMaxMinTransformer<CONTEXT extends TransformContext> extends ExpressionTransformer<CONTEXT> {
-
- @Override
- public ExpressionNode transform(ExpressionNode node, CONTEXT context) {
- if (node instanceof CompositeNode) {
- node = transformChildren((CompositeNode) node, context);
- }
- if (node instanceof FunctionNode) {
- node = transformFunctionNode((FunctionNode) node, context.types());
- }
- return node;
- }
-
- public static ExpressionNode transformFunctionNode(FunctionNode node, TypeContext<Reference> context) {
- switch (node.getFunction()) {
- case min:
- case max:
- return transformMaxAndMinFunctionNode(node, context);
- }
- return node;
- }
-
- /**
- * Transforms max and min functions if the first
- * argument returns a tensor type and the second argument is a valid
- * dimension in the tensor.
- */
- private static ExpressionNode transformMaxAndMinFunctionNode(FunctionNode node, TypeContext<Reference> context) {
- if (node.children().size() != 2) {
- return node;
- }
- ExpressionNode arg1 = node.children().get(0);
- Optional<String> dimension = dimensionName(node.children().get(1));
- if (dimension.isPresent()) {
- TensorType type = arg1.type(context);
- if (type.dimension(dimension.get()).isPresent()) {
- return replaceMaxAndMinFunction(node);
- }
- }
- return node;
- }
-
- private static Optional<String> dimensionName(ExpressionNode node) {
- if (node instanceof ReferenceNode) {
- Reference reference = ((ReferenceNode)node).reference();
- if (reference.isIdentifier())
- return Optional.of(reference.name());
- else
- return Optional.empty();
- }
- else if (node instanceof NameNode) {
- return Optional.of(((NameNode)node).getValue());
- }
- else {
- return Optional.empty();
- }
- }
-
- private static 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));
- }
-
-}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/TransformContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/TransformContext.java
index 0113a650277..7485ce69f98 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/TransformContext.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/transform/TransformContext.java
@@ -1,9 +1,7 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.rankingexpression.transform;
-import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.searchlib.rankingexpression.evaluation.Value;
-import com.yahoo.tensor.evaluation.TypeContext;
import java.util.Map;
@@ -15,19 +13,11 @@ import java.util.Map;
public class TransformContext {
private final Map<String, Value> constants;
- private final TypeContext<Reference> types;
- public TransformContext(Map<String, Value> constants, TypeContext<Reference> types) {
+ public TransformContext(Map<String, Value> constants) {
this.constants = constants;
- this.types = types;
}
public Map<String, Value> constants() { return constants; }
- /**
- * Returns the types known in this context. We may have type information for references
- * for which no value is available
- */
- public TypeContext<Reference> types() { return types; }
-
}