Пример #1
0
        public static void TestUnaryOperation(UnaryOp op)
        {
            PrecisionResult precision = TestUnaryPrecision(op);
            BenchmarkResult benchmark = BenchmarkUnaryOperation(op);

            PrintOperationSummary(op.name, precision, benchmark);
        }
Пример #2
0
        public static void TestUnaryBasicValues(UnaryOp op)
        {
            int numValues = op.basicValues.Length;

            if (numValues > 0)
            {
                F64[]    inputs    = new F64[numValues];
                F64[]    outputs   = new F64[numValues];
                double[] reference = new double[numValues];

                for (int i = 0; i < numValues; i++)
                {
                    F64 i0 = F64.FromDouble(op.basicValues[i]);
                    inputs[i]    = i0;
                    reference[i] = op.refExecute(i0.Double);
                }

                op.arrayExecute(numValues, inputs, outputs);

                Console.WriteLine("{0,-16}    {1,16} {2,16} {3,16}", op.name, "reference", "result", "error");
                for (int i = 0; i < numValues; i++)
                {
                    double input = inputs[i].Double;
                    double res   = outputs[i].Double;
                    double err   = op.evaluateError(inputs[i], outputs[i], reference[i]);
                    Console.WriteLine("{0} -> {1} {2} {3}", DoubleToString(input, 16), DoubleToString(reference[i], 16), DoubleToString(res, 16), DoubleToString(err, 16));
                }
                Console.WriteLine();
            }
        }
Пример #3
0
        public static PrecisionResult TestUnaryPrecision(UnaryOp op)
        {
            int    numTested  = 0;
            double totalErr   = 0.0;
            double maxErr     = 0.0;
            F64    worstInput = F64.Zero;

            foreach (ValueGenerator inputGenerator in op.inputGenerators)
            {
                F64[] inputs  = inputGenerator(rnd, NUM_PRECISION_TESTS).Select(d => F64.FromDouble(d)).ToArray();
                F64[] outputs = new F64[NUM_PRECISION_TESTS];

                op.arrayExecute(NUM_PRECISION_TESTS, inputs, outputs);

                for (int i = 0; i < NUM_PRECISION_TESTS; i++)
                {
                    double input     = inputs[i].Double;
                    double res       = outputs[i].Double;
                    double reference = op.refExecute(input);

                    if (reference >= ValueBounds.NegMax && reference <= ValueBounds.PosMax)
                    {
                        double err = op.evaluateError(inputs[i], outputs[i], reference);
                        numTested++;
                        totalErr += err;

                        if (err >= maxErr)
                        {
                            maxErr     = Math.Max(maxErr, err);
                            worstInput = inputs[i];
                        }
                    }
                }
            }

            Debug.Assert(numTested > 1000);
            double avgErr  = totalErr / (double)numTested;
            double numBits = -Math.Log(maxErr, 2.0);

            return(new PrecisionResult(avgErr, maxErr, numBits, new[] { worstInput }));
        }
Пример #4
0
        public static BenchmarkResult BenchmarkUnaryOperation(UnaryOp op)
        {
            // \todo [petri] use all generators?
            F64[] inputs  = op.inputGenerators[0](rnd, BENCHMARK_CHUNK_SIZE).Select(d => F64.FromDouble(d)).ToArray();
            F64[] outputs = new F64[BENCHMARK_CHUNK_SIZE];

            // Measure execution time.
            double elapsedSeconds = BenchmarkFunction(() =>
            {
                for (int iter = 0; iter < op.numBenchmarkIters; iter++)
                {
                    op.arrayExecute(BENCHMARK_CHUNK_SIZE, inputs, outputs);
                }
            });

            // Return result.
            long   numTotalOps = op.numBenchmarkIters * BENCHMARK_CHUNK_SIZE;
            double opsPerSec   = numTotalOps / elapsedSeconds;

            return(new BenchmarkResult(opsPerSec, elapsedSeconds));
        }