From 8c23296c0feb1c418706f847c7b78ae926180859 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 3 Apr 2019 22:41:18 +0200 Subject: Infer value type --- vespajlib/abi-spec.json | 1 - vespajlib/src/main/java/com/yahoo/tensor/TensorType.java | 12 ++++++------ .../src/main/java/com/yahoo/tensor/functions/Concat.java | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'vespajlib') diff --git a/vespajlib/abi-spec.json b/vespajlib/abi-spec.json index b071566ae31..43388e4e18d 100644 --- a/vespajlib/abi-spec.json +++ b/vespajlib/abi-spec.json @@ -1164,7 +1164,6 @@ "public void ()", "public void (com.yahoo.tensor.TensorType$Value)", "public varargs void (com.yahoo.tensor.TensorType[])", - "public varargs void (com.yahoo.tensor.TensorType$Value, com.yahoo.tensor.TensorType[])", "public void (java.lang.Iterable)", "public void (com.yahoo.tensor.TensorType$Value, java.lang.Iterable)", "public int rank()", diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java index aaa25a0b058..df78f3dfc3a 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java @@ -4,6 +4,7 @@ package com.yahoo.tensor; import com.google.common.collect.ImmutableList; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; @@ -410,7 +411,7 @@ public class TensorType { private final Value valueType; - /** Creates an empty builder with cells of type double*/ + /** Creates an empty builder with cells of type double */ public Builder() { this(Value.DOUBLE); } @@ -425,17 +426,16 @@ public class TensorType { * If the same dimension is indexed with different size restrictions the largest size will be used. * If it is size restricted in one argument but not the other it will not be size restricted. * If it is indexed in one and mapped in the other it will become mapped. + * + * The value type will be the largest of the value types of the input types */ public Builder(TensorType ... types) { - this(Value.DOUBLE, types); - } - public Builder(Value valueType, TensorType ... types) { - this.valueType = valueType; + this.valueType = TensorType.Value.largestOf(Arrays.stream(types).map(type -> type.valueType()).collect(Collectors.toList())); for (TensorType type : types) addDimensionsOf(type); } - /** Creates a builder from the given dimensions */ + /** Creates a builder from the given dimensions, having double as the value type */ public Builder(Iterable dimensions) { this(Value.DOUBLE, dimensions); } 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 a0a257bb909..a48ac19fbff 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java @@ -73,8 +73,8 @@ public class Concat extends PrimitiveTensorFunction { MutableLong concatSize = new MutableLong(0); a.sizeOfDimension(dimension).ifPresent(concatSize::add); b.sizeOfDimension(dimension).ifPresent(concatSize::add); - builder.set(TensorType.Dimension.indexed(dimension, concatSize.get())); - */ + builder.set(TensorType.Dimension.indexed(dimension, concatSize.get())); + */ } return builder.build(); } -- cgit v1.2.3