[pythran] Re: gmp

  • From: Brunet Pierrick <pierrick.brunet@xxxxxxxxxxxxxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Sat, 27 Oct 2012 22:55:20 +0200

Le 27/10/2012 22:44, serge Guelton a écrit :
On Sat, Oct 27, 2012 at 03:54:45PM +0200, Brunet Pierrick wrote:

    About last commit, I did some modification as I never tested to use
    a long
    as pythran input specification. In the code, we need to use
    mpz_class as a
    constructed type to have a correct behaviour.
    Also, I fix another issue un the conversion from pylong to

    I tested the code below and get an error:

    #export pythran test(long)
    def test(a)
    ??? for i in xrange(a):

    Because xrange doesn't support long as input parameter. It looks
    python doesn't support either.
Ok. If Cpython fails, we can fail too :-)

    About profiling, I did some test using the binamial law with : 10
    by 60.
    Result look good and we have almost the same ratio with others
    numbers. I
    just need to find some others bench

    In [4]: %timeit test1.test(10,60)
    100000 loops, best of 3: 5.26 us per loop

    In [5]: %timeit test2.test(10,60)
    100000 loops, best of 3: 5.32 us per loop

    In [6]: %timeit test3.test(10,60)
    100000 loops, best of 3: 11.5 us per loop
mmmh, where is the reference ? CPython timings ? g++ flags used by
pythran ?

Sorry, test1 is pythran without gmp
test2 is pythran with gmp
test3 is CPython

    Finally, we have another error now:

    if we define a long num : a = 1111111111111L
    and add a float: b = a +2.5
    the result is b = 1111111111113L
    Pythran doesn't care about the value after the point.
    Issue comme from Assignable specification but we can't do this in
    way as gmp have some limitation about Templates :
Does it mean we have to make all arguments assignable ?

The problem is not with assignable. For now, when we have a __gmp_expr<T,G>, Assignable say : "ho, I have a specialisation which say it is a mpz_class" but in fact, is is not really a mpz_class. It is for exemple a __gmp_expr<mpz_struct, gmp_binary<__gmp_expr<mpz_struct,mpz_struct>,double,binary_plus> > or something like this. As you can see, in fact this is the result of an addition between a double and a mpz_class and it should be a mpf_class because we can see a double in this expression. But it should be more complicated otherwise gmp developper may have fix this problem isn't it?

    The solution can be to concidere long as mpf_class instead of
    But if we keep the same precision, we will lose some performance.

I agree...

    Have a good week end.
u2 !

Other related posts: