diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-12-12 11:31:16 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-12-12 11:31:16 +0100 |
commit | b322b63d220413f92eee8f33fe01dfaf41317832 (patch) | |
tree | 3932c529f6ee00073a61e5db42b77439cc77dd9f /vespajlib | |
parent | 85ef5cbe283235dfa6720336c1f68487fcc62f0c (diff) |
MapTensor -> MappedTensor
Diffstat (limited to 'vespajlib')
19 files changed, 147 insertions, 52 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/MapTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/MappedTensor.java index 09a2ef1bc27..db1a0a0ca53 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/MapTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/MappedTensor.java @@ -12,7 +12,7 @@ import java.util.Map; * @author bratseth */ @Beta -public class MapTensor implements Tensor { +public class MappedTensor implements Tensor { private final TensorType type; @@ -20,12 +20,12 @@ public class MapTensor implements Tensor { /** Creates a sparse tensor. The cell addresses must match the type. */ // TODO: Privatize - public MapTensor(TensorType type, Map<TensorAddress, Double> cells) { + public MappedTensor(TensorType type, Map<TensorAddress, Double> cells) { this.type = type; this.cells = ImmutableMap.copyOf(cells); } - static MapTensor from(TensorType type, String tensorString) { + static MappedTensor from(TensorType type, String tensorString) { tensorString = tensorString.trim(); if ( ! tensorString.startsWith("{")) throw new IllegalArgumentException("Expecting a tensor starting by {, got '" + tensorString+ "'"); @@ -49,7 +49,7 @@ public class MapTensor implements Tensor { } ImmutableMap<TensorAddress, Double> cellMap = cells.build(); - return new MapTensor(type, cellMap); + return new MappedTensor(type, cellMap); } /** Creates a tenor address from a string on the form {dimension1:label1,dimension2:label2,...} */ @@ -116,7 +116,7 @@ public class MapTensor implements Tensor { } public Tensor build() { - return new MapTensor(type, cells.build()); + return new MappedTensor(type, cells.build()); } public class CellBuilder { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java b/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java index 107925de8c0..42df2877537 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java @@ -2,7 +2,6 @@ package com.yahoo.tensor; import com.google.common.annotations.Beta; -import com.google.common.collect.ImmutableMap; import com.yahoo.tensor.functions.ConstantTensor; import com.yahoo.tensor.functions.Generate; import com.yahoo.tensor.functions.Join; @@ -16,16 +15,12 @@ import com.yahoo.tensor.functions.Softmax; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.function.DoubleBinaryOperator; import java.util.function.DoubleUnaryOperator; import java.util.function.Function; -import static com.yahoo.tensor.TensorType.Dimension.Type.mapped; - /** * A multidimensional array which can be used in computations. * <p> @@ -229,7 +224,7 @@ public interface Tensor { if (containsIndexedDimensions && containsMappedDimensions) throw new IllegalArgumentException("Mixed dimension types are not supported, got: " + type); if (containsMappedDimensions) - return MapTensor.from(type, tensorString); + return MappedTensor.from(type, tensorString); else // indexed or none return IndexedTensor.from(type, tensorString); } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/EvaluationContext.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/EvaluationContext.java new file mode 100644 index 00000000000..de085f3951f --- /dev/null +++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/EvaluationContext.java @@ -0,0 +1,13 @@ +package com.yahoo.tensor.evaluation; + +import java.util.HashMap; + +/** + * An evaluation context which is passed down to all nested functions during evaluation. + * The default context is empty to allow various evaluation frameworks to support their own implementation. + * + * @author bratseth + */ +public interface EvaluationContext { + +} diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/FunctionOptimizer.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/FunctionOptimizer.java new file mode 100644 index 00000000000..b0d0a25f0e3 --- /dev/null +++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/FunctionOptimizer.java @@ -0,0 +1,17 @@ +package com.yahoo.tensor.evaluation; + +import com.yahoo.tensor.functions.TensorFunction; + +/** + * Optimizer of tensor functions + * + * @author bratseth + */ +public class FunctionOptimizer { + + public TensorFunction optimize(TensorFunction function) { + // TODO + return function; + } + +} diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java new file mode 100644 index 00000000000..5a7fae1b3c5 --- /dev/null +++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java @@ -0,0 +1,21 @@ +package com.yahoo.tensor.evaluation; + +import com.yahoo.tensor.Tensor; + +import java.util.HashMap; + +/** + * @author bratseth + */ +public class MapEvaluationContext implements EvaluationContext { + + private final java.util.Map<String, Tensor> bindings = new HashMap<>(); + + static MapEvaluationContext empty() { return new MapEvaluationContext(); } + + public void put(String name, Tensor tensor) { bindings.put(name, tensor); } + + /** Returns the tensor bound to this name, or null if none */ + public Tensor get(String name) { return bindings.get(name); } + +} diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java new file mode 100644 index 00000000000..2ce4707fc77 --- /dev/null +++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java @@ -0,0 +1,45 @@ +package com.yahoo.tensor.evaluation; + +import com.yahoo.tensor.Tensor; +import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.MapEvaluationContext; +import com.yahoo.tensor.functions.PrimitiveTensorFunction; +import com.yahoo.tensor.functions.TensorFunction; +import com.yahoo.tensor.functions.ToStringContext; + +import java.util.Collections; +import java.util.List; + +/** + * A tensor variable name which resolves to a tensor in the context at evaluation time + * + * @author bratseth + */ +public class VariableTensor extends PrimitiveTensorFunction { + + private final String name; + + public VariableTensor(String name) { + this.name = name; + } + + @Override + public List<TensorFunction> functionArguments() { return Collections.emptyList(); } + + @Override + public TensorFunction replaceArguments(List<TensorFunction> arguments) { return this; } + + @Override + public PrimitiveTensorFunction toPrimitive() { return this; } + + @Override + public Tensor evaluate(EvaluationContext context) { + return ((MapEvaluationContext)context).get(name); + } + + @Override + public String toString(ToStringContext context) { + return name; + } + +} diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/CompositeTensorFunction.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/CompositeTensorFunction.java index 31454e28baf..9ea1718ce18 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/CompositeTensorFunction.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/CompositeTensorFunction.java @@ -1,6 +1,7 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.Tensor; +import com.yahoo.tensor.evaluation.EvaluationContext; /** * A composite tensor function is a tensor function which can be expressed (less tersely) diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/ConstantTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/ConstantTensor.java index 22cf5820d81..03bda744bf8 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/ConstantTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/ConstantTensor.java @@ -1,7 +1,7 @@ package com.yahoo.tensor.functions; -import com.yahoo.tensor.MapTensor; import com.yahoo.tensor.Tensor; +import com.yahoo.tensor.evaluation.EvaluationContext; import java.util.Collections; import java.util.List; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/EvaluationContext.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/EvaluationContext.java deleted file mode 100644 index 24a4c61a58c..00000000000 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/EvaluationContext.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.yahoo.tensor.functions; - -/** - * An evaluation context which is passed down to all nested functions during evaluation. - * The default implementation is empty as this library does not in itself have any need for a - * context. - * - * @author bratseth - */ -public interface EvaluationContext { - - static EvaluationContext empty() { return new EvaluationContext() {}; } - -} 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 013a95fe51f..27c494f87e4 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java @@ -2,6 +2,7 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; +import com.yahoo.tensor.evaluation.EvaluationContext; import java.util.Collections; import java.util.List; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java index e439b273429..5db60fe0b80 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java @@ -3,10 +3,11 @@ package com.yahoo.tensor.functions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.yahoo.tensor.IndexedTensor; -import com.yahoo.tensor.MapTensor; +import com.yahoo.tensor.MappedTensor; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; +import com.yahoo.tensor.evaluation.EvaluationContext; import java.util.List; import java.util.Map; @@ -91,7 +92,7 @@ public class Join extends PrimitiveTensorFunction { if (bCellValue == null) continue; // no match joinedCells.put(aCell.getKey(), combinator.applyAsDouble(aCell.getValue(), bCellValue)); } - return new MapTensor(joinedType, joinedCells.build()); + return new MappedTensor(joinedType, joinedCells.build()); } /** Slow join which works for any two tensors */ @@ -107,7 +108,7 @@ public class Join extends PrimitiveTensorFunction { joinedCells.put(combinedAddress, combinator.applyAsDouble(aCell.getValue(), bCell.getValue())); } } - return new MapTensor(joinedType, joinedCells.build()); + return new MappedTensor(joinedType, joinedCells.build()); } /** diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Map.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Map.java index 3246f7c5555..3046d022695 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Map.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Map.java @@ -1,9 +1,10 @@ package com.yahoo.tensor.functions; import com.google.common.collect.ImmutableMap; -import com.yahoo.tensor.MapTensor; +import com.yahoo.tensor.MappedTensor; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; +import com.yahoo.tensor.evaluation.EvaluationContext; import java.util.Collections; import java.util.List; @@ -51,7 +52,7 @@ public class Map extends PrimitiveTensorFunction { ImmutableMap.Builder<TensorAddress, Double> mappedCells = new ImmutableMap.Builder<>(); for (java.util.Map.Entry<TensorAddress, Double> cell : argument.cells().entrySet()) mappedCells.put(cell.getKey(), mapper.applyAsDouble(cell.getValue())); - return new MapTensor(argument.type(), mappedCells.build()); + return new MappedTensor(argument.type(), mappedCells.build()); } @Override diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java index 3da236a2624..fbdc175dc60 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java @@ -3,10 +3,11 @@ package com.yahoo.tensor.functions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.yahoo.tensor.IndexedTensor; -import com.yahoo.tensor.MapTensor; +import com.yahoo.tensor.MappedTensor; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; +import com.yahoo.tensor.evaluation.EvaluationContext; import java.util.Collections; import java.util.HashMap; @@ -118,7 +119,7 @@ public class Reduce extends PrimitiveTensorFunction { ImmutableMap.Builder<TensorAddress, Double> reducedCells = new ImmutableMap.Builder<>(); for (Map.Entry<TensorAddress, ValueAggregator> aggregatingCell : aggregatingCells.entrySet()) reducedCells.put(aggregatingCell.getKey(), aggregatingCell.getValue().aggregatedValue()); - return new MapTensor(reducedType, reducedCells.build()); + return new MappedTensor(reducedType, reducedCells.build()); } private TensorAddress reduceDimensions(TensorAddress address, TensorType argumentType, TensorType reducedType) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java index 7d6dab7af7b..281d0c3cdfd 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java @@ -2,10 +2,11 @@ package com.yahoo.tensor.functions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.yahoo.tensor.MapTensor; +import com.yahoo.tensor.MappedTensor; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; +import com.yahoo.tensor.evaluation.EvaluationContext; import java.util.Collections; import java.util.HashMap; @@ -71,7 +72,7 @@ public class Rename extends PrimitiveTensorFunction { TensorAddress renamedAddress = rename(cell.getKey(), toIndexes); renamedCells.put(renamedAddress, cell.getValue()); } - return new MapTensor(renamedType, renamedCells.build()); + return new MappedTensor(renamedType, renamedCells.build()); } private TensorType rename(TensorType type, Map<String, String> fromToMap) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/TensorFunction.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/TensorFunction.java index 34ccf0704ca..193c4c90736 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/TensorFunction.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/TensorFunction.java @@ -1,6 +1,8 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.Tensor; +import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.MapEvaluationContext; import java.util.List; @@ -39,7 +41,7 @@ public abstract class TensorFunction { public abstract Tensor evaluate(EvaluationContext context); /** Evaluate with no context */ - public final Tensor evaluate() { return evaluate(EvaluationContext.empty()); } + public final Tensor evaluate() { return evaluate(new MapEvaluationContext()); } /** * Return a string representation of this context. diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java index 89104018c90..a6c2462f577 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java @@ -3,7 +3,7 @@ package com.yahoo.tensor.serialization; import com.google.common.annotations.Beta; import com.yahoo.io.GrowableByteBuffer; -import com.yahoo.tensor.MapTensor; +import com.yahoo.tensor.MappedTensor; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; @@ -61,7 +61,7 @@ class SparseBinaryFormat implements BinaryFormat { @Override public Tensor decode(GrowableByteBuffer buffer) { TensorType type = decodeDimensions(buffer); - MapTensor.Builder builder = new MapTensor.Builder(type); + MappedTensor.Builder builder = new MappedTensor.Builder(type); decodeCells(buffer, builder, type); return builder.build(); } @@ -75,16 +75,16 @@ class SparseBinaryFormat implements BinaryFormat { return builder.build(); } - private static void decodeCells(GrowableByteBuffer buffer, MapTensor.Builder builder, TensorType type) { + private static void decodeCells(GrowableByteBuffer buffer, MappedTensor.Builder builder, TensorType type) { int numCells = buffer.getInt1_4Bytes(); for (int i = 0; i < numCells; ++i) { - MapTensor.Builder.CellBuilder cellBuilder = builder.cell(); + MappedTensor.Builder.CellBuilder cellBuilder = builder.cell(); decodeAddress(buffer, cellBuilder, type); cellBuilder.value(buffer.getDouble()); } } - private static void decodeAddress(GrowableByteBuffer buffer, MapTensor.Builder.CellBuilder builder, + private static void decodeAddress(GrowableByteBuffer buffer, MappedTensor.Builder.CellBuilder builder, TensorType type) { for (TensorType.Dimension dimension : type.dimensions()) { String label = decodeString(buffer); diff --git a/vespajlib/src/test/java/com/yahoo/tensor/MapTensorBuilderTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorBuilderTestCase.java index 3704f54acec..cbbccd71f56 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/MapTensorBuilderTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorBuilderTestCase.java @@ -10,11 +10,11 @@ import static org.junit.Assert.assertTrue; /** * @author geirst */ -public class MapTensorBuilderTestCase { +public class MappedTensorBuilderTestCase { @Test public void requireThatEmptyTensorCanBeBuilt() { - Tensor tensor = new MapTensor.Builder(TensorType.empty).build(); + Tensor tensor = new MappedTensor.Builder(TensorType.empty).build(); assertEquals(0, tensor.type().dimensions().size()); assertEquals("{}", tensor.toString()); } @@ -22,7 +22,7 @@ public class MapTensorBuilderTestCase { @Test public void requireThatOneDimensionalTensorCanBeBuilt() { TensorType type = new TensorType.Builder().mapped("x").build(); - Tensor tensor = new MapTensor.Builder(type). + Tensor tensor = new MappedTensor.Builder(type). cell().label("x", "0").value(1). cell().label("x", "1").value(2).build(); assertEquals(Sets.newHashSet("x"), tensor.type().dimensionNames()); @@ -32,7 +32,7 @@ public class MapTensorBuilderTestCase { @Test public void requireThatTwoDimensionalTensorCanBeBuilt() { TensorType type = new TensorType.Builder().mapped("x").mapped("y").build(); - Tensor tensor = new MapTensor.Builder(type). + Tensor tensor = new MappedTensor.Builder(type). cell().label("x", "0").label("y", "0").value(1). cell().label("x", "1").label("y", "0").value(2).build(); assertEquals(Sets.newHashSet("x", "y"), tensor.type().dimensionNames()); diff --git a/vespajlib/src/test/java/com/yahoo/tensor/MapTensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorTestCase.java index b5d948971f4..b9bc1292e91 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/MapTensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorTestCase.java @@ -14,7 +14,7 @@ import static org.junit.Assert.fail; * * @author bratseth */ -public class MapTensorTestCase { +public class MappedTensorTestCase { @Test public void testStringForm() { diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java index 7c451faf8a5..230a9a89ba9 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java @@ -1,5 +1,8 @@ package com.yahoo.tensor; +import com.yahoo.tensor.evaluation.MapEvaluationContext; +import com.yahoo.tensor.evaluation.VariableTensor; +import com.yahoo.tensor.functions.ConstantTensor; import com.yahoo.tensor.functions.Join; import com.yahoo.tensor.functions.Reduce; import com.yahoo.tensor.functions.TensorFunction; @@ -34,10 +37,17 @@ public class TensorFunctionBenchmark { private double dotProduct(Tensor tensor, List<Tensor> tensors) { double largest = Double.MIN_VALUE; // TODO: Build function before applying, support context - // TensorFunction dotProduct = new Reduce(new Join(), Reduce.Aggregator.max); + TensorFunction dotProductFunction = new Reduce(new Join(new ConstantTensor(tensor), + new VariableTensor("argument"), (a, b) -> a * b), + Reduce.Aggregator.max).toPrimitive(); + MapEvaluationContext context = new MapEvaluationContext(); + for (Tensor tensorElement : tensors) { // tensors.size() = 1 for larger tensor - Tensor result = tensor.join(tensorElement, (a, b) -> a * b).reduce(Reduce.Aggregator.sum, "x"); - double dotProduct = result.reduce(Reduce.Aggregator.max).asDouble(); // for larger tensor + context.put("argument", tensorElement); + double dotProduct = dotProductFunction.evaluate(context).asDouble(); + // Tensor result = tensor.join(tensorElement, (a, b) -> a * b).reduce(Reduce.Aggregator.sum, "x"); + + //double dotProduct = result.reduce(Reduce.Aggregator.max).asDouble(); // for larger tensor if (dotProduct > largest) { largest = dotProduct; } @@ -52,7 +62,7 @@ public class TensorFunctionBenchmark { for (int i = 0; i < vectorCount; i++) { // TODO: Avoid this by creating a (type independent) Tensor.Builder if (dimensionType == TensorType.Dimension.Type.mapped) { - MapTensor.Builder builder = new MapTensor.Builder(type); + MappedTensor.Builder builder = new MappedTensor.Builder(type); for (int j = 0; j < vectorSize; j++) { builder.cell().label("x", String.valueOf(j)).value(random.nextDouble()); } @@ -69,13 +79,13 @@ public class TensorFunctionBenchmark { return tensors; } - private static List<Tensor> generateMatrix(int vectorCount, int vectorSize, + private static List<Tensor> generateMatrix(int vectorCount, int vectorSize, TensorType.Dimension.Type dimensionType) { List<Tensor> tensors = new ArrayList<>(); TensorType type = new TensorType.Builder().dimension("i", dimensionType).dimension("x", dimensionType).build(); // TODO: Avoid this by creating a (type independent) Tensor.Builder if (dimensionType == TensorType.Dimension.Type.mapped) { - MapTensor.Builder builder = new MapTensor.Builder(type); + MappedTensor.Builder builder = new MappedTensor.Builder(type); for (int i = 0; i < vectorCount; i++) { for (int j = 0; j < vectorSize; j++) { builder.cell() |