diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-11-27 17:55:01 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-11-27 17:55:01 +0200 |
commit | d3bb9e1b8f2b36688915fed559a1feac449216d7 (patch) | |
tree | 184df4eb34703bd0e2ff1ef7bdd8a593a555178e | |
parent | 9f1564bc8eb6568b54ed344a2c3201bfe634ac0e (diff) |
Pull name up
35 files changed, 114 insertions, 107 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/Reference.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/Reference.java index 829a796eee0..fa2d0f1ee45 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/Reference.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/Reference.java @@ -7,19 +7,18 @@ import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode; import com.yahoo.searchlib.rankingexpression.rule.NameNode; import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode; import com.yahoo.searchlib.rankingexpression.rule.SerializationContext; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.Deque; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; /** * A reference to a feature, function, or value in ranking expressions * * @author bratseth */ -public class Reference extends TypeContext.Name { +public class Reference extends Name { private final int hashCode; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/EvaluationContext.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/EvaluationContext.java index 9ec105f8174..6e6b42cc1cd 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/EvaluationContext.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/EvaluationContext.java @@ -8,7 +8,7 @@ import com.yahoo.tensor.Tensor; * * @author bratseth */ -public interface EvaluationContext<NAMETYPE extends TypeContext.Name> extends TypeContext<NAMETYPE> { +public interface EvaluationContext<NAMETYPE extends Name> extends TypeContext<NAMETYPE> { /** Returns the tensor bound to this name, or null if none */ Tensor getTensor(String name); diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java index 076c73212d1..f684987476f 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java @@ -9,7 +9,7 @@ import java.util.HashMap; /** * @author bratseth */ -public class MapEvaluationContext<NAMETYPE extends TypeContext.Name> implements EvaluationContext<NAMETYPE> { +public class MapEvaluationContext<NAMETYPE extends Name> implements EvaluationContext<NAMETYPE> { private final java.util.Map<String, Tensor> bindings = new HashMap<>(); diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/Name.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/Name.java new file mode 100644 index 00000000000..9033af1d7ec --- /dev/null +++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/Name.java @@ -0,0 +1,28 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.tensor.evaluation; + +/** A name which is just a string. Names are value objects. */ +public class Name { + + private final String name; + + public Name(String name) { + this.name = name; + } + + public String name() { return name; } + + @Override + public String toString() { return name; } + + @Override + public int hashCode() { return name.hashCode(); } + + @Override + public boolean equals(Object other) { + if (other == this) return true; + if ( ! (other instanceof Name)) return false; + return ((Name)other).name.equals(this.name); + } + +} diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/TypeContext.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/TypeContext.java index 1437fd91974..84d82b624ba 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/TypeContext.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/TypeContext.java @@ -8,7 +8,7 @@ import com.yahoo.tensor.TensorType; * * @author bratseth */ -public interface TypeContext<NAMETYPE extends TypeContext.Name> { +public interface TypeContext<NAMETYPE extends Name> { /** * Returns the type of the tensor with this name. @@ -26,31 +26,5 @@ public interface TypeContext<NAMETYPE extends TypeContext.Name> { */ TensorType getType(String name); - /** A name which is just a string. Names are value objects. */ - class Name { - - private final String name; - - public Name(String name) { - this.name = name; - } - - public String name() { return name; } - - @Override - public String toString() { return name; } - - @Override - public int hashCode() { return name.hashCode(); } - - @Override - public boolean equals(Object other) { - if (other == this) return true; - if ( ! (other instanceof Name)) return false; - return ((Name)other).name.equals(this.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 index f4e025b3843..8ea82aa4a79 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java @@ -16,7 +16,7 @@ import java.util.Optional; * * @author bratseth */ -public class VariableTensor<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFunction<NAMETYPE> { +public class VariableTensor<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE> { private final String name; private final Optional<TensorType> requiredType; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmax.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmax.java index c52e566ed1e..a365f0f4bdc 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmax.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmax.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor.functions; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.Collections; import java.util.List; @@ -9,7 +9,7 @@ import java.util.List; /** * @author bratseth */ -public class Argmax<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class Argmax<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argument; private final String dimension; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmin.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmin.java index aa0333aa421..32ccdf51336 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmin.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmin.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor.functions; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.Collections; import java.util.List; @@ -9,7 +9,7 @@ import java.util.List; /** * @author bratseth */ -public class Argmin<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class Argmin<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argument; private final String dimension; 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 59c0fae39b5..eacc4493035 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/CompositeTensorFunction.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/CompositeTensorFunction.java @@ -4,6 +4,7 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; /** @@ -12,7 +13,7 @@ import com.yahoo.tensor.evaluation.TypeContext; * * @author bratseth */ -public abstract class CompositeTensorFunction<NAMETYPE extends TypeContext.Name> extends TensorFunction<NAMETYPE> { +public abstract class CompositeTensorFunction<NAMETYPE extends Name> extends TensorFunction<NAMETYPE> { /** Finds the type this produces by first converting it to a primitive function */ @Override diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java index a31a7da67e5..fff2ddaf320 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java @@ -8,6 +8,7 @@ import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; import java.util.Arrays; @@ -23,7 +24,7 @@ import java.util.stream.Collectors; * * @author bratseth */ -public class Concat<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFunction<NAMETYPE> { +public class Concat<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argumentA, argumentB; private final String dimension; 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 9d6d488eb60..bb7481f7c64 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/ConstantTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/ConstantTensor.java @@ -4,6 +4,7 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; import java.util.Collections; @@ -14,7 +15,7 @@ import java.util.List; * * @author bratseth */ -public class ConstantTensor<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFunction<NAMETYPE> { +public class ConstantTensor<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE> { private final Tensor constant; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Diag.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Diag.java index 638a5246378..203331a1c0d 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Diag.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Diag.java @@ -2,7 +2,7 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.TensorType; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.Collections; import java.util.List; @@ -15,7 +15,7 @@ import java.util.stream.Stream; * * @author bratseth */ -public class Diag<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class Diag<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorType type; private final Function<List<Long>, Double> diagFunction; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/DynamicTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/DynamicTensor.java index 6830ec50c5f..416940a60eb 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/DynamicTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/DynamicTensor.java @@ -7,20 +7,19 @@ import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.function.Function; /** * A function which is a tensor whose values are computed by individual lambda functions on evaluation. * * @author bratseth */ -public abstract class DynamicTensor<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFunction<NAMETYPE> { +public abstract class DynamicTensor<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE> { private final TensorType type; @@ -54,16 +53,16 @@ public abstract class DynamicTensor<NAMETYPE extends TypeContext.Name> extends P abstract String contentToString(ToStringContext context); /** Creates a dynamic tensor function. The cell addresses must match the type. */ - public static <NAMETYPE extends TypeContext.Name> DynamicTensor<NAMETYPE> from(TensorType type, Map<TensorAddress, ScalarFunction<NAMETYPE>> cells) { + public static <NAMETYPE extends Name> DynamicTensor<NAMETYPE> from(TensorType type, Map<TensorAddress, ScalarFunction<NAMETYPE>> cells) { return new MappedDynamicTensor<>(type, cells); } /** Creates a dynamic tensor function for a bound, indexed tensor */ - public static <NAMETYPE extends TypeContext.Name> DynamicTensor<NAMETYPE> from(TensorType type, List<ScalarFunction<NAMETYPE>> cells) { + public static <NAMETYPE extends Name> DynamicTensor<NAMETYPE> from(TensorType type, List<ScalarFunction<NAMETYPE>> cells) { return new IndexedDynamicTensor<>(type, cells); } - private static class MappedDynamicTensor<NAMETYPE extends TypeContext.Name> extends DynamicTensor<NAMETYPE> { + private static class MappedDynamicTensor<NAMETYPE extends Name> extends DynamicTensor<NAMETYPE> { private final ImmutableMap<TensorAddress, ScalarFunction<NAMETYPE>> cells; @@ -101,7 +100,7 @@ public abstract class DynamicTensor<NAMETYPE extends TypeContext.Name> extends P } - private static class IndexedDynamicTensor<NAMETYPE extends TypeContext.Name> extends DynamicTensor<NAMETYPE> { + private static class IndexedDynamicTensor<NAMETYPE extends Name> extends DynamicTensor<NAMETYPE> { private final List<ScalarFunction<NAMETYPE>> cells; 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 aaed607aaa1..e5095178be7 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Generate.java @@ -6,6 +6,7 @@ import com.yahoo.tensor.IndexedTensor; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; import java.util.Collections; @@ -19,7 +20,7 @@ import java.util.function.Function; * * @author bratseth */ -public class Generate<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFunction<NAMETYPE> { +public class Generate<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE> { private final TensorType type; @@ -40,7 +41,7 @@ public class Generate<NAMETYPE extends TypeContext.Name> extends PrimitiveTenso * tensor cell which will receive the value * @throws IllegalArgumentException if any of the tensor dimensions are not indexed bound */ - public static <NAMETYPE extends TypeContext.Name> Generate<NAMETYPE> free(TensorType type, Function<List<Long>, Double> generator) { + public static <NAMETYPE extends Name> Generate<NAMETYPE> free(TensorType type, Function<List<Long>, Double> generator) { return new Generate<>(type, Objects.requireNonNull(generator), null); } @@ -52,7 +53,7 @@ public class Generate<NAMETYPE extends TypeContext.Name> extends PrimitiveTenso * tensor cell which will receive the value * @throws IllegalArgumentException if any of the tensor dimensions are not indexed bound */ - public static <NAMETYPE extends TypeContext.Name> Generate<NAMETYPE> bound(TensorType type, ScalarFunction<NAMETYPE> generator) { + public static <NAMETYPE extends Name> Generate<NAMETYPE> bound(TensorType type, ScalarFunction<NAMETYPE> generator) { return new Generate<>(type, null, Objects.requireNonNull(generator)); } 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 29239957260..1e0eaa7fad3 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java @@ -10,6 +10,7 @@ import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; import java.util.ArrayList; @@ -31,7 +32,7 @@ import java.util.function.DoubleBinaryOperator; * * @author bratseth */ -public class Join<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFunction<NAMETYPE> { +public class Join<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argumentA, argumentB; private final DoubleBinaryOperator combinator; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/L1Normalize.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/L1Normalize.java index 3ec7ed4ed07..ed4da6678ce 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/L1Normalize.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/L1Normalize.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor.functions; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.Collections; import java.util.List; @@ -9,7 +9,7 @@ import java.util.List; /** * @author bratseth */ -public class L1Normalize<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class L1Normalize<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argument; private final String dimension; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/L2Normalize.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/L2Normalize.java index a6b30d0b292..93b2b377176 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/L2Normalize.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/L2Normalize.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor.functions; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.Collections; import java.util.List; @@ -9,7 +9,7 @@ import java.util.List; /** * @author bratseth */ -public class L2Normalize<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class L2Normalize<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argument; private final String dimension; 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 d482c70680a..0ddf0bb4e63 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Map.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Map.java @@ -5,6 +5,7 @@ import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; import java.util.Collections; @@ -18,7 +19,7 @@ import java.util.function.DoubleUnaryOperator; * * @author bratseth */ -public class Map<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFunction<NAMETYPE> { +public class Map<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argument; private final DoubleUnaryOperator mapper; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Matmul.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Matmul.java index d32e84f1ca0..54bfdd4a732 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Matmul.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Matmul.java @@ -3,14 +3,14 @@ package com.yahoo.tensor.functions; import com.google.common.collect.ImmutableList; import com.yahoo.tensor.TensorType; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.List; /** * @author bratseth */ -public class Matmul<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class Matmul<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argument1, argument2; private final String dimension; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/PrimitiveTensorFunction.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/PrimitiveTensorFunction.java index 1113da39508..99117bb250e 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/PrimitiveTensorFunction.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/PrimitiveTensorFunction.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor.functions; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; /** * A primitive tensor function is a tensor function which cannot be expressed in terms of other tensor functions. @@ -10,6 +10,6 @@ import com.yahoo.tensor.evaluation.TypeContext; * * @author bratseth */ -public abstract class PrimitiveTensorFunction<NAMETYPE extends TypeContext.Name> extends TensorFunction<NAMETYPE> { +public abstract class PrimitiveTensorFunction<NAMETYPE extends Name> extends TensorFunction<NAMETYPE> { } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Random.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Random.java index 4ccf41de0fe..b459b1a8ddd 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Random.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Random.java @@ -2,7 +2,7 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.TensorType; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.Collections; import java.util.List; @@ -14,7 +14,7 @@ import java.util.stream.Stream; * * @author bratseth */ -public class Random<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class Random<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorType type; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Range.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Range.java index f75d0f2cbef..00d0e4b4818 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Range.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Range.java @@ -2,7 +2,7 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.TensorType; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.Collections; import java.util.List; @@ -16,7 +16,7 @@ import java.util.stream.Stream; * * @author bratseth */ -public class Range<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class Range<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorType type; private final Function<List<Long>, Double> rangeFunction; 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 1d24333623b..1eb09a603fa 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java @@ -7,6 +7,7 @@ import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; import java.util.Collections; @@ -24,7 +25,7 @@ import java.util.Set; * * @author bratseth */ -public class Reduce<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFunction<NAMETYPE> { +public class Reduce<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE> { public enum Aggregator { avg, count, prod, sum, max, min; } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/ReduceJoin.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/ReduceJoin.java index 36c20b9e044..83807a20ec9 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/ReduceJoin.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/ReduceJoin.java @@ -7,7 +7,7 @@ import com.yahoo.tensor.IndexedTensor; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.Arrays; import java.util.List; @@ -26,7 +26,7 @@ import java.util.stream.Collectors; * * @author lesters */ -public class ReduceJoin<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class ReduceJoin<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argumentA, argumentB; private final DoubleBinaryOperator combinator; 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 6731f80cbce..275b546c0aa 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java @@ -6,6 +6,7 @@ import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; import java.util.Collections; @@ -20,7 +21,7 @@ import java.util.Objects; * * @author bratseth */ -public class Rename<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFunction<NAMETYPE> { +public class Rename<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argument; private final List<String> fromDimensions; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunction.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunction.java index 70e08af16b6..07b3658fb58 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunction.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunction.java @@ -2,7 +2,7 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.evaluation.EvaluationContext; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.function.Function; @@ -11,7 +11,7 @@ import java.util.function.Function; * * @author bratseth */ -public interface ScalarFunction<NAMETYPE extends TypeContext.Name> extends Function<EvaluationContext<NAMETYPE>, Double> { +public interface ScalarFunction<NAMETYPE extends Name> extends Function<EvaluationContext<NAMETYPE>, Double> { @Override Double apply(EvaluationContext<NAMETYPE> context); diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java index 4636871e19c..755711a4d44 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java @@ -3,7 +3,7 @@ package com.yahoo.tensor.functions; import com.google.common.collect.ImmutableList; import com.yahoo.tensor.TensorType; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.Collections; import java.util.List; @@ -11,7 +11,7 @@ import java.util.List; /** * @author bratseth */ -public class Softmax<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class Softmax<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argument; private final String dimension; 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 1c52046a9be..b4c5dedbf4e 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/TensorFunction.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/TensorFunction.java @@ -5,6 +5,7 @@ import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.MapEvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; import java.util.List; @@ -16,7 +17,7 @@ import java.util.List; * * @author bratseth */ -public abstract class TensorFunction<NAMETYPE extends TypeContext.Name> { +public abstract class TensorFunction<NAMETYPE extends Name> { /** Returns the function arguments of this node in the order they are applied */ public abstract List<TensorFunction<NAMETYPE>> arguments(); diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Value.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Value.java index 0325753d2e0..cb14711c0dd 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Value.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Value.java @@ -6,6 +6,7 @@ import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; import java.util.List; @@ -19,7 +20,7 @@ import java.util.stream.Collectors; * @author bratseth */ @Beta -public class Value<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFunction<NAMETYPE> { +public class Value<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> argument; private final List<DimensionValue<NAMETYPE>> cellAddress; @@ -93,7 +94,7 @@ public class Value<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFun } } - public static class DimensionValue<NAMETYPE extends TypeContext.Name> { + public static class DimensionValue<NAMETYPE extends Name> { private final Optional<String> dimension; @@ -166,7 +167,7 @@ public class Value<NAMETYPE extends TypeContext.Name> extends PrimitiveTensorFun } - private static class ConstantScalarFunction<NAMETYPE extends TypeContext.Name> implements ScalarFunction<NAMETYPE> { + private static class ConstantScalarFunction<NAMETYPE extends Name> implements ScalarFunction<NAMETYPE> { private final Double value; diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/XwPlusB.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/XwPlusB.java index 60b4438e909..53e23674617 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/XwPlusB.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/XwPlusB.java @@ -2,14 +2,14 @@ package com.yahoo.tensor.functions; import com.google.common.collect.ImmutableList; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import java.util.List; /** * @author bratseth */ -public class XwPlusB<NAMETYPE extends TypeContext.Name> extends CompositeTensorFunction<NAMETYPE> { +public class XwPlusB<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE> { private final TensorFunction<NAMETYPE> x, w, b; private final String dimension; diff --git a/vespajlib/src/test/java/com/yahoo/tensor/MatrixDotProductBenchmark.java b/vespajlib/src/test/java/com/yahoo/tensor/MatrixDotProductBenchmark.java index 9c4fa0cf931..c334c58042c 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/MatrixDotProductBenchmark.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/MatrixDotProductBenchmark.java @@ -2,18 +2,16 @@ package com.yahoo.tensor; import com.yahoo.tensor.evaluation.MapEvaluationContext; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; 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; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; -import java.util.stream.Collectors; /** * Microbenchmark of a "dot product" of two mapped rank 2 tensors @@ -43,10 +41,10 @@ public class MatrixDotProductBenchmark { private double dotProduct(Tensor tensor, List<Tensor> tensors) { double largest = Double.MIN_VALUE; - TensorFunction<TypeContext.Name> dotProductFunction = new Reduce<>(new Join<>(new ConstantTensor<>(tensor), - new VariableTensor<>("argument"), (a, b) -> a * b), - Reduce.Aggregator.sum).toPrimitive(); - MapEvaluationContext<TypeContext.Name> context = new MapEvaluationContext<>(); + TensorFunction<Name> dotProductFunction = new Reduce<>(new Join<>(new ConstantTensor<>(tensor), + new VariableTensor<>("argument"), (a, b) -> a * b), + Reduce.Aggregator.sum).toPrimitive(); + MapEvaluationContext<Name> context = new MapEvaluationContext<>(); for (Tensor tensorElement : tensors) { // tensors.size() = 1 for larger tensor context.put("argument", tensorElement); diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java index 3c07dd9e6d4..b3c6fbc6862 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorFunctionBenchmark.java @@ -2,7 +2,7 @@ package com.yahoo.tensor; import com.yahoo.tensor.evaluation.MapEvaluationContext; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.VariableTensor; import com.yahoo.tensor.functions.ConstantTensor; import com.yahoo.tensor.functions.Join; @@ -50,10 +50,10 @@ public class TensorFunctionBenchmark { private double dotProduct(Tensor tensor, List<Tensor> tensors) { double largest = Double.MIN_VALUE; - TensorFunction<TypeContext.Name> dotProductFunction = new Reduce<>(new Join<>(new ConstantTensor<>(tensor), - new VariableTensor<>("argument"), (a, b) -> a * b), - Reduce.Aggregator.sum).toPrimitive(); - MapEvaluationContext<TypeContext.Name> context = new MapEvaluationContext<>(); + TensorFunction<Name> dotProductFunction = new Reduce<>(new Join<>(new ConstantTensor<>(tensor), + new VariableTensor<>("argument"), (a, b) -> a * b), + Reduce.Aggregator.sum).toPrimitive(); + MapEvaluationContext<Name> context = new MapEvaluationContext<>(); for (Tensor tensorElement : tensors) { // tensors.size() = 1 for larger tensor context.put("argument", tensorElement); diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java index ae73770b7f7..11365531019 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java @@ -3,7 +3,7 @@ package com.yahoo.tensor; import com.google.common.collect.ImmutableList; import com.yahoo.tensor.evaluation.MapEvaluationContext; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.VariableTensor; import com.yahoo.tensor.functions.ConstantTensor; import com.yahoo.tensor.functions.Join; @@ -308,10 +308,10 @@ public class TensorTestCase { private double dotProduct(Tensor tensor, List<Tensor> tensors) { double sum = 0; - TensorFunction<TypeContext.Name> dotProductFunction = new Reduce<>(new Join<>(new ConstantTensor<>(tensor), - new VariableTensor<>("argument"), (a, b) -> a * b), - Reduce.Aggregator.sum).toPrimitive(); - MapEvaluationContext<TypeContext.Name> context = new MapEvaluationContext<>(); + TensorFunction<Name> dotProductFunction = new Reduce<>(new Join<>(new ConstantTensor<>(tensor), + new VariableTensor<>("argument"), (a, b) -> a * b), + Reduce.Aggregator.sum).toPrimitive(); + MapEvaluationContext<Name> context = new MapEvaluationContext<>(); for (Tensor tensorElement : tensors) { // tensors.size() = 1 for larger tensor context.put("argument", tensorElement); diff --git a/vespajlib/src/test/java/com/yahoo/tensor/functions/DynamicTensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/functions/DynamicTensorTestCase.java index 0f8fbade910..e16b7b90a1d 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/functions/DynamicTensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/functions/DynamicTensorTestCase.java @@ -5,12 +5,11 @@ import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.EvaluationContext; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import org.junit.Test; import java.util.Collections; import java.util.List; -import java.util.function.Function; import static org.junit.Assert.assertEquals; @@ -22,27 +21,27 @@ public class DynamicTensorTestCase { @Test public void testDynamicTensorFunction() { TensorType dense = TensorType.fromSpec("tensor(x[3])"); - DynamicTensor<TypeContext.Name> t1 = DynamicTensor.from(dense, - List.of(new Constant(1), new Constant(2), new Constant(3))); + DynamicTensor<Name> t1 = DynamicTensor.from(dense, + List.of(new Constant(1), new Constant(2), new Constant(3))); assertEquals(Tensor.from(dense, "[1, 2, 3]"), t1.evaluate()); assertEquals("tensor(x[3]):{{x:0}:1.0,{x:1}:2.0,{x:2}:3.0}", t1.toString()); TensorType sparse = TensorType.fromSpec("tensor(x{})"); - DynamicTensor<TypeContext.Name> t2 = DynamicTensor.from(sparse, - Collections.singletonMap(new TensorAddress.Builder(sparse).add("x", "a").build(), + DynamicTensor<Name> t2 = DynamicTensor.from(sparse, + Collections.singletonMap(new TensorAddress.Builder(sparse).add("x", "a").build(), new Constant(5))); assertEquals(Tensor.from(sparse, "{{x:a}:5}"), t2.evaluate()); assertEquals("tensor(x{}):{{x:a}:5.0}", t2.toString()); } - private static class Constant implements ScalarFunction<TypeContext.Name> { + private static class Constant implements ScalarFunction<Name> { private final double value; public Constant(double value) { this.value = value; } @Override - public Double apply(EvaluationContext<TypeContext.Name> evaluationContext) { return value; } + public Double apply(EvaluationContext<Name> evaluationContext) { return value; } @Override public String toString() { return String.valueOf(value); } diff --git a/vespajlib/src/test/java/com/yahoo/tensor/functions/TensorFunctionTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/functions/TensorFunctionTestCase.java index ff035f3aed2..e6560242d5c 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/functions/TensorFunctionTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/functions/TensorFunctionTestCase.java @@ -2,7 +2,7 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.TensorType; -import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.evaluation.Name; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -23,7 +23,7 @@ public class TensorFunctionTestCase { new Argmax<>(new ConstantTensor<>("{ {x:1}:1, {x:3}:5, {x:9}:3 }"), "x")); } - private void assertTranslated(String expectedTranslation, TensorFunction<TypeContext.Name> inputFunction) { + private void assertTranslated(String expectedTranslation, TensorFunction<Name> inputFunction) { assertEquals(expectedTranslation, inputFunction.toPrimitive().toString()); } |