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