aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/tensor
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2022-08-31 11:47:39 +0000
committerArne Juul <arnej@yahooinc.com>2022-08-31 12:27:20 +0000
commit45eda4e9feae8d045ea05f72e49021de62842e0f (patch)
tree0ead6d47b7e8b82b4bd49304b4a7964859800d43 /vespajlib/src/test/java/com/yahoo/tensor
parent6dd09abd549f28ab65bfa2ffe38f69228c3d9b12 (diff)
allow simple hex format for dense tensors of known type
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo/tensor')
-rw-r--r--vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java
index 53df95ec2e8..387cad49f5d 100644
--- a/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java
@@ -81,6 +81,47 @@ public class TensorParserTestCase {
.cell( 5.0, 2, 0, 0)
.cell(-6.0, 2, 1, 0).build(),
Tensor.from("tensor( x[3],y[2],z[1]) : [1.0, 2.0, 3.0 , 4.0, 5, -6.0]"));
+
+ var int8TT = TensorType.fromSpec("tensor<int8>(x[2],y[3])");
+
+ assertEquals("binary tensor A",
+ Tensor.Builder.of(int8TT)
+ .cell(1, 0, 0)
+ .cell(20, 0, 1)
+ .cell(127, 0, 2)
+ .cell(-1, 1, 0)
+ .cell(50, 1, 1)
+ .cell(-128, 1, 2).build(),
+ Tensor.from(int8TT, "01147FFF3280"));
+
+ assertEquals("binary tensor B",
+ Tensor.Builder.of(int8TT)
+ .cell(26.0, 0, 0)
+ .cell(0.0, 0, 1)
+ .cell(31.0, 0, 2)
+ .cell(-68.0, 1, 0)
+ .cell(-98.0, 1, 1)
+ .cell(-34.0, 1, 2).build(),
+ Tensor.from(int8TT, "1a001fbc9ede"));
+
+ assertEquals("binary tensor C",
+ Tensor.Builder.of(int8TT)
+ .cell(16, 0, 0)
+ .cell(32, 0, 1)
+ .cell(48, 0, 2)
+ .cell(-16, 1, 0)
+ .cell(-32, 1, 1)
+ .cell(-64, 1, 2).build(),
+ Tensor.from(int8TT, "102030F0E0C0"));
+
+ var floatTT = TensorType.fromSpec("tensor<float>(x[3])");
+ assertEquals("float tensor hexdump",
+ Tensor.Builder.of(floatTT)
+ .cell(0, 0)
+ .cell(1.25, 1)
+ .cell(-19.125, 2).build(),
+ Tensor.from(floatTT, "000000003FA00000c1990000"));
+
}
@Test