Ticket #10905: trac10905-efficiency_improvment.patch

File trac10905-efficiency_improvment.patch, 2.4 KB (added by ylchapuy, 10 years ago)

apply after trac_10905.patch

  • sage/graphs/base/c_graph.pyx

    # HG changeset patch
    # User YLC <y@l.c>
    # Date 1299782259 -3600
    # Node ID 407ddcc93ce72baa181c453fd219d6992158f23c
    # Parent  1202db4df8c225b23a9cee751f544671389540fc
    #10905 reviewer efficiency improvment
    
    diff -r 1202db4df8c2 -r 407ddcc93ce7 sage/graphs/base/c_graph.pyx
    a b  
    27232723    # The vertices which have already been visited
    27242724    cdef bitset_t seen
    27252725    bitset_init(seen, cg.active_vertices.size)
    2726    
     2726
    27272727    # The list of waiting vertices, the beginning and the end of the list
    27282728
    27292729    cdef unsigned short * waiting_list = <unsigned short *> sage_malloc(n*sizeof(short))
     
    27452745    cdef unsigned short * v_distances = <unsigned short *> sage_malloc(n*sizeof(short))
    27462746    cdef unsigned short * v_prec      = <unsigned short *> sage_malloc(n*sizeof(short))
    27472747
     2748    cdef dict ggbvi = gg._backend.vertex_ints
     2749    cdef dict ggbvl = gg._backend.vertex_labels
     2750
     2751    cdef list outneighbors
    27482752    for source in vertices:
    27492753        bitset_set_first_n(seen, 0)
    27502754        bitset_add(seen, source)
     
    27572761
    27582762        while waiting_beginning <= waiting_end:
    27592763            v = waiting_list[waiting_beginning]
    2760 
    2761             for u in cg.out_neighbors(v):
     2764            outneighbors = cg.out_neighbors(v)
     2765            for u in outneighbors:
    27622766                if not bitset_in(seen, u):
    27632767                    v_distances[u] = v_distances[v]+1
    27642768                    v_prec[u] = v
     
    27712775        tmp_distances = dict()
    27722776        tmp_prec = dict()
    27732777        for v in vertices:
    2774             vv = vertex_label(v, gg._backend.vertex_ints, gg._backend.vertex_labels, gg._backend._cg)
     2778            vv = vertex_label(v, ggbvi, ggbvl, cg)
    27752779
    27762780            if bitset_in(seen, v):
    2777                 tmp_prec[vv] = vertex_label(v_prec[v], gg._backend.vertex_ints, gg._backend.vertex_labels, gg._backend._cg)
     2781                tmp_prec[vv] = vertex_label(v_prec[v], ggbvi, ggbvl, cg)
    27782782                tmp_distances[vv] = v_distances[v]
    27792783            else:
    27802784                tmp_prec[vv] = None
    27812785                tmp_distances[vv] = Infinity
    27822786
    2783         vv = vertex_label(source, gg._backend.vertex_ints, gg._backend.vertex_labels, gg._backend._cg)
     2787        vv = vertex_label(source, ggbvi, ggbvl, cg)
    27842788        tmp_prec[vv] = None
    27852789        d_prec[vv] = tmp_prec
    27862790        d_distances[vv] = tmp_distances