creating Lib/tests/cmath_testcases.txt for 64 bit complex numbers (text)

(I apologize for posting HTML mail. Retrying.) Hi. I am implementing complex numbers for pypy's version of numpy. Numpy has both 128 bit (based on 64 bit floats) and 64 bit (based on 32 bit floats) complex numbers, where afaict cmath uses strictly 128 bit complex numbers. I made sure the 128 bit numpy complex numbers in pypy pass the tests in Lib/tests/cmath_testcases.txt. I would like to generate a similar file to cmath_testcases.txt for 64 bit complex numbers. I found the earliest commit of the file at http://hg.python.org/cpython/file/b69f443ef480/Lib/test/cmath_testcases.txt Can the authors of the original file help me reconstruct the scripts or programs used to generate it, and reformulate them for 32 bit floats? Since there are more than 2000 cases, and many need rewriting, I prefer an automated method to error-prone hand coding. By the way, the level of testing is most impressive. Thanks for any help or tips, Matti Picus

On Mon, Sep 10, 2012 at 9:06 PM, Matti Picus <matti.picus@gmail.com> wrote:
Can the authors of the original file help me reconstruct the scripts or programs used to generate it, and reformulate them for 32 bit floats?
I used a ctypes wrapper around the MPFR library for most of the testcases, though some were generated by hand. I later pushed a version of the MPFR wrapper to PyPI under the name 'bigfloat', but unfortunately haven't had time to maintain it; it may or may not work right now. (IIRC, version 0.2 should work okay; I'd started a rewrite using Cython instead of ctypes and then got bogged down in Python 2 / Python 3 distribution fun. The source at https://bitbucket.org/dickinsm/bigfloat/src is functional, but doesn't have distribution sorted out.) I also used Pari/GP to spot check some of the results. And that only gets you halfway there, since MPFR only does the real parts; it's still necessary to implement the formulas for the real and imaginary parts in each case, using as much additional precision as necessary to compute intermediate results. I used a simple 'peeling the onion' approach, computing lower and upper bounds for the values in each case and extending precision until both the lower and upper values gave the same result when rounded to 53 bit precision. At the time I did this, I don't think the MPC library[1] existed in usable form; that may make life easier. You should also look at Gmpy2 [2]; I believe the most recent release supports MPC and MPFR. That's probably the simplest way forward. Note that MPFR doesn't support IEEE subnormals out of the box, though it provides some convenience functions to make it relatively easy to add subnormal support. That was one of my motivations for writing bigfloat. I'm afraid I don't have the exact scripts that I used any more; they're sitting on the hard drive of a defunct computer that's awaiting resurrection. Mark [1] http://www.multiprecision.org/ [2] http://code.google.com/p/gmpy/

On Mon, Sep 10, 2012 at 9:06 PM, Matti Picus <matti.picus@gmail.com> wrote:
Can the authors of the original file help me reconstruct the scripts or programs used to generate it, and reformulate them for 32 bit floats?
I used a ctypes wrapper around the MPFR library for most of the testcases, though some were generated by hand. I later pushed a version of the MPFR wrapper to PyPI under the name 'bigfloat', but unfortunately haven't had time to maintain it; it may or may not work right now. (IIRC, version 0.2 should work okay; I'd started a rewrite using Cython instead of ctypes and then got bogged down in Python 2 / Python 3 distribution fun. The source at https://bitbucket.org/dickinsm/bigfloat/src is functional, but doesn't have distribution sorted out.) I also used Pari/GP to spot check some of the results. And that only gets you halfway there, since MPFR only does the real parts; it's still necessary to implement the formulas for the real and imaginary parts in each case, using as much additional precision as necessary to compute intermediate results. I used a simple 'peeling the onion' approach, computing lower and upper bounds for the values in each case and extending precision until both the lower and upper values gave the same result when rounded to 53 bit precision. At the time I did this, I don't think the MPC library[1] existed in usable form; that may make life easier. You should also look at Gmpy2 [2]; I believe the most recent release supports MPC and MPFR. That's probably the simplest way forward. Note that MPFR doesn't support IEEE subnormals out of the box, though it provides some convenience functions to make it relatively easy to add subnormal support. That was one of my motivations for writing bigfloat. I'm afraid I don't have the exact scripts that I used any more; they're sitting on the hard drive of a defunct computer that's awaiting resurrection. Mark [1] http://www.multiprecision.org/ [2] http://code.google.com/p/gmpy/
participants (2)
-
Mark Dickinson
-
Matti Picus