Exemplo n.º 1
0
        public void TestTensorVar()
        {
            var x = Op.Matrix <float>("x");
            var f = Op.Function(input: x, output: x);

            AssertArray.AreEqual(f(NN.Const(3.0f, 2, 2)), NN.Const(3.0f, 2, 2));
            AssertArray.AreNotEqual(f(NN.Const(3.0f, 2, 2)), NN.Const(4.0f, 2, 2));
        }
Exemplo n.º 2
0
        public void TestTensorConst()
        {
            var x = Op.Const(2.0f, 2, 2);
            var f = Op.Function(output: x);

            AssertArray.AreEqual(f(), NN.Const(2.0f, 2, 2));
            AssertArray.AreNotEqual(f(), NN.Const(3.0f, 2, 2));
        }
Exemplo n.º 3
0
        public void TestTensorUnary()
        {
            var x = Op.Matrix <float>("x");
            var f = Op.Function(input: x, output: Op.Abs(x));

            AssertArray.AreEqual(f(NN.Const(5.0f, 2, 2)), NN.Const(5.0f, 2, 2));
            AssertArray.AreEqual(f(NN.Const(-5.0f, 2, 2)), NN.Const(5.0f, 2, 2));
            AssertArray.AreNotEqual(f(NN.Const(6.0f, 2, 2)), NN.Const(5.0f, 2, 2));
            AssertArray.AreNotEqual(f(NN.Const(-6.0f, 2, 2)), NN.Const(5.0f, 2, 2));
        }
Exemplo n.º 4
0
        public void TestTensorMulAdd()
        {
            var a = Op.Matrix <float>("a");
            var b = Op.Matrix <float>("b");
            var f = Op.Function(input: (a, b), output: 3 * (a + b));

            AssertArray.AreEqual(f(NN.Const(3f, 2, 2), NN.Const(4f, 2, 2)), NN.Const(21f, 2, 2));
            AssertArray.AreEqual(f(NN.Const(3f, 2, 2), NN.Const(-4f, 2, 2)), NN.Const(-3f, 2, 2));
            AssertArray.AreNotEqual(f(NN.Const(3f, 2, 2), NN.Const(4f, 2, 2)), NN.Const(7f, 2, 2));
            AssertArray.AreNotEqual(f(NN.Const(3f, 2, 2), NN.Const(4f, 2, 2)), NN.Const(9f, 2, 2));
        }
Exemplo n.º 5
0
        public void TestTensorAdd()
        {
            var x = Op.Matrix <float>("x");
            var y = Op.Matrix <float>("y");
            var f = Op.Function(input: (x, y), output: x + y);

            AssertArray.AreEqual(f(NN.Const(3f, 2, 2), NN.Const(4f, 2, 2)), NN.Const(7f, 2, 2));
            AssertArray.AreEqual(f(NN.Const(3f, 2, 2), NN.Const(-4f, 2, 2)), NN.Const(-1f, 2, 2));
            AssertArray.AreNotEqual(f(NN.Const(3f, 2, 2), NN.Const(4f, 2, 2)), NN.Const(3f, 2, 2));
            AssertArray.AreNotEqual(f(NN.Const(3f, 2, 2), NN.Const(-4f, 2, 2)), NN.Const(4f, 2, 2));
        }
Exemplo n.º 6
0
 public static Array <T> Const <T>(T a, int[] shape, Array <T> result = null)
 {
     if (result != null)
     {
         result.FillWith(a);
         return(result);
     }
     else
     {
         return(NN.Const(a, shape));
     }
 }
Exemplo n.º 7
0
        // TODO: this test doesn't work due to bugs in Elementwise
        public void PushCoherentGradientOnSimpleAbstraction()
        {
            var x = T.Shared(NN.Range <float>(4), "x");
            var b = T.Scalar <float>("b");

            var y    = T.Apply(x, x_ => x_ + b);
            var loss = T.Sum(y);

            var dL_db = T.Function(b, T.Grad(loss, b));

            //dL_db should be 4;

            AssertArray.AreEqual(NN.Const(4f, 10), NN.Range <float>(10).Apply(dL_db));
        }