예제 #1
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();
            }
        }
예제 #2
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 }));
        }