<commit_before>from sfepy.base.base import *

##
# 15.06.2006, c
# 17.07.2006
# 04.09.2006
def sort_by_dependency( graph ):

    out = []

    n_nod = len( graph )
    idone = 0
    idone0 = -1
    while idone < n_nod:

        dep_removed = 0
        for node, deps in graph.iteritems():
#            print '--', node, deps
            if (len( deps ) == 1) and not deps[0]:
                out.append( node )
                deps[0] = 1
                idone += 1
            elif not deps[0]:
#                print '--->', deps
                for ii, dep in enumerate( deps[1:] ):
                    if graph[dep][0]:
                        ir = deps.index( dep )
                        deps.pop( ir )
                        dep_removed += 1
#                print '---<', deps

##         print graph
##         print out
##         print idone, idone0, n_nod, dep_removed
##         pause()

        if (idone <= idone0) and not dep_removed:
            raise ValueError, 'circular dependency'
        idone0 = idone

    return out

##
# 15.06.2006, c
def _join( def1, op, def2 ):
    return '(' + def1 + ' ' + op + ' ' + def2 + ')'

##
# 31.10.2005, c
class Region( Struct ):

    ##
    # 14.06.2006, c
    # 15.06.2006
    # 23.02.2007
    def __init__( self, name, definition, domain, parse_def ):
        """conns, vertex_groups are links to domain data"""
        Struct.__init__( self,
                         name = name, definition = definition,
                         n_v_max = domain.shape.n_nod, domain = domain,
                         parse_def = parse_def, all_vertices = None,
                         igs = [], vertices = {}, edges = {}, faces = {},
                         cells = {}, fis = {},
                         volume = {}, surface = {}, length = {},
                         can_cells = True, must_update = True,
                         is_complete = False )

    ##
    # 15.06.2006, c
    def light_copy( self, name, parse_def ):
        return Region( name, self.definition, self.domain, parse_def )

    ##
    # c: 15.06.2006, r: 04.02.2008
    def update_groups( self, force = False ):
        """Vertices common to several groups are listed only in all of them -
        fa, ed.unique_indx contain no edge/face duplicates already."""
        if self.must_update or force:

            self.igs = []
            self.vertices = {}
            self.cells = {}

            for group in self.domain.iter_groups():
                ig = group.ig
                vv = nm.intersect1d( group.vertices, self.all_vertices )
                if len( vv ) == 0: continue

                self.igs.append( ig )
                self.vertices[ig] = vv

                if self.can_cells:
                    mask = nm.zeros( self.n_v_max, nm.int32 )
                    mask[vv] = 1

                    conn = group.conn
                    aux = nm.sum( mask[conn], 1, dtype = nm.int32 )
                    rcells = nm.where( aux == conn.shape[1] )[0]
                    self.cells[ig] = nm.asarray( rcells, dtype = nm.int32 )
        self.must_update = False

    ##
    # 15.06.2006, c
    def update_vertices( self ):
        self.all_vertices = nm.zeros( (0,), nm.int32 )
        self.vertices = {}
        for ig, group in self.domain.iter_groups( self.igs ):
            rcells = self.cells[ig]
            conn = group.conn
            nods = conn[rcells,:].ravel()
            aux = nm.unique1d( nods )
            self.vertices[ig] = aux
            self.all_vertices = nm.unique1d( nm.r_[self.all_vertices, aux] )
        
    ##
    # 15.06.2006, c
    def set_vertices( self, vertices ):

        self.all_vertices = vertices
        self.update_groups( force = True )
        self.is_complete = False

    ##
    # c: 15.06.2006, r: 14.07.2008
    def set_cells( self, cells ):

        self.igs = []
        self.cells = {}
        for ig, rcells in cells.iteritems():
            self.cells[ig] = nm.array( rcells, ndmin = 1 )
            self.igs.append( ig )
        self.update_vertices()
        self.is_complete = False
        self.must_update = False

    ##
    # 15.06.2006, c
    def set_from_group( self, ig, vertices, n_cell ):

        self.igs = [ig]
        self.cells = {ig : nm.arange( n_cell, dtype = nm.int32 )}
        self.vertices = {ig: vertices.copy()}
        self.all_vertices = vertices.copy()
        self.must_update = False

    ##
    # c: 23.02.2007, r: 22.01.2008
    def delete_groups( self, digs ):
        """self.complete_description must be called after!"""
        for ig in digs:
            try:
                del self.vertices[ig]<commit_msg>fixed Region.set_cells() for 64bit architectures<commit_after>from sfepy.base.base import *

##
# 15.06.2006, c
# 17.07.2006
# 04.09.2006
def sort_by_dependency( graph ):

    out = []

    n_nod = len( graph )
    idone = 0
    idone0 = -1
    while idone < n_nod:

        dep_removed = 0
        for node, deps in graph.iteritems():
#            print '--', node, deps
            if (len( deps ) == 1) and not deps[0]:
                out.append( node )
                deps[0] = 1
                idone += 1
            elif not deps[0]:
#                print '--->', deps
                for ii, dep in enumerate( deps[1:] ):
                    if graph[dep][0]:
                        ir = deps.index( dep )
                        deps.pop( ir )
                        dep_removed += 1
#                print '---<', deps

##         print graph
##         print out
##         print idone, idone0, n_nod, dep_removed
##         pause()

        if (idone <= idone0) and not dep_removed:
            raise ValueError, 'circular dependency'
        idone0 = idone

    return out

##
# 15.06.2006, c
def _join( def1, op, def2 ):
    return '(' + def1 + ' ' + op + ' ' + def2 + ')'

##
# 31.10.2005, c
class Region( Struct ):

    ##
    # 14.06.2006, c
    # 15.06.2006
    # 23.02.2007
    def __init__( self, name, definition, domain, parse_def ):
        """conns, vertex_groups are links to domain data"""
        Struct.__init__( self,
                         name = name, definition = definition,
                         n_v_max = domain.shape.n_nod, domain = domain,
                         parse_def = parse_def, all_vertices = None,
                         igs = [], vertices = {}, edges = {}, faces = {},
                         cells = {}, fis = {},
                         volume = {}, surface = {}, length = {},
                         can_cells = True, must_update = True,
                         is_complete = False )

    ##
    # 15.06.2006, c
    def light_copy( self, name, parse_def ):
        return Region( name, self.definition, self.domain, parse_def )

    ##
    # c: 15.06.2006, r: 04.02.2008
    def update_groups( self, force = False ):
        """Vertices common to several groups are listed only in all of them -
        fa, ed.unique_indx contain no edge/face duplicates already."""
        if self.must_update or force:

            self.igs = []
            self.vertices = {}
            self.cells = {}

            for group in self.domain.iter_groups():
                ig = group.ig
                vv = nm.intersect1d( group.vertices, self.all_vertices )
                if len( vv ) == 0: continue

                self.igs.append( ig )
                self.vertices[ig] = vv

                if self.can_cells:
                    mask = nm.zeros( self.n_v_max, nm.int32 )
                    mask[vv] = 1

                    conn = group.conn
                    aux = nm.sum( mask[conn], 1, dtype = nm.int32 )
                    rcells = nm.where( aux == conn.shape[1] )[0]
                    self.cells[ig] = nm.asarray( rcells, dtype = nm.int32 )
        self.must_update = False

    ##
    # 15.06.2006, c
    def update_vertices( self ):
        self.all_vertices = nm.zeros( (0,), nm.int32 )
        self.vertices = {}
        for ig, group in self.domain.iter_groups( self.igs ):
            rcells = self.cells[ig]
            conn = group.conn
            nods = conn[rcells,:].ravel()
            aux = nm.unique1d( nods )
            self.vertices[ig] = aux
            self.all_vertices = nm.unique1d( nm.r_[self.all_vertices, aux] )
        
    ##
    # 15.06.2006, c
    def set_vertices( self, vertices ):

        self.all_vertices = vertices
        self.update_groups( force = True )
        self.is_complete = False

    ##
    # c: 15.06.2006, r: 14.07.2008
    def set_cells( self, cells ):

        self.igs = []
        self.cells = {}
        for ig, rcells in cells.iteritems():
            self.cells[ig] = nm.array( rcells, dtype = nm.int32, ndmin = 1 )
            self.igs.append( ig )
        self.update_vertices()
        self.is_complete = False
        self.must_update = False

    ##
    # 15.06.2006, c
    def set_from_group( self, ig, vertices, n_cell ):

        self.igs = [ig]
        self.cells = {ig : nm.arange( n_cell, dtype = nm.int32 )}
        self.vertices = {ig: vertices.copy()}
        self.all_vertices = vertices.copy()
        self.must_update = False

    ##
    # c: 23.02.2007, r: 22.01.2008
    def delete_groups( self, digs ):
        """self.complete_description must be called after!"""
        for ig in digs:
            try:
                del self.vertices[ig]
{'fraction_non_alphanumeric': 0.12338010067473493, 'fraction_numerical': 0.03984149084288315, 'mean_word_length': 1.4292403746097815, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3906050', 'n_tokens_mistral': 3261, 'n_tokens_neox': 2834, 'n_words': 729}