[pythran] Re: question on slice.hpp

  • From: Pierrick Brunet <pierrick.brunet@xxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Fri, 05 Sep 2014 08:43:47 +0200

Nice website Medhi. There is a lot of pattern matching that could be done in Pythran.

Also, our formule is : int to double * 2 = [10,40] cycles, float division = [20,45],, ceil?, double_to_int = 40 =>[70-125] + ceil Neal formule is : int division = [27, 80], int add / sub = 1 cycle => [29, 82] cycles

Neal formul should be faster reading : http://agner.org/optimize/optimizing_cpp.pdf

But as state by Medhi, if it is critical, it should be compute once for all in the constructor. Do you have any code like this? I think this part of the code is only use in the len() but I didn't look at gsliced array for this.

On 05/09/2014 01:26, Mehdi Amini wrote:
Integer division is usually *slow*.
Converting an integer to a float is 1 cycle, a floating point division is 1 cycle, and integer division is 9 cycles (32 bits) or 59 to 134 cycles (64 bits).


PS: based on Ivy Bridge data from agner.org

On 9/4/14, 11:58 AM, Neal Becker wrote:
I think it is probably faster, avoiding int <-> float conversions, and potentially more accurate.

On Thu, Sep 4, 2014 at 2:56 PM, Pierrick Brunet <pierrick.brunet@xxxxxxxx <mailto:pierrick.brunet@xxxxxxxx>> wrote:

    I think it is rounded up as the slice : 1:5:3 is 2 with a roundup
    and 1 with a round down with your expression.

    It looks like your formule have the same final behavior but need
    more operation to perform it. Do you have any example where the
    current function fail?

    On 04/09/2014 20:32, Neal Becker wrote:
    In pythran/pythonic/types/slice.hpp

                long size() const
                    assert( not upper.is_none and not lower.is_none
    and not step.is_none );
                    return std::max(0L, long(ceil(double(upper -

    Maybe this should be:
    (using python code here:)

    def roundup_divide (a, b):
        return (a + b - 1) // b

    return std::max(0L, roundup_divide (upper-lower, step));

    But on the other hand, did you really mean to roundup?  Should
    the size of a slice be rounded down?

-- /Those who don't understand recursion are doomed to repeat it/

/Those who don't understand recursion are doomed to repeat it/

Other related posts: