コード例 #1
0
        public void ReferenceTest()
        {
            int inchannels = 6, outchannels = 8, batch = 3;

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

            System.Numerics.Complex[] xcval = (new System.Numerics.Complex[xval.Length / 2])
                                              .Select((_, idx) => new System.Numerics.Complex(xval[idx * 2], xval[idx * 2 + 1])).ToArray();

            System.Numerics.Complex[] wcval = (new System.Numerics.Complex[wval.Length / 2])
                                              .Select((_, idx) => new System.Numerics.Complex(wval[idx * 2], wval[idx * 2 + 1])).ToArray();

            ComplexMap0D    x = new ComplexMap0D(inchannels / 2, batch, xcval);
            ComplexFilter0D w = new ComplexFilter0D(inchannels / 2, outchannels / 2, wcval);

            ComplexMap0D y = Reference(x, w);

            float[] y_expect =
            {
                -5.400000e-05f, 2.930000e-04f, -3.600000e-05f, 2.030000e-04f, -1.800000e-05f, 1.130000e-04f,
                0.000000e+00f,  2.300000e-05f, -3.600000e-05f, 1.031000e-03f, -1.800000e-05f, 7.250000e-04f,
                -2.710505e-20f, 4.190000e-04f,  1.800000e-05f, 1.130000e-04f, -1.800000e-05f, 1.769000e-03f,
                0.000000e+00f,  1.247000e-03f,  1.800000e-05f, 7.250000e-04f,  3.600000e-05f, 2.030000e-04f,
            };

            float[] y_actual = y.ToArray();

            AssertError.Tolerance(y_expect, y_actual, 1e-9f, 1e-5f, $"mismatch value {inchannels},{outchannels},{batch}");
        }
コード例 #2
0
        public void ReferenceTest()
        {
            int inchannels = 6, outchannels = 8, batch = 3;

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

            System.Numerics.Complex[] ycval = (new System.Numerics.Complex[yval.Length / 2])
                                              .Select((_, idx) => new System.Numerics.Complex(yval[idx * 2], yval[idx * 2 + 1])).ToArray();

            System.Numerics.Complex[] wcval = (new System.Numerics.Complex[wval.Length / 2])
                                              .Select((_, idx) => new System.Numerics.Complex(wval[idx * 2], wval[idx * 2 + 1])).ToArray();

            ComplexMap0D    y = new ComplexMap0D(outchannels / 2, batch, ycval);
            ComplexFilter0D w = new ComplexFilter0D(inchannels / 2, outchannels / 2, wcval);

            ComplexMap0D x = Reference(y, w);

            float[] x_expect =
            {
                -4.000000e-05f, 2.600000e-04f, -3.200000e-05f, 2.040000e-04f, -2.400000e-05f, 1.480000e-04f,
                -8.000000e-06f, 1.124000e-03f,  0.000000e+00f, 9.400000e-04f,  8.000000e-06f, 7.560000e-04f,
                2.400000e-05f,  1.988000e-03f,  3.200000e-05f, 1.676000e-03f,  4.000000e-05f, 1.364000e-03f,
            };

            float[] x_actual = x.ToArray();

            AssertError.Tolerance(x_expect, x_actual, 1e-9f, 1e-5f, $"mismatch value {inchannels},{outchannels},{batch}");
        }
コード例 #3
0
        public void ExecuteTest()
        {
            float max_err = 0;

            foreach (int batch in new int[] { 1, 2, 3 })
            {
                foreach (int inchannels in new int[] { 2, 4, 10, 20 })
                {
                    foreach (int outchannels in new int[] { 6, 14 })
                    {
                        float[] xval = (new float[inchannels * batch]).Select((_, idx) => idx * 1e-3f).ToArray();
                        float[] wval = (new float[inchannels * outchannels / 2]).Select((_, idx) => idx * 1e-3f).Reverse().ToArray();

                        System.Numerics.Complex[] xcval = (new System.Numerics.Complex[xval.Length / 2])
                                                          .Select((_, idx) => new System.Numerics.Complex(xval[idx * 2], xval[idx * 2 + 1])).ToArray();

                        System.Numerics.Complex[] wcval = (new System.Numerics.Complex[wval.Length / 2])
                                                          .Select((_, idx) => new System.Numerics.Complex(wval[idx * 2], wval[idx * 2 + 1])).ToArray();

                        ComplexMap0D    x = new ComplexMap0D(inchannels / 2, batch, xcval);
                        ComplexFilter0D w = new ComplexFilter0D(inchannels / 2, outchannels / 2, wcval);

                        ComplexMap0D y = Reference(x, w);

                        OverflowCheckedTensor x_tensor = new OverflowCheckedTensor(Shape.Map0D(inchannels, batch), xval);
                        OverflowCheckedTensor w_tensor = new OverflowCheckedTensor(Shape.Kernel0D(inchannels, outchannels / 2), wval);

                        OverflowCheckedTensor y_tensor = new OverflowCheckedTensor(Shape.Map0D(outchannels, batch));

                        ComplexDense ope = new ComplexDense(inchannels, outchannels, gradmode: false, batch);

                        ope.Execute(x_tensor, w_tensor, y_tensor);

                        float[] y_expect = y.ToArray();
                        float[] y_actual = y_tensor.State;

                        CollectionAssert.AreEqual(xval, x_tensor.State);
                        CollectionAssert.AreEqual(wval, w_tensor.State);

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

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

            Console.WriteLine($"maxerr:{max_err}");
        }