From 03bce1fe1a494f2ac9d4268d4c90b08011b3f600 Mon Sep 17 00:00:00 2001 From: gjoranv Date: Sun, 17 Dec 2017 21:44:49 +0100 Subject: Revert "Bratseth/tensorflow models" --- .../com/yahoo/tensor/functions/JoinTestCase.java | 10 +-- .../com/yahoo/tensor/functions/MatmulTestCase.java | 97 ---------------------- .../tensor/functions/TensorFunctionTestCase.java | 6 +- 3 files changed, 8 insertions(+), 105 deletions(-) delete mode 100644 vespajlib/src/test/java/com/yahoo/tensor/functions/MatmulTestCase.java (limited to 'vespajlib/src/test/java/com/yahoo/tensor/functions') diff --git a/vespajlib/src/test/java/com/yahoo/tensor/functions/JoinTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/functions/JoinTestCase.java index f11c068bd74..fab53218b2c 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/functions/JoinTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/functions/JoinTestCase.java @@ -10,12 +10,12 @@ import static org.junit.Assert.assertEquals; * @author bratseth */ public class JoinTestCase { - + /** Test the indexed subspace join optimization */ @Test public void testJoinIndexedSubspace() { Tensor t1, t2; - + t1 = Tensor.from("tensor(x[]):{{x:0}:1.0,{x:1}:2.0}"); t2 = Tensor.from("tensor(x[],y[],z[]):{{x:0,y:0,z:0}:6,{x:0,y:1,z:0}:0.0,{x:1,y:0,z:0}:10,{x:1,y:1,z:0}:0.0}"); assertEquals(Tensor.from("tensor(x[],y[],z[]):{{x:0,y:0,z:0}:6,{x:0,y:1,z:0}:0.0,{x:1,y:0,z:0}:20.0,{x:1,y:1,z:0}:0.0}"), @@ -34,10 +34,10 @@ public class JoinTestCase { assertEquals(Tensor.from("tensor(x[],y[],z[]):{{x:0,y:0,z:0}:6,{x:0,y:1,z:0}:0.0,{x:1,y:0,z:0}:10.0,{x:1,y:1,z:0}:0.0}"), t2.divide(t1)); } - + @Test public void testGeneralJoin() { - assertEquals(Tensor.from("tensor(x[],y[]):{ {x:0,y:0}:1, {x:1,y:0}:2, {x:2,y:0}:3 }"), + assertEquals(Tensor.from("tensor(x[],y[]):{ {x:0,y:0}:1, {x:1,y:0}:2, {x:2,y:0}:3 }"), Tensor.from("tensor(x[]):{ {x:0}:2, {x:1}:4, {x:2}:6 }") .divide(Tensor.from("tensor(y[]):{{y:0}:2}"))); @@ -45,5 +45,5 @@ public class JoinTestCase { Tensor.from("tensor(x[],y[]):{ {x:0,y:0}:6, {x:1,y:0}:8, {x:0,y:1}:20, {x:1,y:1}:24 }") .divide(Tensor.from("tensor(y[],z[]):{ {y:0,z:0}:2, {y:1,z:0}:4, {y:2,z:0}:6 }"))); } - + } diff --git a/vespajlib/src/test/java/com/yahoo/tensor/functions/MatmulTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/functions/MatmulTestCase.java deleted file mode 100644 index 9643c0a56e7..00000000000 --- a/vespajlib/src/test/java/com/yahoo/tensor/functions/MatmulTestCase.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.yahoo.tensor.functions; - -import com.google.common.collect.ImmutableList; -import com.yahoo.tensor.Tensor; -import com.yahoo.tensor.TensorType; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * @author bratseth - */ -public class MatmulTestCase { - - @Test - public void testMatmul2d() { - // d0 is the 'outermost' dimension, etc. - Tensor.Builder ab = Tensor.Builder.of(TensorType.fromSpec("tensor(d0[2],d1[3])")); - ab.cell( 1,0, 0); - ab.cell( 2,0, 1); - ab.cell( 3,0, 2); - ab.cell( 4,1, 0); - ab.cell( 5,1, 1); - ab.cell( 6,1, 2); - Tensor a = ab.build(); - - Tensor.Builder bb = Tensor.Builder.of(TensorType.fromSpec("tensor(d0[3],d1[2])")); - bb.cell( 7,0, 0); - bb.cell( 8,0, 1); - bb.cell( 9,1, 0); - bb.cell(10,1, 1); - bb.cell(11,2, 0); - bb.cell(12,2, 1); - Tensor b = bb.build(); - - Tensor.Builder rb = Tensor.Builder.of(TensorType.fromSpec("tensor(d0[2],d1[2])")); - rb.cell( 58,0, 0); - rb.cell( 64,0, 1); - rb.cell(139,1, 0); - rb.cell(154,1, 1); - Tensor r = rb.build(); - - Tensor result = a.matmul(b.rename(ImmutableList.of("d0","d1"), ImmutableList.of("d1","d2")), "d1") - .rename("d2","d1"); - assertEquals(r, result); - } - - @Test - public void testMatmul3d() { - // Convention: a is the 'outermost' dimension, etc. - Tensor.Builder ab = Tensor.Builder.of(TensorType.fromSpec("tensor(d0[2],d1[2],d2[3])")); - ab.cell( 1,0, 0, 0); - ab.cell( 2,0, 0, 1); - ab.cell( 3,0, 0, 2); - ab.cell( 4,0, 1, 0); - ab.cell( 5,0, 1, 1); - ab.cell( 6,0, 1, 2); - ab.cell( 7,1, 0, 0); - ab.cell( 8,1, 0, 1); - ab.cell( 9,1, 0, 2); - ab.cell(10,1, 1, 0); - ab.cell(11,1, 1, 1); - ab.cell(12,1, 1, 2); - Tensor a = ab.build(); - - Tensor.Builder bb = Tensor.Builder.of(TensorType.fromSpec("tensor(d0[2],d1[3],d2[2])")); - bb.cell(13,0, 0, 0); - bb.cell(14,0, 0, 1); - bb.cell(15,0, 1, 0); - bb.cell(16,0, 1, 1); - bb.cell(17,0, 2, 0); - bb.cell(18,0, 2, 1); - bb.cell(19,1, 0, 0); - bb.cell(20,1, 0, 1); - bb.cell(21,1, 1, 0); - bb.cell(22,1, 1, 1); - bb.cell(23,1, 2, 0); - bb.cell(24,1, 2, 1); - Tensor b = bb.build(); - - Tensor.Builder rb = Tensor.Builder.of(TensorType.fromSpec("tensor(d0[2],d1[2],d2[2])")); - rb.cell( 94,0, 0, 0); - rb.cell(100,0, 0, 1); - rb.cell(229,0, 1, 0); - rb.cell(244,0, 1, 1); - rb.cell(508,1, 0, 0); - rb.cell(532,1, 0, 1); - rb.cell(697,1, 1, 0); - rb.cell(730,1, 1, 1); - Tensor r = rb.build(); - - Tensor result = a.matmul(b.rename(ImmutableList.of("d1","d2"), ImmutableList.of("d2","d3")), "d2") - .rename("d3","d2"); - assertEquals(r, result); - } - -} diff --git a/vespajlib/src/test/java/com/yahoo/tensor/functions/TensorFunctionTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/functions/TensorFunctionTestCase.java index 55069eaced7..8a58cb0bbed 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/functions/TensorFunctionTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/functions/TensorFunctionTestCase.java @@ -7,7 +7,7 @@ import static org.junit.Assert.assertEquals; /** * Tests translation of composite to primitive tensor function translation. - * + * * @author bratseth */ public class TensorFunctionTestCase { @@ -16,12 +16,12 @@ public class TensorFunctionTestCase { public void testTranslation() { assertTranslated("join({{x:1}:1.0}, reduce({{x:1}:1.0}, sum, x), f(a,b)(a / b))", new L1Normalize(new ConstantTensor("{{x:1}:1.0}"), "x")); - assertTranslated("tensor(x[2],y[3],z[4])((x==y)*(y==z))", + assertTranslated("tensor(x[2],y[3],z[4])((x==y)*(y==z))", new Diag(new TensorType.Builder().indexed("y",3).indexed("x",2).indexed("z",4).build())); assertTranslated("join({{x:1}:1.0,{x:3}:5.0,{x:9}:3.0}, reduce({{x:1}:1.0,{x:3}:5.0,{x:9}:3.0}, max, x), f(a,b)(a==b))", new Argmax(new ConstantTensor("{ {x:1}:1, {x:3}:5, {x:9}:3 }"), "x")); } - + private void assertTranslated(String expectedTranslation, TensorFunction inputFunction) { assertEquals(expectedTranslation, inputFunction.toPrimitive().toString()); } -- cgit v1.2.3