Exemple #1
0
def pattern_filter(pattern,
                   xs,
                   report_failed=None,
                   check_errors=False,
                   range_match=False):
    ps = pattern.split(",")
    filtered_set = set([])
    for p0 in ps:
        p = p0.split("excluding")
        if (len(p) == 1):
            try:
                pstr = p[0].strip()
                p = re.compile(pstr + "$")
            except:
                sys.stderr.write("ERROR:`" + p[0].strip() +
                                 "' is not a valid regular expression ")
                if (report_failed):
                    sys.stderr.write(report_failed)
                sys.stderr.write("\n")
                exit(1)
            found = False
            for item in xs:
                if p.match(str(item)):
                    found = True
                    filtered_set.add((item, 0))
                elif range_match:
                    range_pattern = re.compile("(.*)__RANGE$")
                    m = range_pattern.match(str(item))
                    if m:
                        item_root = m.groups(0)[0]
                        item_pattern = re.compile(item_root + "_(.*)")
                        m = item_pattern.match(pstr)
                        if m:
                            n = int(m.groups(0)[0])
                            filtered_set.add((item, n))

            if check_errors and report_failed and not found:
                sys.stderr.write("Cannot match `" + p0 + "'" + report_failed +
                                 "\n")
                if check_errors:
                    exit(1)

        else:
            in_pattern = re.compile(p[0].strip())
            exc_pattern = re.compile(p[1].strip())
            in_set = set([])
            exc_set = set([])
            for item in xs:
                if in_pattern.match(str(item)):
                    in_set.add(item)
                if exc_pattern.match(str(item)):
                    exc_set.add(item)
            in_set = in_set - exc_set
            filtered_set = set.union(filtered_set, in_set)
    return list(filtered_set)
Exemple #2
0
def pattern_filter(pattern, xs, report_failed=None, check_errors=False,
                   range_match=False):
    ps = pattern.split(",")
    filtered_set = set([])
    for p0 in ps:
        p = p0.split("excluding")
        if (len(p) == 1):
            try:
                pstr = p[0].strip()
                p = re.compile(pstr + "$")
            except:
                sys.stderr.write("ERROR:`"+p[0].strip()+"' is not a valid regular expression ") 
                if (report_failed):
                    sys.stderr.write(report_failed)
                sys.stderr.write("\n")
                exit(1)
            found = False
            for item in xs:
                if p.match(str(item)):
                    found = True
                    filtered_set.add((item,0))
                elif range_match:
                    range_pattern = re.compile("(.*)__RANGE$")
                    m = range_pattern.match(str(item))
                    if m:
                        item_root = m.groups(0)[0]
                        item_pattern = re.compile(item_root + "_(.*)")
                        m = item_pattern.match(pstr)
                        if m:                            
                            n = int(m.groups(0)[0])
                            filtered_set.add((item, n))

            if check_errors and report_failed and not found:                    
                sys.stderr.write("Cannot match `" + p0 + "'" + report_failed +"\n")
                if check_errors:
                    exit(1)
                
        else:
            in_pattern = re.compile(p[0].strip())
            exc_pattern = re.compile(p[1].strip())
            in_set = set([])
            exc_set = set([])
            for item in xs:
                if in_pattern.match(str(item)):
                    in_set.add(item)
                if exc_pattern.match(str(item)):
                    exc_set.add(item)
            in_set = in_set - exc_set
            filtered_set = set.union(filtered_set, in_set)
    return list(filtered_set)
Exemple #3
0
def explore_sheep(N):
    #import pdb;pdb.set_trace()
    sN = str(N)
    sn_array = Set([sN[i] for i in range(len(sN))])
    val = len(sn_array)
    k = 1
    while (val < 10):
        k += 1
        new_N = k*N
        sn = str(new_N)
        sn_array_new = Set([sn[i] for i in range(len(sn))])
        union_set = Set.union(sn_array_new, sn_array)
        val = len(union_set)
        sn_array = union_set
    return new_N
def print_conflict_table(xmml_array, code_array, direction):
    prebuffer = " " * 6
    prebuffer_diff = "  --> "
    joint = list(set.union(set(xmml_array), set(code_array)))
    maxlen = 30  # minimum column width
    for s in joint:
        maxlen = max(maxlen, len(s))
    none = "#" * maxlen

    # just in case, probably not necessary
    joint.sort()

    if direction == IN:
        label1 = "XMML (input) "
        label2 = "Code (reads) "
    else:
        label1 = "XMML (output)"
        label2 = "Code (adds)  "

    gapf = " " * ((maxlen - 6) / 2)
    gapb = " " * (maxlen - ((maxlen - 6) / 2) - 13)
    print ""
    print "%s%s" % (prebuffer, "=" * (maxlen * 2 + 4))
    print "%s%s%s%s | %s%s" % (prebuffer, gapf, label1, gapb, gapf, label2)
    print "%s%s" % (prebuffer, "-" * (maxlen * 2 + 4))
    for f in joint:

        preb = prebuffer

        if f in xmml_array: label1 = f
        else:
            label1 = none
            preb = prebuffer_diff

        if f in code_array: label2 = f
        else:
            label2 = none
            preb = prebuffer_diff

        gap = " " * (maxlen - len(label1))
        print "%s%s%s | %s" % (preb, label1, gap, label2)
    print "%s%s" % (prebuffer, "=" * (maxlen * 2 + 4))
Exemple #5
0
def plot_obj(obj,ax=None,kwline={},kwcontact={}):
    if ax is None:
        ax = plt.gca()
    
    i = range(obj.num_vertices) + [0]
    
    plotted = []
    
    plotted.extend( ax.plot(obj.vertex_list[i,0],obj.vertex_list[i,1],'b-',**kwline) )

    plotted.extend ( ax.plot(obj.vertex_list[0,0],obj.vertex_list[0,1],'k*',**kwline) ) #to mark orientation
    
    leftcontact, bottomcontact = obj.contact_vertices()
    
    contacts = Set.union(Set(leftcontact),Set(bottomcontact))
    
    i = list(contacts)
    plotted.extend( ax.plot(obj.vertex_list[i,0],obj.vertex_list[i,1],'r.',**kwcontact))

    return plotted
Exemple #6
0
    def findNeighbors(self) :
        neighbors = []
        nEdges = 0
        for i in range(self.numElems()) :
            allNeighbors = Set()
            for v in self.elemVerts_[i] :
                allNeighbors = Set.union(allNeighbors, self.vertToElemMap_[v])
            # get rid of self-references
            allNeighbors.discard(i)
            fullNeighbors = []
            for j in allNeighbors :

                numCommonNodes = Set.intersection(self.elemVerts_[i],
                                                  self.elemVerts_[j])
                if len(numCommonNodes) == self.dim_ :
                    fullNeighbors.append(j)
                         
            nEdges = nEdges + len(fullNeighbors)
            neighbors.append(fullNeighbors)

        nEdges = nEdges/2

        return (neighbors, nEdges)
Exemple #7
0
    def findNeighbors(self):
        neighbors = []
        nEdges = 0
        for i in range(self.numElems()):
            allNeighbors = Set()
            for v in self.elemVerts_[i]:
                allNeighbors = Set.union(allNeighbors, self.vertToElemMap_[v])
            # get rid of self-references
            allNeighbors.discard(i)
            fullNeighbors = []
            for j in allNeighbors:

                numCommonNodes = Set.intersection(self.elemVerts_[i],
                                                  self.elemVerts_[j])
                if len(numCommonNodes) == self.dim_:
                    fullNeighbors.append(j)

            nEdges = nEdges + len(fullNeighbors)
            neighbors.append(fullNeighbors)

        nEdges = nEdges / 2

        return (neighbors, nEdges)
Exemple #8
0
def makeChacoGraphFile(filename) : 
    f = file(filename + '.ele')
    nodeToEleMap = {}
    elemVerts = []
    # read header 
    while 1 :
        line = f.readline()
        if line[0]=='#': continue
        header = line.split()
        nElems = int(header[0])
        d = int(header[1])-1
        break
    # read lines, building elements and the element-to-node map
    while 1:
        line = f.readline()
        if not line : break
        if line[0]=='#': continue
        toks = line.split()
        ele = int(toks[0])
        verts = Set()
        for i in range(d+1) :
            node = int(toks[i+1])
            verts.add(node)
            if nodeToEleMap.has_key(node) :
                nodeToEleMap[node].add(ele)
            else :
                nodeToEleMap[node] = Set()
                nodeToEleMap[node].add(ele)
        elemVerts.append(verts)

    # For each node, assign one of the adjoining elements as its "owner."
    # The node will later be assigned to the same processer as the owner.
    # The choice of owner is arbitrary; here, we simply choose the
    # adjoining element having the largest index.
    #
    # We write the ownership information to a file, with the format:
    # line 1: <num nodes>
    # line 2: <node 1 number> <node 1 owner>
    # etc.
    nodeOwnerFile = file(filename + '.owner', 'w')
    nodeOwnerFile.write('%d\n' % len(nodeToEleMap.keys()))
    for node in nodeToEleMap.keys() :
        owner = max(nodeToEleMap[node])
        nodeOwnerFile.write('%d %d\n' % (node, owner))


    
    
    # determine lists of neighbors for each element
    neighbors = []
    nEdges = 0
    for i in range(nElems) :
        allNeighbors = Set()
        for v in elemVerts[i] :
            allNeighbors = Set.union(allNeighbors, nodeToEleMap[v])
        # get rid of self-references
        allNeighbors.discard(i)
        fullNeighbors = []
        for j in allNeighbors :
            numCommonNodes = Set.intersection(elemVerts[i], elemVerts[j])
            if len(numCommonNodes) == d :
                fullNeighbors.append(j)
                
        nEdges = nEdges + len(fullNeighbors)
        neighbors.append(fullNeighbors)

    nEdges = nEdges/2

    graphFile = file(filename + '.graph', 'w')
    graphFile.write('%d %d\n' % (nElems, nEdges))

    for i in range(nElems) :
        line = ''
        for j in neighbors[i] :
            line = line +  '%d ' % (j+1)
        graphFile.write(line + '\n');
    graphFile.flush()

    return (elemVerts, nodeToEleMap)
        try:
            if f not in msgdst[m]: msgdst[m].append(f)
        except KeyError:
            msgdst[m] = [f]
    for m in ccode["sends"]:
        try:
            if f not in msgsrc[m]: msgsrc[m].append(f)
        except KeyError:
            msgsrc[m] = [f]

# check for message sent but not read, or vice versa (based on XMML)
msent = set(msent)  # convert to set to remove duplicates
mrecv = set(mrecv)  # convert to set to remove duplicates
csent = set(csent)  # convert to set to remove duplicates
crecv = set(crecv)  # convert to set to remove duplicates
sent = set.union(msent, csent)  # all sent messages
recv = set.union(mrecv, crecv)  # all received messages


def print_incomplete_comm_list(msg):
    global msent, mrecv, csent, crecv
    global msgsrc, msgdst
    global funclist, F

    none = " ########## NONE ##########"
    src_xmml = []
    dst_xmml = []
    src_code = []
    dst_code = []

    try:
Exemple #10
0
def makeChacoGraphFile(filename):
    f = file(filename + '.ele')
    nodeToEleMap = {}
    elemVerts = []
    # read header
    while 1:
        line = f.readline()
        if line[0] == '#': continue
        header = line.split()
        nElems = int(header[0])
        d = int(header[1]) - 1
        break
    # read lines, building elements and the element-to-node map
    while 1:
        line = f.readline()
        if not line: break
        if line[0] == '#': continue
        toks = line.split()
        ele = int(toks[0])
        verts = Set()
        for i in range(d + 1):
            node = int(toks[i + 1])
            verts.add(node)
            if nodeToEleMap.has_key(node):
                nodeToEleMap[node].add(ele)
            else:
                nodeToEleMap[node] = Set()
                nodeToEleMap[node].add(ele)
        elemVerts.append(verts)

    # For each node, assign one of the adjoining elements as its "owner."
    # The node will later be assigned to the same processer as the owner.
    # The choice of owner is arbitrary; here, we simply choose the
    # adjoining element having the largest index.
    #
    # We write the ownership information to a file, with the format:
    # line 1: <num nodes>
    # line 2: <node 1 number> <node 1 owner>
    # etc.
    nodeOwnerFile = file(filename + '.owner', 'w')
    nodeOwnerFile.write('%d\n' % len(nodeToEleMap.keys()))
    for node in nodeToEleMap.keys():
        owner = max(nodeToEleMap[node])
        nodeOwnerFile.write('%d %d\n' % (node, owner))

    # determine lists of neighbors for each element
    neighbors = []
    nEdges = 0
    for i in range(nElems):
        allNeighbors = Set()
        for v in elemVerts[i]:
            allNeighbors = Set.union(allNeighbors, nodeToEleMap[v])
        # get rid of self-references
        allNeighbors.discard(i)
        fullNeighbors = []
        for j in allNeighbors:
            numCommonNodes = Set.intersection(elemVerts[i], elemVerts[j])
            if len(numCommonNodes) == d:
                fullNeighbors.append(j)

        nEdges = nEdges + len(fullNeighbors)
        neighbors.append(fullNeighbors)

    nEdges = nEdges / 2

    graphFile = file(filename + '.graph', 'w')
    graphFile.write('%d %d\n' % (nElems, nEdges))

    for i in range(nElems):
        line = ''
        for j in neighbors[i]:
            line = line + '%d ' % (j + 1)
        graphFile.write(line + '\n')
    graphFile.flush()

    return (elemVerts, nodeToEleMap)