aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/tensor/functions
diff options
context:
space:
mode:
authorLester Solbakken <lesters@oath.com>2021-03-16 12:11:26 +0100
committerLester Solbakken <lesters@oath.com>2021-03-16 12:11:26 +0100
commita72c0d645fcf7dcf9225d9e13a16b3bc0434c6ca (patch)
treef2a58b3268c39ecd4686d2408dc09b0274c67435 /vespajlib/src/test/java/com/yahoo/tensor/functions
parentf59e36dd56d18f1148a0665823c0dfe7e40dd805 (diff)
Add Java-side tensor type cell casting
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo/tensor/functions')
-rw-r--r--vespajlib/src/test/java/com/yahoo/tensor/functions/CellCastTestCase.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/functions/CellCastTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/functions/CellCastTestCase.java
new file mode 100644
index 00000000000..bc10ecc3abd
--- /dev/null
+++ b/vespajlib/src/test/java/com/yahoo/tensor/functions/CellCastTestCase.java
@@ -0,0 +1,38 @@
+// Copyright Verizon Media. 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.Tensor;
+import com.yahoo.tensor.TensorType;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author lesters
+ */
+public class CellCastTestCase {
+
+ @Test
+ public void testCellCasting() {
+ Tensor tensor;
+
+ tensor = Tensor.from("tensor(x[3]):[1.0, 2.0, 3.0]");
+ assertEquals(TensorType.Value.DOUBLE, tensor.type().valueType());
+ assertEquals(TensorType.Value.DOUBLE, tensor.cellCast(TensorType.Value.DOUBLE).type().valueType());
+ assertEquals(TensorType.Value.FLOAT, tensor.cellCast(TensorType.Value.FLOAT).type().valueType());
+ assertEquals(tensor, tensor.cellCast(TensorType.Value.FLOAT));
+
+ tensor = Tensor.from("tensor<double>(x{}):{{x:0}:1.0,{x:1}:2.0,{x:2}:3.0}");
+ assertEquals(TensorType.Value.DOUBLE, tensor.type().valueType());
+ assertEquals(TensorType.Value.DOUBLE, tensor.cellCast(TensorType.Value.DOUBLE).type().valueType());
+ assertEquals(TensorType.Value.FLOAT, tensor.cellCast(TensorType.Value.FLOAT).type().valueType());
+ assertEquals(tensor, tensor.cellCast(TensorType.Value.FLOAT));
+
+ tensor = Tensor.from("tensor<float>(x[3],y{}):{a:[1.0, 2.0, 3.0],b:[4.0,5.0,6.0]}");
+ assertEquals(TensorType.Value.FLOAT, tensor.type().valueType());
+ assertEquals(TensorType.Value.DOUBLE, tensor.cellCast(TensorType.Value.DOUBLE).type().valueType());
+ assertEquals(TensorType.Value.FLOAT, tensor.cellCast(TensorType.Value.FLOAT).type().valueType());
+ assertEquals(tensor, tensor.cellCast(TensorType.Value.DOUBLE));
+ }
+
+}