kerncraft/kernel.py
def global_iterator_to_indices(self, git=None):
        """
        Return sympy expressions translating global_iterator to loop indices.

        If global_iterator is given, an integer is returned
        """
        # unwind global iteration count into loop counters:
        base_loop_counters = {}
        global_iterator = symbol_pos_int('global_iterator')
        idiv = implemented_function(sympy.Function(str('idiv')), lambda x, y: x//y)
        total_length = 1
        last_incr = 1
        for var_name, start, end, incr in reversed(self._loop_stack):
            loop_var = symbol_pos_int(var_name)

            # This unspools the iterations:
            length = end-start  # FIXME is incr handled correct here?
            counter = start+(idiv(global_iterator*last_incr, total_length)*incr) % length
            total_length = total_length*length
            last_incr = incr

            base_loop_counters[loop_var] = sympy.lambdify(
                global_iterator,
                self.subs_consts(counter), modules=[numpy, {'Mod': numpy.mod}])

            if git is not None:
                try:  # Try to resolve to integer if global_iterator was given
                    base_loop_counters[loop_var] = sympy.Integer(self.subs_consts(counter))
                    continue
                except (ValueError, TypeError):
                    base_loop_counters[loop_var] = base_loop_counters[loop_var](git)

        return base_loop_counters
def global_iterator_to_indices(self, git=None):
        # unwind global iteration count into loop counters:
        base_loop_counters = {}
        global_iterator = symbol_pos_int('global_iterator')
        idiv = implemented_function(sympy.Function(str('idiv')), lambda x, y: x//y)
        total_length = 1
        last_incr = 1
        for var_name, start, end, incr in reversed(self._loop_stack):
            loop_var = symbol_pos_int(var_name)

            # This unspools the iterations:
            length = end-start  # FIXME is incr handled correct here?
            counter = start+(idiv(global_iterator*last_incr, total_length)*incr) % length
            total_length = total_length*length
            last_incr = incr

            base_loop_counters[loop_var] = sympy.lambdify(
                global_iterator,
                self.subs_consts(counter), modules=[numpy, {'Mod': numpy.mod}])

            if git is not None:
                try:  # Try to resolve to integer if global_iterator was given
                    base_loop_counters[loop_var] = sympy.Integer(self.subs_consts(counter))
                    continue
                except (ValueError, TypeError):
                    base_loop_counters[loop_var] = base_loop_counters[loop_var](git)

        return base_loop_counters
def global_iterator_to_indices ( self , git = None ) : # unwind global iteration count into loop counters: base_loop_counters = { } global_iterator = symbol_pos_int ( 'global_iterator' ) idiv = implemented_function ( sympy . Function ( str ( 'idiv' ) ) , lambda x , y : x // y ) total_length = 1 last_incr = 1 for var_name , start , end , incr in reversed ( self . _loop_stack ) : loop_var = symbol_pos_int ( var_name ) # This unspools the iterations: length = end - start # FIXME is incr handled correct here? counter = start + ( idiv ( global_iterator * last_incr , total_length ) * incr ) % length total_length = total_length * length last_incr = incr base_loop_counters [ loop_var ] = sympy . lambdify ( global_iterator , self . subs_consts ( counter ) , modules = [ numpy , { 'Mod' : numpy . mod } ] ) if git is not None : try : # Try to resolve to integer if global_iterator was given base_loop_counters [ loop_var ] = sympy . Integer ( self . subs_consts ( counter ) ) continue except ( ValueError , TypeError ) : base_loop_counters [ loop_var ] = base_loop_counters [ loop_var ] ( git ) return base_loop_counters
Return sympy expressions translating global_iterator to loop indices.

        If global_iterator is given, an integer is returned
Return sympy expressions translating global_iterator to loop indices .