diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-12-21 14:25:01 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-12-21 14:25:01 +0100 |
commit | ed8ec5305f6838e31de94ef87ddd3a75390b59ed (patch) | |
tree | 6266387837bafdc29713b1a9605919b59fd86079 /vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java | |
parent | b56911f909e6ca68fa0a02cf5932d422a61a9f49 (diff) |
- Tensor generate implementation
- Cross tensor implementation equals
- Better iteration
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java | 18 |
1 files changed, 16 insertions, 2 deletions
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 508e322c3a1..9c92ca00eac 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java @@ -1,6 +1,7 @@ package com.yahoo.tensor.functions; import com.google.common.annotations.Beta; +import com.yahoo.tensor.IndexedTensor; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; @@ -58,9 +59,22 @@ public class Generate extends PrimitiveTensorFunction { @Override public Tensor evaluate(EvaluationContext context) { - throw new UnsupportedOperationException("Not implemented"); // TODO + Tensor.Builder builder = Tensor.Builder.of(type); + IndexedTensor.Indexes indexes = IndexedTensor.Indexes.of(dimensionSizes(type)); + for (int i = 0; i < indexes.size(); i++) { + indexes.next(); + builder.cell(generator.apply(indexes.toList()), indexes.indexesForReading()); + } + return builder.build(); } - + + private int[] dimensionSizes(TensorType type) { + int dimensionSizes[] = new int[type.dimensions().size()]; + for (int i = 0; i < dimensionSizes.length; i++) + dimensionSizes[i] = type.dimensions().get(i).size().get(); + return dimensionSizes; + } + @Override public String toString(ToStringContext context) { return type + "(" + generator + ")"; } |