コード例 #1
0
        public void NegateDoubleSingleValue()
        {
            INode <double> value = Flow.Negate(Flow.Constant(42.0)).Evaluate();

            Assert.IsNotNull(value);
            Assert.AreEqual(-42.0, value.GetValue());
        }
コード例 #2
0
        public void SessionRunManyTimes()
        {
            var constant    = Flow.Constant(1);
            var placeholder = Flow.PlaceHolder <int>("number", new int[0]);
            var operation   = Flow.Add(placeholder, Flow.Constant(1));

            Context context = new Context();

            context.SetNode("number", constant);
            Session session = new Session();

            var result = session.Run(operation, context);

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.GetValue(0));

            context.SetNode("number", result);

            result = session.Run(operation, context);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.GetValue(0));

            context.SetNode("number", result);

            result = session.Run(operation, context);

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.GetValue(0));
        }
コード例 #3
0
        public void NegateIntegerSingleValue()
        {
            INode <int> value = Flow.Negate(Flow.Constant(42)).Evaluate();

            Assert.IsNotNull(value);
            Assert.AreEqual(-42, value.GetValue());
        }
コード例 #4
0
        public void CreateConstantSingleValue()
        {
            INode <int> value = Flow.Constant <int>(42);

            Assert.IsNotNull(value);
            Assert.AreEqual(42, value.GetValue());
        }
コード例 #5
0
        public void SessionRunConstant()
        {
            var     constant = Flow.Constant(42);
            Session session  = new Session();

            var result = session.Run(constant, null);

            Assert.IsNotNull(result);
        }
コード例 #6
0
 public void CreateConstantMatrixWithNullValues()
 {
     try
     {
         Flow.Constant <int>((int[][])null);
         Assert.Fail();
     }
     catch (InvalidOperationException)
     {
     }
 }
コード例 #7
0
        public void AddDoubleSingleValues()
        {
            INode <double> left  = Flow.Constant(0.5);
            INode <double> right = Flow.Constant(41.5);

            var add = Flow.Add(left, right);

            Assert.AreEqual(left.Rank, add.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(add.Shape));
            Assert.AreEqual(42, add.GetValue());
        }
コード例 #8
0
 public void CreateConstantMatrixWithBadShape()
 {
     try
     {
         Flow.Constant <int>(new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5 } });
         Assert.Fail();
     }
     catch (InvalidOperationException)
     {
     }
 }
コード例 #9
0
        public void AddIntegerSingleValues()
        {
            INode <int> left  = Flow.Constant(1);
            INode <int> right = Flow.Constant(41);

            var add = Flow.Add(left, right);

            Assert.AreEqual(left.Rank, add.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(add.Shape));
            Assert.AreEqual(42, add.GetValue());
        }
コード例 #10
0
        public void ApplySimpleValueToPlaceHolder()
        {
            PlaceHolderNode <int> node  = new PlaceHolderNode <int>("answer", new int[0]);
            INode <int>           value = Flow.Constant(42);

            Context context = new Context();

            context.SetNode("answer", value);

            Assert.IsTrue(node.ApplyContext(context));
            Assert.AreEqual(42, node.GetValue(0));
        }
コード例 #11
0
        public void CreateConstantVector()
        {
            INode <int> value = Flow.Constant <int>(new int[] { 1, 2, 3 });

            Assert.IsNotNull(value);
            Assert.AreEqual(1, value.GetValue(0));
            Assert.AreEqual(2, value.GetValue(1));
            Assert.AreEqual(3, value.GetValue(2));

            Assert.AreEqual(1, value.Rank);
            Assert.IsTrue(value.Shape.SequenceEqual(new int[] { 3 }));
        }
コード例 #12
0
        public void NegateIntegerVector()
        {
            INode <int> value = Flow.Negate(Flow.Constant(new int[] { 1, 2, 3 })).Evaluate();

            Assert.IsNotNull(value);
            Assert.AreEqual(-1, value.GetValue(0));
            Assert.AreEqual(-2, value.GetValue(1));
            Assert.AreEqual(-3, value.GetValue(2));

            Assert.AreEqual(1, value.Rank);
            Assert.IsTrue(value.Shape.SequenceEqual(new int[] { 3 }));
        }
コード例 #13
0
        public void NegateDoubleVector()
        {
            INode <double> value = Flow.Negate(Flow.Constant(new double[] { 1.1, 2.2, 3.3 })).Evaluate();

            Assert.IsNotNull(value);
            Assert.AreEqual(-1.1, value.GetValue(0));
            Assert.AreEqual(-2.2, value.GetValue(1));
            Assert.AreEqual(-3.3, value.GetValue(2));

            Assert.AreEqual(1, value.Rank);
            Assert.IsTrue(value.Shape.SequenceEqual(new int[] { 3 }));
        }
コード例 #14
0
        public void DivideMatricesWithDifferentShapes()
        {
            INode <int> left  = Flow.Constant(new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 } });
            INode <int> right = Flow.Constant(new int[][] { new int[] { 10, 20 }, new int[] { 40, 50 } });

            try
            {
                new DivideIntegerOperation(left, right);
                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }
        }
コード例 #15
0
        public void DivideVectorsWithDifferentLengths()
        {
            INode <int> left  = Flow.Constant(new int[] { 1, 2, 3 });
            INode <int> right = Flow.Constant(new int[] { 4, 5, 6, 7 });

            try
            {
                new DivideIntegerOperation(left, right);
                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }
        }
コード例 #16
0
        public void SubtractVectorsWithDifferentLengths()
        {
            INode <double> left  = Flow.Constant(new double[] { 1.5, 2.5, 3.5 });
            INode <double> right = Flow.Constant(new double[] { 4.0, 5.0, 6.0, 7.0 });

            try
            {
                new AddDoubleOperation(left, right);
                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }
        }
コード例 #17
0
        public void SubtractMatricesWithDifferentShapes()
        {
            INode <double> left  = Flow.Constant(new double[][] { new double[] { 1.5, 2.5, 3.5 }, new double[] { 4.5, 5.5, 6.5 } });
            INode <double> right = Flow.Constant(new double[][] { new double[] { 10.0, 20.0 }, new double[] { 40.0, 50.0 } });

            try
            {
                new SubtractDoubleOperation(left, right);
                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }
        }
コード例 #18
0
        public void SetAndGetDoubleNode()
        {
            Context context = new Context();

            INode <double> node = Flow.Constant <double>(3.14159);

            context.SetNode("x", node);

            var result = context.GetNode <double>("x");

            Assert.IsNotNull(result);
            Assert.AreSame(node, result);

            Assert.IsNull(context.GetNode <int>("x"));
        }
コード例 #19
0
        public void SessionRunPlaceHolderContextWithConstant()
        {
            var constant    = Flow.Constant(42);
            var placeholder = Flow.PlaceHolder <int>("answer", new int[0]);

            Context context = new Context();

            context.SetNode("answer", constant);
            Session session = new Session();

            var result = session.Run(placeholder, context);

            Assert.IsNotNull(result);
            Assert.AreEqual(42, result.GetValue(0));
        }
コード例 #20
0
        public void CreateConstantMatrix()
        {
            INode <int> value = Flow.Constant <int>(new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 } });

            Assert.AreEqual(2, value.Rank);
            Assert.IsNotNull(value.Shape);
            Assert.IsTrue(value.Shape.SequenceEqual(new int[] { 2, 3 }));

            Assert.AreEqual(1, value.GetValue(0, 0));
            Assert.AreEqual(2, value.GetValue(0, 1));
            Assert.AreEqual(3, value.GetValue(0, 2));

            Assert.AreEqual(4, value.GetValue(1, 0));
            Assert.AreEqual(5, value.GetValue(1, 1));
            Assert.AreEqual(6, value.GetValue(1, 2));
        }
コード例 #21
0
        public void NegateIntegerMatrix()
        {
            INode <int> value = Flow.Negate(Flow.Constant(new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 } })).Evaluate();

            Assert.AreEqual(2, value.Rank);
            Assert.IsNotNull(value.Shape);
            Assert.IsTrue(value.Shape.SequenceEqual(new int[] { 2, 3 }));

            Assert.AreEqual(-1, value.GetValue(0, 0));
            Assert.AreEqual(-2, value.GetValue(0, 1));
            Assert.AreEqual(-3, value.GetValue(0, 2));

            Assert.AreEqual(-4, value.GetValue(1, 0));
            Assert.AreEqual(-5, value.GetValue(1, 1));
            Assert.AreEqual(-6, value.GetValue(1, 2));
        }
コード例 #22
0
        public void NegateDoubleMatrix()
        {
            INode <double> value = Flow.Negate(Flow.Constant(new double[][] { new double[] { 1.1, 2.2, 3.3 }, new double[] { 4.4, 5.5, 6.6 } })).Evaluate();

            Assert.AreEqual(2, value.Rank);
            Assert.IsNotNull(value.Shape);
            Assert.IsTrue(value.Shape.SequenceEqual(new int[] { 2, 3 }));

            Assert.AreEqual(-1.1, value.GetValue(0, 0));
            Assert.AreEqual(-2.2, value.GetValue(0, 1));
            Assert.AreEqual(-3.3, value.GetValue(0, 2));

            Assert.AreEqual(-4.4, value.GetValue(1, 0));
            Assert.AreEqual(-5.5, value.GetValue(1, 1));
            Assert.AreEqual(-6.6, value.GetValue(1, 2));
        }
コード例 #23
0
        public void AddSingleValues()
        {
            INode <double> left  = Flow.Constant(0.5);
            INode <double> right = Flow.Constant(41.5);

            var add = new AddDoubleOperation(left, right);

            Assert.AreEqual(left.Rank, add.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(right.Shape));

            var result = add.Evaluate();

            Assert.IsNotNull(result);
            Assert.AreEqual(left.Rank, result.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(result.Shape));
            Assert.AreEqual(42.0, result.GetValue());
        }
コード例 #24
0
        public void DivideSingleValues()
        {
            INode <int> left  = Flow.Constant(84);
            INode <int> right = Flow.Constant(2);

            var divide = new DivideIntegerOperation(left, right);

            Assert.AreEqual(left.Rank, divide.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(right.Shape));

            var result = divide.Evaluate();

            Assert.IsNotNull(result);
            Assert.AreEqual(left.Rank, result.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(result.Shape));
            Assert.AreEqual(42, result.GetValue());
        }
コード例 #25
0
        public void SubtractSingleValues()
        {
            INode <double> left  = Flow.Constant(42.5);
            INode <double> right = Flow.Constant(0.5);

            var subtract = new SubtractDoubleOperation(left, right);

            Assert.AreEqual(left.Rank, subtract.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(right.Shape));

            var result = subtract.Evaluate();

            Assert.IsNotNull(result);
            Assert.AreEqual(left.Rank, result.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(result.Shape));
            Assert.AreEqual(42.0, result.GetValue());
        }
コード例 #26
0
        public void MultiplySingleValues()
        {
            INode <int> left  = Flow.Constant(2);
            INode <int> right = Flow.Constant(21);

            var multiply = new MultiplyIntegerOperation(left, right);

            Assert.AreEqual(left.Rank, multiply.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(right.Shape));

            var result = multiply.Evaluate();

            Assert.IsNotNull(result);
            Assert.AreEqual(left.Rank, result.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(result.Shape));
            Assert.AreEqual(42, result.GetValue());
        }
コード例 #27
0
        public void SubtractSingleValues()
        {
            INode <int> left  = Flow.Constant(43);
            INode <int> right = Flow.Constant(1);

            var add = new SubtractIntegerOperation(left, right);

            Assert.AreEqual(left.Rank, add.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(right.Shape));

            var result = add.Evaluate();

            Assert.IsNotNull(result);
            Assert.AreEqual(left.Rank, result.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(result.Shape));
            Assert.AreEqual(42, result.GetValue());
        }
コード例 #28
0
        public void MultiplySingleValues()
        {
            INode <double> left  = Flow.Constant(2.0);
            INode <double> right = Flow.Constant(41.5);

            var multiply = new MultiplyDoubleOperation(left, right);

            Assert.AreEqual(left.Rank, multiply.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(right.Shape));

            var result = multiply.Evaluate();

            Assert.IsNotNull(result);
            Assert.AreEqual(left.Rank, result.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(result.Shape));
            Assert.AreEqual(83.0, result.GetValue());
        }
コード例 #29
0
        public void SubtractDoubleSingleValues()
        {
            INode <double> left  = Flow.Constant(43.5);
            INode <double> right = Flow.Constant(1.5);

            var add = Flow.Subtract(left, right);

            Assert.AreEqual(left.Rank, add.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(right.Shape));

            var result = add.Evaluate();

            Assert.IsNotNull(result);
            Assert.AreEqual(left.Rank, result.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(result.Shape));
            Assert.AreEqual(42.0, result.GetValue());
        }
コード例 #30
0
        public void DivideDoubleSingleValues()
        {
            INode <double> left  = Flow.Constant(10.0);
            INode <double> right = Flow.Constant(4.0);

            var divide = Flow.Divide(left, right);

            Assert.AreEqual(left.Rank, divide.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(right.Shape));

            var result = divide.Evaluate();

            Assert.IsNotNull(result);
            Assert.AreEqual(left.Rank, result.Rank);
            Assert.IsTrue(left.Shape.SequenceEqual(result.Shape));
            Assert.AreEqual(2.5, result.GetValue());
        }