Search in sources :

Example 1 with VariableTensor

use of com.yahoo.tensor.evaluation.VariableTensor 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 2 with VariableTensor

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

the class Placeholder method lazyGetFunction.

@Override
protected TensorFunction lazyGetFunction() {
    TensorFunction output = new VariableTensor(vespaName(), standardNamingType.type());
    if (!standardNamingType.equals(type)) {
        List<String> renameFrom = standardNamingType.dimensionNames();
        List<String> renameTo = type.dimensionNames();
        output = new Rename(output, renameFrom, renameTo);
    }
    return output;
}
Also used : VariableTensor(com.yahoo.tensor.evaluation.VariableTensor) TensorFunction(com.yahoo.tensor.functions.TensorFunction) Rename(com.yahoo.tensor.functions.Rename)

Example 3 with VariableTensor

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

the class TensorFunctionBenchmark method dotProduct.

private double dotProduct(Tensor tensor, List<Tensor> tensors) {
    double largest = Double.MIN_VALUE;
    TensorFunction dotProductFunction = new Reduce(new Join(new ConstantTensor(tensor), new VariableTensor("argument"), (a, b) -> a * b), Reduce.Aggregator.sum).toPrimitive();
    MapEvaluationContext context = new MapEvaluationContext();
    for (Tensor tensorElement : tensors) {
        // tensors.size() = 1 for larger tensor
        context.put("argument", tensorElement);
        double dotProduct = dotProductFunction.evaluate(context).asDouble();
        if (dotProduct > largest) {
            largest = dotProduct;
        }
    }
    return largest;
}
Also used : VariableTensor(com.yahoo.tensor.evaluation.VariableTensor) ConstantTensor(com.yahoo.tensor.functions.ConstantTensor) VariableTensor(com.yahoo.tensor.evaluation.VariableTensor) TensorFunction(com.yahoo.tensor.functions.TensorFunction) Join(com.yahoo.tensor.functions.Join) Reduce(com.yahoo.tensor.functions.Reduce) ConstantTensor(com.yahoo.tensor.functions.ConstantTensor) MapEvaluationContext(com.yahoo.tensor.evaluation.MapEvaluationContext)

Example 4 with VariableTensor

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

the class TensorTestCase method dotProduct.

private double dotProduct(Tensor tensor, List<Tensor> tensors) {
    double sum = 0;
    TensorFunction dotProductFunction = new Reduce(new Join(new ConstantTensor(tensor), new VariableTensor("argument"), (a, b) -> a * b), Reduce.Aggregator.sum).toPrimitive();
    MapEvaluationContext context = new MapEvaluationContext();
    for (Tensor tensorElement : tensors) {
        // tensors.size() = 1 for larger tensor
        context.put("argument", tensorElement);
        // System.out.println("Dot product of " + tensor + " and " + tensorElement + ": " + dotProductFunction.evaluate(context).asDouble());
        sum += dotProductFunction.evaluate(context).asDouble();
    }
    return sum;
}
Also used : VariableTensor(com.yahoo.tensor.evaluation.VariableTensor) ConstantTensor(com.yahoo.tensor.functions.ConstantTensor) VariableTensor(com.yahoo.tensor.evaluation.VariableTensor) TensorFunction(com.yahoo.tensor.functions.TensorFunction) Join(com.yahoo.tensor.functions.Join) Reduce(com.yahoo.tensor.functions.Reduce) ConstantTensor(com.yahoo.tensor.functions.ConstantTensor) MapEvaluationContext(com.yahoo.tensor.evaluation.MapEvaluationContext)

Aggregations

VariableTensor (com.yahoo.tensor.evaluation.VariableTensor)4 TensorFunction (com.yahoo.tensor.functions.TensorFunction)3 MapEvaluationContext (com.yahoo.tensor.evaluation.MapEvaluationContext)2 ConstantTensor (com.yahoo.tensor.functions.ConstantTensor)2 Join (com.yahoo.tensor.functions.Join)2 Reduce (com.yahoo.tensor.functions.Reduce)2 ExpressionNode (com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)1 ReferenceNode (com.yahoo.searchlib.rankingexpression.rule.ReferenceNode)1 TensorFunctionNode (com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode)1 Rename (com.yahoo.tensor.functions.Rename)1