summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLester Solbakken <lesters@oath.com>2019-02-20 16:09:16 +0100
committerLester Solbakken <lesters@oath.com>2019-02-20 16:09:16 +0100
commit5d0bff5230d3d8a304f786cbcc3c486ee9f941bb (patch)
treeebca6996f13ea1e197556abddc9119f3722c8bbd
parentb7dd335bdaeb889bca08daf8c79a47eb3d62c732 (diff)
Don't convert tensor add update type to sparse dimensions
-rw-r--r--document/abi-spec.json2
-rw-r--r--document/src/main/java/com/yahoo/document/json/readers/TensorAddUpdateReader.java9
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java4
-rw-r--r--document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java8
-rw-r--r--document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java6
-rw-r--r--document/src/test/java/com/yahoo/document/update/TensorAddUpdateTest.java45
6 files changed, 37 insertions, 37 deletions
diff --git a/document/abi-spec.json b/document/abi-spec.json
index 61390af3523..f100178ee16 100644
--- a/document/abi-spec.json
+++ b/document/abi-spec.json
@@ -5244,7 +5244,7 @@
],
"methods": [
"public void <init>(com.yahoo.document.update.TensorModifyUpdate$Operation, com.yahoo.document.datatypes.TensorFieldValue)",
- "public static com.yahoo.tensor.TensorType convertToCompatibleType(com.yahoo.tensor.TensorType)",
+ "public static com.yahoo.tensor.TensorType convertDimensionsToMapped(com.yahoo.tensor.TensorType)",
"public com.yahoo.document.update.TensorModifyUpdate$Operation getOperation()",
"public com.yahoo.document.datatypes.TensorFieldValue getValue()",
"public void setValue(com.yahoo.document.datatypes.TensorFieldValue)",
diff --git a/document/src/main/java/com/yahoo/document/json/readers/TensorAddUpdateReader.java b/document/src/main/java/com/yahoo/document/json/readers/TensorAddUpdateReader.java
index d01b54328cf..5ed4455435a 100644
--- a/document/src/main/java/com/yahoo/document/json/readers/TensorAddUpdateReader.java
+++ b/document/src/main/java/com/yahoo/document/json/readers/TensorAddUpdateReader.java
@@ -6,12 +6,10 @@ import com.yahoo.document.TensorDataType;
import com.yahoo.document.datatypes.TensorFieldValue;
import com.yahoo.document.json.TokenBuffer;
import com.yahoo.document.update.TensorAddUpdate;
-import com.yahoo.document.update.TensorModifyUpdate;
import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.TensorType;
import static com.yahoo.document.json.readers.JsonParserHelpers.expectObjectStart;
-import static com.yahoo.document.json.readers.TensorModifyUpdateReader.validateBounds;
import static com.yahoo.document.json.readers.TensorReader.fillTensor;
/**
@@ -27,15 +25,12 @@ public class TensorAddUpdateReader {
expectObjectStart(buffer.currentToken());
expectTensorTypeHasSparseDimensions(field);
- // Convert update type to only have mapped dimensions - to avoid spanning out dense subspace
TensorDataType tensorDataType = (TensorDataType)field.getDataType();
- TensorType originalType = tensorDataType.getTensorType();
- TensorType convertedType = TensorModifyUpdate.convertDimensionsToMapped(originalType);
+ TensorType tensorType = tensorDataType.getTensorType();
- TensorFieldValue tensorFieldValue = new TensorFieldValue(convertedType);
+ TensorFieldValue tensorFieldValue = new TensorFieldValue(tensorType);
fillTensor(buffer, tensorFieldValue);
expectTensorIsNonEmpty(field, tensorFieldValue.getTensor().get());
- validateBounds(tensorFieldValue.getTensor().get(), originalType);
return new TensorAddUpdate(tensorFieldValue);
}
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java
index 65025fada8f..fb252b1a30a 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java
@@ -51,9 +51,7 @@ public class VespaDocumentDeserializerHead extends VespaDocumentDeserializer6 {
}
TensorDataType tensorDataType = (TensorDataType)type;
TensorType tensorType = tensorDataType.getTensorType();
- TensorType convertedType = TensorModifyUpdate.convertDimensionsToMapped(tensorType);
-
- TensorFieldValue tensor = new TensorFieldValue(convertedType);
+ TensorFieldValue tensor = new TensorFieldValue(tensorType);
tensor.deserialize(this);
return new TensorAddUpdate(tensor);
}
diff --git a/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java b/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java
index 0cc821680b2..454ad72f344 100644
--- a/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java
+++ b/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java
@@ -385,8 +385,12 @@ public class DocumentUpdateJsonSerializerTest {
" 'mixed_tensor': {",
" 'add': {",
" 'cells': [",
- " { 'address': { 'x': '0', 'y': '0' }, 'value': 2.0 },",
- " { 'address': { 'x': '1', 'y': '2' }, 'value': 3.0 }",
+ " { 'address': { 'x': '1', 'y': '0' }, 'value': 2.0 },",
+ " { 'address': { 'x': '1', 'y': '1' }, 'value': 0.0 },",
+ " { 'address': { 'x': '1', 'y': '2' }, 'value': 0.0 },",
+ " { 'address': { 'x': '0', 'y': '0' }, 'value': 0.0 },",
+ " { 'address': { 'x': '0', 'y': '1' }, 'value': 0.0 },",
+ " { 'address': { 'x': '0', 'y': '2' }, 'value': 3.0 }",
" ]",
" }",
" }",
diff --git a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
index 4bff6f44188..15d1e859f73 100644
--- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
+++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
@@ -1479,7 +1479,7 @@ public class JsonReaderTestCase {
@Test
public void tensor_add_update_on_mixed_tensor() {
- assertTensorAddUpdate("{{x:a,y:0}:2.0, {x:a,y:1}:3.0}", "mixed_tensor",
+ assertTensorAddUpdate("{{x:a,y:0}:2.0, {x:a,y:1}:3.0, {x:a,y:2}:0.0}", "mixed_tensor",
inputJson("{",
" 'cells': [",
" { 'address': { 'x': 'a', 'y': '0' }, 'value': 2.0 },",
@@ -1487,9 +1487,9 @@ public class JsonReaderTestCase {
}
@Test
- public void tensor_add_update_with_out_of_bound_dense_cells_throws() {
+ public void tensor_add_update_on_mixed_with_out_of_bound_dense_cells_throws() {
exception.expect(IndexOutOfBoundsException.class);
- exception.expectMessage("Dimension 'y' has label '3' but type is tensor(x{},y[3])");
+ exception.expectMessage("Index 3 out of bounds for length 3");
createTensorAddUpdate(inputJson("{",
" 'cells': [",
" { 'address': { 'x': '0', 'y': '3' }, 'value': 2.0 } ]}"), "mixed_tensor");
diff --git a/document/src/test/java/com/yahoo/document/update/TensorAddUpdateTest.java b/document/src/test/java/com/yahoo/document/update/TensorAddUpdateTest.java
index c6b21380e4b..288bd112cd6 100644
--- a/document/src/test/java/com/yahoo/document/update/TensorAddUpdateTest.java
+++ b/document/src/test/java/com/yahoo/document/update/TensorAddUpdateTest.java
@@ -3,40 +3,43 @@ package com.yahoo.document.update;
import com.yahoo.document.datatypes.TensorFieldValue;
import com.yahoo.tensor.Tensor;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
public class TensorAddUpdateTest {
- @Rule
- public ExpectedException exception = ExpectedException.none();
+ @Test
+ public void apply_add_update_operations_sparse() {
+ assertSparseApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:2}:3}", "{{x:0,y:0}:1,{x:0,y:1}:2,{x:0,y:2}:3}");
+ assertSparseApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3}", "{{x:0,y:0}:1,{x:0,y:1}:3}");
+ assertSparseApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3,{x:0,y:2}:4}", "{{x:0,y:0}:1,{x:0,y:1}:3,{x:0,y:2}:4}");
+ assertSparseApplyTo("{}", "{{x:0,y:0}:5}", "{{x:0,y:0}:5}");
+ assertSparseApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{}", "{{x:0,y:0}:1, {x:0,y:1}:2}");
+ }
@Test
- public void apply_add_update_operations() {
- assertApplyTo("tensor(x{},y{})", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:2}:3}", "{{x:0,y:0}:1,{x:0,y:1}:2,{x:0,y:2}:3}");
- assertApplyTo("tensor(x{},y{})", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3}", "{{x:0,y:0}:1,{x:0,y:1}:3}");
- assertApplyTo("tensor(x{},y{})", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3,{x:0,y:2}:4}", "{{x:0,y:0}:1,{x:0,y:1}:3,{x:0,y:2}:4}");
- assertApplyTo("tensor(x{},y{})", "{}", "{{x:0,y:0}:5}", "{{x:0,y:0}:5}");
- assertApplyTo("tensor(x{},y{})", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{}", "{{x:0,y:0}:1, {x:0,y:1}:2}");
-
- assertApplyTo("tensor(x{},y[3])", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:2}:3}", "{{x:0,y:0}:1,{x:0,y:1}:2,{x:0,y:2}:3}");
- assertApplyTo("tensor(x{},y[3])", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3}", "{{x:0,y:0}:1,{x:0,y:1}:3,{x:0,y:2}:0}");
- assertApplyTo("tensor(x{},y[3])", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3,{x:0,y:2}:4}", "{{x:0,y:0}:1,{x:0,y:1}:3,{x:0,y:2}:4}");
- assertApplyTo("tensor(x{},y[3])", "{}", "{{x:0,y:0}:5}", "{{x:0,y:0}:5,{x:0,y:1}:0,{x:0,y:2}:0}");
- assertApplyTo("tensor(x{},y[3])", "{{x:0,y:0}:1, {x:0,y:1}:2}", "{}", "{{x:0,y:0}:1,{x:0,y:1}:2,{x:0,y:2}:0}");
+ public void apply_add_update_operations_mixed() {
+ assertMixedApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:2}:3}", "{{x:0,y:0}:0,{x:0,y:1}:0,{x:0,y:2}:3}");
+ assertMixedApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3}", "{{x:0,y:0}:0,{x:0,y:1}:3,{x:0,y:2}:0}");
+ assertMixedApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{{x:0,y:1}:3,{x:0,y:2}:4}", "{{x:0,y:0}:0,{x:0,y:1}:3,{x:0,y:2}:4}");
+ assertMixedApplyTo("{}", "{{x:0,y:0}:5}", "{{x:0,y:0}:5,{x:0,y:1}:0,{x:0,y:2}:0}");
+ assertMixedApplyTo("{{x:0,y:0}:1, {x:0,y:1}:2}", "{}", "{{x:0,y:0}:1,{x:0,y:1}:2,{x:0,y:2}:0}");
}
- private Tensor updateField(String spec, String init, String update) {
- TensorFieldValue initialFieldValue = new TensorFieldValue(Tensor.from(spec, init));
- TensorAddUpdate addUpdate = new TensorAddUpdate(new TensorFieldValue(Tensor.from("tensor(x{},y{})", update)));
- return ((TensorFieldValue) addUpdate.applyTo(initialFieldValue)).getTensor().get();
+ private void assertSparseApplyTo(String init, String update, String expected) {
+ assertApplyTo("tensor(x{},y{})", init, update, expected);
+ }
+
+ private void assertMixedApplyTo(String init, String update, String expected) {
+ assertApplyTo("tensor(x{},y[3])", init, update, expected);
}
private void assertApplyTo(String spec, String init, String update, String expected) {
- assertEquals(Tensor.from(spec, expected), updateField(spec, init, update));
+ TensorFieldValue initialFieldValue = new TensorFieldValue(Tensor.from(spec, init));
+ TensorAddUpdate addUpdate = new TensorAddUpdate(new TensorFieldValue(Tensor.from(spec, update)));
+ Tensor updated = ((TensorFieldValue) addUpdate.applyTo(initialFieldValue)).getTensor().get();
+ assertEquals(Tensor.from(spec, expected), updated);
}
}