From a71001d66ada9eaf4ae89d896fea60a39ea2056b Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 4 Dec 2019 04:52:16 -0800 Subject: Propagate binding context to/from tensor functions --- .../java/com/yahoo/tensor/functions/Generate.java | 31 ++++++++++++++++++---- .../yahoo/tensor/functions/ToStringContext.java | 20 +++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) (limited to 'vespajlib') diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java index e5095178be7..ac6621ce78b 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java @@ -91,7 +91,7 @@ public class Generate extends PrimitiveTensorFunction context) { Tensor.Builder builder = Tensor.Builder.of(type); IndexedTensor.Indexes indexes = IndexedTensor.Indexes.of(dimensionSizes(type)); - GenerateContext generateContext = new GenerateContext(type, context); + GenerateEvaluationContext generateContext = new GenerateEvaluationContext(type, context); for (int i = 0; i < indexes.size(); i++) { indexes.next(); builder.cell(generateContext.apply(indexes), indexes.indexesForReading()); @@ -113,7 +113,7 @@ public class Generate extends PrimitiveTensorFunction extends PrimitiveTensorFunction { + private class GenerateEvaluationContext implements EvaluationContext { private final TensorType type; private final EvaluationContext context; private IndexedTensor.Indexes indexes; - GenerateContext(TensorType type, EvaluationContext context) { + GenerateEvaluationContext(TensorType type, EvaluationContext context) { this.type = type; this.context = context; } - @SuppressWarnings("unchecked") double apply(IndexedTensor.Indexes indexes) { if (freeGenerator != null) { return freeGenerator.apply(indexes.toList()); @@ -173,4 +172,26 @@ public class Generate extends PrimitiveTensorFunction