Example #1
0
        public void ExecuteTest()
        {
            float max_err = 0;

            foreach (int batch in new int[] { 1, 2 })
            {
                foreach (int inchannels in new int[] { 1, 2, 3, 4, 5, 10, 15, 20 })
                {
                    foreach (int outchannels in new int[] { 7, 13 })
                    {
                        float[] xval = (new float[inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray();
                        float[] yval = (new float[outchannels * batch]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray();

                        Map0D x = new Map0D(inchannels, batch, xval);
                        Map0D y = new Map0D(outchannels, batch, yval);

                        Filter0D gw = Reference(x, y);

                        OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels, batch), xval);
                        OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels, batch), yval);

                        OverflowCheckedTensor gw_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels));

                        KernelProduct ope = new KernelProduct(inchannels, outchannels, batch);

                        ope.Execute(x_tensor, y_tensor, gw_tensor);

                        float[] gw_expect = gw.ToArray();
                        float[] gw_actual = gw_tensor.State;

                        CollectionAssert.AreEqual(xval, x_tensor.State);
                        CollectionAssert.AreEqual(yval, y_tensor.State);

                        AssertError.Tolerance(gw_expect, gw_actual, 1e-7f, 1e-5f, ref max_err, $"mismatch value {inchannels},{outchannels},{batch}");

                        Console.WriteLine($"pass: {inchannels},{outchannels},{batch}");
                    }
                }
            }

            Console.WriteLine($"maxerr:{max_err}");
        }
Example #2
0
        public void ReferenceTest()
        {
            int inchannels = 7, outchannels = 11, batch = 2;

            float[] xval = (new float[batch * inchannels]).Select((_, idx) => idx * 1e-3f).ToArray();
            float[] yval = (new float[batch * outchannels]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray();

            Map0D x = new Map0D(inchannels, batch, xval);
            Map0D y = new Map0D(outchannels, batch, yval);

            Filter0D gw = Reference(x, y);

            float[] gw_expect =
            {
                7.0000e-05f, 1.0100e-04f, 1.3200e-04f, 1.6300e-04f, 1.9400e-04f,
                2.2500e-04f, 2.5600e-04f, 6.3000e-05f, 9.2000e-05f, 1.2100e-04f,
                1.5000e-04f, 1.7900e-04f, 2.0800e-04f, 2.3700e-04f, 5.6000e-05f,
                8.3000e-05f, 1.1000e-04f, 1.3700e-04f, 1.6400e-04f, 1.9100e-04f,
                2.1800e-04f, 4.9000e-05f, 7.4000e-05f, 9.9000e-05f, 1.2400e-04f,
                1.4900e-04f, 1.7400e-04f, 1.9900e-04f, 4.2000e-05f, 6.5000e-05f,
                8.8000e-05f, 1.1100e-04f, 1.3400e-04f, 1.5700e-04f, 1.8000e-04f,
                3.5000e-05f, 5.6000e-05f, 7.7000e-05f, 9.8000e-05f, 1.1900e-04f,
                1.4000e-04f, 1.6100e-04f, 2.8000e-05f, 4.7000e-05f, 6.6000e-05f,
                8.5000e-05f, 1.0400e-04f, 1.2300e-04f, 1.4200e-04f, 2.1000e-05f,
                3.8000e-05f, 5.5000e-05f, 7.2000e-05f, 8.9000e-05f, 1.0600e-04f,
                1.2300e-04f, 1.4000e-05f, 2.9000e-05f, 4.4000e-05f, 5.9000e-05f,
                7.4000e-05f, 8.9000e-05f, 1.0400e-04f, 7.0000e-06f, 2.0000e-05f,
                3.3000e-05f, 4.6000e-05f, 5.9000e-05f, 7.2000e-05f, 8.5000e-05f,
                0.0000e+00f, 1.1000e-05f, 2.2000e-05f, 3.3000e-05f, 4.4000e-05f,
                5.5000e-05f, 6.6000e-05f
            };

            float[] gw_actual = gw.ToArray();

            AssertError.Tolerance(gw_expect, gw_actual, 1e-7f, 1e-5f, $"mismatch value {inchannels},{outchannels},{batch}");
        }