Search in sources :

Example 21 with TensorType

use of com.yahoo.tensor.TensorType in project vespa by vespa-engine.

the class TensorTransformer method transformMaxAndMinFunctionNode.

/**
 * 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 ExpressionNode transformMaxAndMinFunctionNode(FunctionNode node, RankProfileTransformContext 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.rankProfile().typeContext(context.queryProfiles()));
        if (type.dimension(dimension.get()).isPresent()) {
            return replaceMaxAndMinFunction(node);
        }
    }
    return node;
}
Also used : ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) TensorType(com.yahoo.tensor.TensorType)

Example 22 with TensorType

use of com.yahoo.tensor.TensorType in project vespa by vespa-engine.

the class RankFeaturesTestCase method requireThatSingleTensorIsBinaryEncoded.

@Test
public void requireThatSingleTensorIsBinaryEncoded() {
    TensorType type = new TensorType.Builder().mapped("x").mapped("y").mapped("z").build();
    Tensor tensor = Tensor.from(type, "{ {x:a, y:b, z:c}:2.0, {x:a, y:b, z:c2}:3.0 }");
    assertTensorEncodingAndDecoding(type, "query(my_tensor)", "my_tensor", tensor);
    assertTensorEncodingAndDecoding(type, "$my_tensor", "my_tensor", tensor);
}
Also used : Tensor(com.yahoo.tensor.Tensor) TensorType(com.yahoo.tensor.TensorType) Test(org.junit.Test)

Example 23 with TensorType

use of com.yahoo.tensor.TensorType in project vespa by vespa-engine.

the class RankFeaturesTestCase method requireThatMultipleTensorsAreBinaryEncoded.

@Test
public void requireThatMultipleTensorsAreBinaryEncoded() {
    TensorType type = new TensorType.Builder().mapped("x").mapped("y").mapped("z").build();
    Tensor tensor1 = Tensor.from(type, "{ {x:a, y:b, z:c}:2.0, {x:a, y:b, z:c2}:3.0 }");
    Tensor tensor2 = Tensor.from(type, "{ {x:a, y:b, z:c}:5.0 }");
    assertTensorEncodingAndDecoding(type, Arrays.asList(new Entry("query(tensor1)", "tensor1", tensor1), new Entry("$tensor2", "tensor2", tensor2)));
}
Also used : Tensor(com.yahoo.tensor.Tensor) TensorType(com.yahoo.tensor.TensorType) Test(org.junit.Test)

Example 24 with TensorType

use of com.yahoo.tensor.TensorType 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);
}
Also used : ArithmeticNode(com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode) ConstantNode(com.yahoo.searchlib.rankingexpression.rule.ConstantNode) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) ArrayList(java.util.ArrayList) ArithmeticOperator(com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator) OrderedTensorType(com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType) TensorType(com.yahoo.tensor.TensorType)

Example 25 with TensorType

use of com.yahoo.tensor.TensorType in project vespa by vespa-engine.

the class FunctionNode method type.

@Override
public TensorType type(TypeContext<Reference> context) {
    if (arguments.expressions().size() == 0)
        return TensorType.empty;
    TensorType argument1Type = arguments.expressions().get(0).type(context);
    if (arguments.expressions().size() == 1)
        return argument1Type;
    TensorType argument2Type = arguments.expressions().get(1).type(context);
    return Join.outputType(argument1Type, argument2Type);
}
Also used : TensorType(com.yahoo.tensor.TensorType)

Aggregations

TensorType (com.yahoo.tensor.TensorType)38 Tensor (com.yahoo.tensor.Tensor)18 ExpressionNode (com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)8 IndexedTensor (com.yahoo.tensor.IndexedTensor)7 MixedTensor (com.yahoo.tensor.MixedTensor)6 TensorAddress (com.yahoo.tensor.TensorAddress)6 Test (org.junit.Test)6 DoubleValue (com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue)4 OrderedTensorType (com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType)4 ConstantNode (com.yahoo.searchlib.rankingexpression.rule.ConstantNode)4 GeneratorLambdaFunctionNode (com.yahoo.searchlib.rankingexpression.rule.GeneratorLambdaFunctionNode)4 Generate (com.yahoo.tensor.functions.Generate)4 List (java.util.List)4 ImmutableList (com.google.common.collect.ImmutableList)3 RankProfile (com.yahoo.searchdefinition.RankProfile)3 RankingExpression (com.yahoo.searchlib.rankingexpression.RankingExpression)3 DimensionSizes (com.yahoo.tensor.DimensionSizes)3 Reduce (com.yahoo.tensor.functions.Reduce)3 TensorFunction (com.yahoo.tensor.functions.TensorFunction)3 ArrayList (java.util.ArrayList)3