diff options
author | Lester Solbakken <lesters@oath.com> | 2021-08-31 14:40:50 +0200 |
---|---|---|
committer | Lester Solbakken <lesters@oath.com> | 2021-08-31 14:40:50 +0200 |
commit | 522578bb7392c95ac0c8ef2b599f65d6d79df987 (patch) | |
tree | 6da6b89b6a2ec1a06afed512c8498f16033b7001 /vespajlib/src/test | |
parent | 28ed1156289bdb5d6e874c3a84a86f46789dd440 (diff) |
Parse unbound tensors in short form
Diffstat (limited to 'vespajlib/src/test')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java | 47 |
1 files changed, 47 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 431e4b06263..b869107e744 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorParserTestCase.java @@ -150,6 +150,53 @@ public class TensorParserTestCase { Tensor.from("tensor(key{},y[2],x[3]):{key1:[[1,2,3],[4,5,6]], key2:[[7,8,9],[10,11,12]]}")); } + @Test + public void testUnboundShortFormParsing() { + assertEquals(Tensor.from("tensor(x[]):[1.0, 2.0]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[])")).cell(1.0, 0).cell(2.0, 1).build()); + assertEquals(Tensor.from("tensor<float>(x[]):[1.0, 2.0]"), + Tensor.Builder.of(TensorType.fromSpec("tensor<float>(x[])")).cell(1.0, 0).cell(2.0, 1).build()); + assertEquals(Tensor.from("tensor<int8>(x[]):[1.0, 2.0]"), + Tensor.Builder.of(TensorType.fromSpec("tensor<int8>(x[])")).cell(1.0, 0).cell(2.0, 1).build()); + assertEquals(Tensor.from("tensor<bfloat16>(x[]):[1.0, 2.0]"), + Tensor.Builder.of(TensorType.fromSpec("tensor<bfloat16>(x[])")).cell(1.0, 0).cell(2.0, 1).build()); + + assertEquals(Tensor.from("tensor(x[],y[]):[[1,2,3,4]]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[],y[])")) + .cell(1.0, 0, 0).cell(2.0, 0, 1).cell(3.0, 0, 2).cell(4.0, 0, 3).build()); + assertEquals(Tensor.from("tensor(x[],y[]):[[1,2],[3,4]]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[],y[])")) + .cell(1.0, 0, 0).cell(2.0, 0, 1).cell(3.0, 1, 0).cell(4.0, 1, 1).build()); + assertEquals(Tensor.from("tensor(x[],y[]):[[1],[2],[3],[4]]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[],y[])")) + .cell(1.0, 0, 0).cell(2.0, 1, 0).cell(3.0, 2, 0).cell(4.0, 3, 0).build()); + assertEquals(Tensor.from("tensor(x[],y[],z[]):[[[1,2],[3,4]]]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[],y[],z[])")) + .cell(1.0, 0, 0, 0).cell(2.0, 0, 0, 1).cell(3.0, 0, 1, 0).cell(4.0, 0, 1, 1).build()); + assertEquals(Tensor.from("tensor(x[],y[],z[]):[[[1],[2],[3],[4]]]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[],y[],z[])")) + .cell(1.0, 0, 0, 0).cell(2.0, 0, 1, 0).cell(3.0, 0, 2, 0).cell(4.0, 0, 3, 0).build()); + assertEquals(Tensor.from("tensor(x[],y[],z[]):[[[1,2,3,4]]]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[],y[],z[])")) + .cell(1.0, 0, 0, 0).cell(2.0, 0, 0, 1).cell(3.0, 0, 0, 2).cell(4.0, 0, 0, 3).build()); + assertEquals(Tensor.from("tensor(x[],y[],z[]):[[[1]],[[2]],[[3]],[[4]]]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[],y[],z[])")) + .cell(1.0, 0, 0, 0).cell(2.0, 1, 0, 0).cell(3.0, 2, 0, 0).cell(4.0, 3, 0, 0).build()); + assertEquals(Tensor.from("tensor(x[],y[],z[]):[[[1, 2]],[[3, 4]]]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[],y[],z[])")) + .cell(1.0, 0, 0, 0).cell(2.0, 0, 0, 1).cell(3.0, 1, 0, 0).cell(4.0, 1, 0, 1).build()); + + assertEquals(Tensor.from("tensor(x[],y[],z[4]):[[[1,2,3,4]]]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[],y[],z[])")) + .cell(1.0, 0, 0, 0).cell(2.0, 0, 0, 1).cell(3.0, 0, 0, 2).cell(4.0, 0, 0, 3).build()); + assertEquals(Tensor.from("tensor(x[2],y[],z[2]):[[[1, 2]],[[3, 4]]]"), + Tensor.Builder.of(TensorType.fromSpec("tensor(x[],y[],z[])")) + .cell(1.0, 0, 0, 0).cell(2.0, 0, 0, 1).cell(3.0, 1, 0, 0).cell(4.0, 1, 0, 1).build()); + + assertIllegal("Unexpected size 2 for dimension y for type tensor(x[],y[3])", + "tensor(x[],y[3]):[[1,2],[3,4]]"); + } + private void assertDense(Tensor expectedTensor, String denseFormat) { assertEquals(denseFormat, expectedTensor, Tensor.from(denseFormat)); assertEquals(denseFormat, expectedTensor.toString()); |