示例#1
0
        public static double measureFFT(int N, double mintime, Random R)
        {
            double[]  data      = kernel.RandomVector(checked (2 * N), R);
            long      num1      = 20000;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.start();
            int num2 = 0;

            while ((long)num2 < num1)
            {
                FFT.transform(data);
                FFT.inverse(data);
                checked { ++num2; }
            }
            stopwatch.stop();
            if (FFT.test(data) / (double)N > 0.0 / 1.0)
            {
                return(0.0);
            }
            return(FFT.num_flops(N) * (double)num1 / stopwatch.read() * 1E-06);
        }
示例#2
0
        // each measurement returns approx Mflops
        public static double measureFFT(int N, double mintime, Random R)
        {
            // initialize FFT data as complex (N real/img pairs)

            double[] x = RandomVector(2 * N, R);
            //double oldx[] = NewVectorCopy(x);
            long      cycles = 1;
            Stopwatch clock  = new Stopwatch();

            while (true)
            {
                clock.Start();
                for (int i = 0; i < cycles; i++)
                {
                    FFT.transform(x);                   // forward transform
                    FFT.inverse(x);                     // backward transform
                }
                clock.Stop();
                if (clock.Elapsed.TotalSeconds >= mintime)
                {
                    break;
                }

                cycles *= 2;
            }
            // approx Mflops

            const double EPS = 1.0e-10;

            if (FFT.test(x) / N > EPS)
            {
                return(0.0);
            }

            return(FFT.num_flops(N) * cycles / clock.Elapsed.TotalMilliseconds * 1.0e-3);
        }
示例#3
0
        protected internal static void transform_internal(double[] data, int direction)
        {
            if (data.Length == 0)
            {
                return;
            }
            int n = data.Length / 2;

            if (n == 1)
            {
                return;
            }
            int num1 = FFT.log2(n);

            FFT.bitreverse(data);
            int num2 = 0;
            int num3 = 1;

            while (num2 < num1)
            {
                double num4 = 1.0;
                double num5 = 0.0;
                double a    = 2.0 * (double)direction * Math.PI / (2.0 * (double)num3);
                double num6 = Math.Sin(a);
                double num7 = Math.Sin(a / 2.0);
                double num8 = 2.0 * num7 * num7;
                int    num9 = 0;
                while (num9 < n)
                {
                    int    index1 = checked (2 * num9);
                    int    index2 = checked (2 * num9 + num3);
                    double num10  = data[index2];
                    double num11  = data[checked (index2 + 1)];
                    data[index2] = data[index1] - num10;
                    data[checked (index2 + 1)] = data[checked (index1 + 1)] - num11;
                    data[index1] += num10;
                    data[checked (index1 + 1)] += num11;
                    checked { num9 += 2 * num3; }
                }
                int num12 = 1;
                while (num12 < num3)
                {
                    double num10 = num4 - num6 * num5 - num8 * num4;
                    double num11 = num5 + num6 * num4 - num8 * num5;
                    num4 = num10;
                    num5 = num11;
                    int num13 = 0;
                    while (num13 < n)
                    {
                        int    index1 = checked (2 * num13 + num12);
                        int    index2 = checked (2 * num13 + num12 + num3);
                        double num14  = data[index2];
                        double num15  = data[checked (index2 + 1)];
                        double num16  = num4 * num14 - num5 * num15;
                        double num17  = num4 * num15 + num5 * num14;
                        data[index2] = data[index1] - num16;
                        data[checked (index2 + 1)] = data[checked (index1 + 1)] - num17;
                        data[index1] += num16;
                        data[checked (index1 + 1)] += num17;
                        checked { num13 += 2 * num3; }
                    }
                    checked { ++num12; }
                }
                checked { ++num2; }
                checked { num3 *= 2; }
            }
        }
示例#4
0
 public static void transform(double[] data)
 {
     FFT.transform_internal(data, -1);
 }