예제 #1
0
        public void Add_()
        {
            float[] data1   = { float.MinValue, -10, -1.5f, 0, 1.5f, 10, 20, float.MaxValue };
            int[]   shape1  = { 2, 4 };
            var     tensor1 = new FloatTensor(data1, shape1);
            var     tensor2 = new FloatTensor(data1, shape1);

            // Test addition by 0
            float val = 0;

            tensor1.Add_(val);

            for (int i = 0; i < tensor1.Size; i++)
            {
                Assert.AreEqual(tensor2.Data [i] + val, tensor1.Data [i]);
            }

            // Test addition by positive
            tensor1 = new FloatTensor(data1, shape1);
            val     = 99;
            tensor1.Add_(val);

            for (int i = 0; i < tensor1.Size; i++)
            {
                Assert.AreEqual(tensor2.Data [i] + val, tensor1.Data [i]);
            }

            // Test addition by negative
            tensor1 = new FloatTensor(data1, shape1);
            val     = -99;
            tensor1.Add_(val);

            for (int i = 0; i < tensor1.Size; i++)
            {
                Assert.AreEqual(tensor2.Data [i] + val, tensor1.Data [i]);
            }

            // Test addition by decimal
            tensor1 = new FloatTensor(data1, shape1);
            val     = 0.000001f;
            tensor1.Add_(val);

            for (int i = 0; i < tensor1.Size; i++)
            {
                Assert.AreEqual(tensor2.Data [i] + val, tensor1.Data [i]);
            }
        }