Ticket #3676: trac3676-cleanup2.patch

File trac3676-cleanup2.patch, 3.9 KB (added by rlm, 13 years ago)
  • sage/groups/perm_gps/partn_ref/refinement_graphs.pxd

    # HG changeset patch
    # User Robert L. Miller <rlm@rlmiller.org>
    # Date 1218045593 25200
    # Node ID a3565e4f0f9ba13547775e64edaa16dbf441bd0d
    # Parent  b1de815b82dd2e5fc79e9ef0cf70700d2cb5957c
    a few optimizations/fixes
    
    diff -r b1de815b82dd -r a3565e4f0f9b sage/groups/perm_gps/partn_ref/refinement_graphs.pxd
    a b cdef int refine_by_degree(PartitionStack 
    2424cdef int refine_by_degree(PartitionStack *, object, int *, int)
    2525cdef int compare_graphs(int *, int *, object)
    2626cdef bint all_children_are_equivalent(PartitionStack *, object)
    27 cdef int degree(PartitionStack *, CGraph, int, int, bint)
    28 cdef int sort_by_function(PartitionStack *, int, int *)
     27cdef inline int degree(PartitionStack *, CGraph, int, int, bint)
     28cdef inline int sort_by_function(PartitionStack *, int, int *)
    2929
    3030
    3131
  • sage/groups/perm_gps/partn_ref/refinement_graphs.pyx

    diff -r b1de815b82dd -r a3565e4f0f9b sage/groups/perm_gps/partn_ref/refinement_graphs.pyx
    a b def search_tree(G_in, partition, lab=Tru 
    239239    for i from 0 <= i < len(partition):
    240240        part[i] = <int *> sage_malloc((len(partition[i])+1) * sizeof(int))
    241241        if part[i] is NULL:
     242            for j from 0 <= j < i:
     243                sage_free(part[j])
     244            sage_free(part)
    242245            raise MemoryError
    243246        for j from 0 <= j < len(partition[i]):
    244247            part[i][j] = partition[i][j]
    def search_tree(G_in, partition, lab=Tru 
    251254    GS.use_indicator = 1 if use_indicator_function else 0
    252255    GS.scratch = <int *> sage_malloc( (3*G.num_verts + 1) * sizeof(int) )
    253256    if GS.scratch is NULL:
     257        for j from 0 <= j < len(partition):
     258            sage_free(part[j])
     259        sage_free(part)
    254260        raise MemoryError
    255261
    256262    output = traverse_tree(GS, part, G.num_verts, &all_children_are_equivalent, &refine_by_degree, &compare_graphs, lab, base, order)
    cdef int refine_by_degree(PartitionStack 
    360366                        cells_to_refine_by[against_index] = first_largest_subcell
    361367                        break
    362368                    against_index += 1
    363                 against_index = ctrb_len
    364369                r = current_cell
    365370                while 1:
    366371                    if r == current_cell or PS.levels[r-1] == PS.depth:
    367372                        if r != first_largest_subcell:
    368                             cells_to_refine_by[against_index] = r
    369                             against_index += 1
     373                            cells_to_refine_by[ctrb_len] = r
    370374                            ctrb_len += 1
    371375                    r += 1
    372376                    if r >= i:
    cdef bint all_children_are_equivalent(Pa 
    473477        return 1
    474478    return 0
    475479
    476 cdef int degree(PartitionStack *PS, CGraph G, int entry, int cell_index, bint reverse):
     480cdef inline int degree(PartitionStack *PS, CGraph G, int entry, int cell_index, bint reverse):
    477481    """
    478482    Returns the number of edges from the vertex corresponding to entry to
    479483    vertices in the cell corresponding to cell_index.
    cdef int degree(PartitionStack *PS, CGra 
    506510                break
    507511    return num_arcs
    508512
    509 cdef int sort_by_function(PartitionStack *PS, int start, int *degrees):
     513cdef inline int sort_by_function(PartitionStack *PS, int start, int *degrees):
    510514    """
    511515    A simple counting sort, given the degrees of vertices to a certain cell.
    512516   
    cdef int sort_by_function(PartitionStack 
    517521
    518522    """
    519523    cdef int n = PS.degree
    520     cdef int i, j, m = 2*n, max, max_location
     524    cdef int i, j, max, max_location
    521525    cdef int *counts = degrees + n, *output = degrees + 2*n + 1
    522526    for i from 0 <= i <= n:
    523527        counts[i] = 0