Changeset 7120:4a840961f7af


Ignore:
Timestamp:
10/21/07 18:17:26 (6 years ago)
Author:
Robert L Miller <rlm@…>
Branch:
default
Message:

graph_isom memory management cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/graphs/graph_isom.pyx

    r7119 r7120  
    12061206    cdef int *gamma # for storing permutations 
    12071207    cdef int *alpha # for storing pointers to cells of nu[k]: 
    1208                      # allocated to be length 4*n for scratch (see functions 
     1208                     # allocated to be length 4*n + 1 for scratch (see functions 
    12091209                     # _sort_by_function and _refine_by_square_matrix) 
    12101210    cdef int *v # list of vertices determining nu 
     
    12481248    Pi = Pi2 
    12491249 
    1250     # allocate pointers 
    1251     W = <int **> sage_malloc( 2 * (n + L) * sizeof(int *) ) 
    1252     if not W: 
    1253         raise MemoryError("Error allocating memory. Perhaps you are out?") 
    1254     M = W + n 
    1255     Phi = W + 2*n 
    1256     Omega = W + 2*n + L 
    1257      
    1258     # allocate pointers for GMP ints 
    1259     Lambda_mpz = <mpz_t *> sage_malloc( 3 * (n+2) * sizeof(mpz_t) ) 
    1260     if not Lambda_mpz: 
     1250    # allocate int pointers 
     1251    W = <int **> sage_malloc( n * sizeof(int *) ) 
     1252    M = <int **> sage_malloc( n * sizeof(int *) ) 
     1253    Phi = <int **> sage_malloc( L * sizeof(int *) ) 
     1254    Omega = <int **> sage_malloc( L * sizeof(int *) ) 
     1255     
     1256    # allocate GMP int pointers 
     1257    Lambda_mpz = <mpz_t *> sage_malloc( (n+2) * sizeof(mpz_t) ) 
     1258    zf_mpz = <mpz_t *> sage_malloc( (n+2) * sizeof(mpz_t) ) 
     1259    zb_mpz = <mpz_t *> sage_malloc( (n+2) * sizeof(mpz_t) ) 
     1260     
     1261    # check for memory errors 
     1262    if not (W and M and Phi and Omega and Lambda_mpz and zf_mpz and zb_mpz): 
     1263        sage_free(Lambda_mpz) 
     1264        sage_free(zf_mpz) 
     1265        sage_free(zb_mpz) 
    12611266        sage_free(W) 
    1262         raise MemoryError("Error allocating memory. Perhaps you are out?") 
    1263     zf_mpz = Lambda_mpz + n + 2 
    1264     zb_mpz = Lambda_mpz + 2*n + 4 
    1265      
    1266     # allocate arrays 
    1267     gamma = <int *> sage_malloc( ( n * ( 2 * (n + L) + 7 ) + 1 ) * sizeof(int) ) 
    1268     if not gamma: 
     1267        sage_free(M) 
     1268        sage_free(Phi) 
     1269        sage_free(Omega) 
     1270        raise MemoryError("Error allocating memory.") 
     1271     
     1272    # allocate int arrays 
     1273    gamma = <int *> sage_malloc( n * sizeof(int) ) 
     1274    W[0] = <int *> sage_malloc( (n*n) * sizeof(int) ) 
     1275    M[0] = <int *> sage_malloc( (n*n) * sizeof(int) ) 
     1276    Phi[0] = <int *> sage_malloc( (L*n) * sizeof(int) ) 
     1277    Omega[0] = <int *> sage_malloc( (L*n) * sizeof(int) ) 
     1278    alpha = <int *> sage_malloc( (4*n + 1) * sizeof(int) ) 
     1279    v = <int *> sage_malloc( n * sizeof(int) ) 
     1280    e = <int *> sage_malloc( n * sizeof(int) ) 
     1281 
     1282    # check for memory errors 
     1283    if not (gamma and W[0] and M[0] and Phi[0] and Omega[0] and alpha and v and e): 
     1284        sage_free(gamma) 
     1285        sage_free(W[0]) 
     1286        sage_free(M[0]) 
     1287        sage_free(Phi[0]) 
     1288        sage_free(Omega[0]) 
     1289        sage_free(alpha) 
     1290        sage_free(v) 
     1291        sage_free(e) 
     1292        sage_free(Lambda_mpz) 
     1293        sage_free(zf_mpz) 
     1294        sage_free(zb_mpz) 
    12691295        sage_free(W) 
    1270         sage_free(Lambda_mpz) 
    1271         raise MemoryError("Error allocating memory. Perhaps you are out?") 
    1272     alpha = gamma + n*( 2*(n + L) + 1 ) 
    1273     v = alpha + 4*n + 1 
    1274     e = v + n 
    1275     for i from 0 <= i < n: 
    1276         W[i] = gamma + n + n*i 
    1277         M[i] = gamma + n*( 1 + n + 2*L + i ) 
     1296        sage_free(M) 
     1297        sage_free(Phi) 
     1298        sage_free(Omega) 
     1299        raise MemoryError("Error allocating memory.") 
     1300 
     1301    # setup double index arrays 
     1302    for i from 0 < i < n: 
     1303        W[i] = W[0] + n*i 
     1304    for i from 0 < i < n: 
     1305        M[i] = M[0] + n*i 
     1306    for i from 0 < i < L: 
     1307        Phi[i] = Phi[0] + n*i 
     1308    for i from 0 < i < L: 
     1309        Omega[i] = Omega[0] + n*i 
    12781310     
    12791311    # allocate GMP ints 
     
    12841316        # Note that there is a potential memory leak here - if a particular 
    12851317        # mpz fails to allocate, this is not checked for 
    1286     for i from 0 <= i < L: 
    1287         Phi[i] = gamma + n*( 1 + n + i ) 
    1288         Omega[i] = gamma + n*( 1 + n + i + L ) 
    1289      
    1290     # create the dense boolean matrix 
     1318     
     1319    # initialize M and W 
    12911320    for i from 0 <= i < n: 
    12921321        for j from 0 <= j < n: 
     
    17491778            state = 13 
    17501779             
    1751     # deallocate the MP integers 
     1780    # free the GMP ints 
    17521781    for i from 0 <= i < n: 
    17531782        mpz_clear(Lambda_mpz[i]) 
     
    17551784        mpz_clear(zb_mpz[i]) 
    17561785 
     1786    # free int arrays 
     1787    sage_free(gamma) 
     1788    sage_free(W[0]) 
     1789    sage_free(M[0]) 
     1790    sage_free(Phi[0]) 
     1791    sage_free(Omega[0]) 
     1792    sage_free(alpha) 
     1793    sage_free(v) 
     1794    sage_free(e) 
     1795     
     1796    # free GMP int pointers 
     1797    sage_free(Lambda_mpz) 
     1798    sage_free(zf_mpz) 
     1799    sage_free(zb_mpz) 
     1800     
     1801    # free int pointers 
    17571802    sage_free(W) 
    1758     sage_free(Lambda_mpz) 
    1759     sage_free(gamma) 
     1803    sage_free(M) 
     1804    sage_free(Phi) 
     1805    sage_free(Omega) 
    17601806     
    17611807    # use to and from mappings to relabel vertices back from the set {0,...,n-1} 
Note: See TracChangeset for help on using the changeset viewer.