@@ -123,8 +123,9 @@ def weight_dist(M):
123123 cdef bitset_t word
124124 cdef int i,j,k, dim= M.nrows(), deg= M.ncols()
125125 cdef list L
126- cdef int * LL = < int * > sig_malloc((deg+ 1 ) * sizeof(int ))
127- cdef bitset_s * basis = < bitset_s * > sig_malloc(dim * sizeof(bitset_s))
126+ cdef MemoryAllocator mem = MemoryAllocator()
127+ cdef int * LL = < int * > mem.malloc((deg+ 1 ) * sizeof(int ))
128+ cdef bitset_s * basis = < bitset_s * > mem.malloc(dim * sizeof(bitset_s))
128129 for i from 0 <= i < dim:
129130 bitset_init(& basis[i], deg)
130131 bitset_zero(& basis[i])
@@ -150,8 +151,6 @@ def weight_dist(M):
150151 L = [int (LL[i]) for i from 0 <= i < deg+ 1 ]
151152 for i from 0 <= i < dim:
152153 bitset_free(& basis[i])
153- sig_free(LL)
154- sig_free(basis)
155154 return L
156155
157156
@@ -785,12 +784,9 @@ cdef class BinaryCode:
785784 if self .nrows >= self .radix or self .ncols > self .radix:
786785 raise NotImplementedError (" Columns and rows are stored as ints. This code is too big." )
787786
788- self .words = < codeword * > sig_malloc( nwords * sizeof(int ) )
789- self .basis = < codeword * > sig_malloc( nrows * sizeof(int ) )
790- if self .words is NULL or self .basis is NULL :
791- if self .words is not NULL : sig_free(self .words)
792- if self .basis is not NULL : sig_free(self .basis)
793- raise MemoryError (" Memory." )
787+ self .mem = MemoryAllocator()
788+ self .words = < codeword * > self .mem.malloc(nwords * sizeof(int ))
789+ self .basis = < codeword * > self .mem.malloc(nrows * sizeof(int ))
794790 self_words = self .words
795791 self_basis = self .basis
796792
@@ -830,8 +826,7 @@ cdef class BinaryCode:
830826 self_words[combination+ other_nwords] = self_words[combination] ^ glue_word
831827
832828 def __dealloc__ (self ):
833- sig_free(self .words)
834- sig_free(self .basis)
829+ pass
835830
836831 def __reduce__ (self ):
837832 """
@@ -1279,35 +1274,15 @@ cdef class OrbitPartition:
12791274 nwords = (1 << nrows)
12801275 self .nwords = nwords
12811276 self .ncols = ncols
1282- self .wd_parent = < int * > sig_malloc(nwords * sizeof(int ))
1283- self .wd_rank = < int * > sig_malloc(nwords * sizeof(int ))
1284- self .wd_min_cell_rep = < int * > sig_malloc(nwords * sizeof(int ))
1285- self .wd_size = < int * > sig_malloc(nwords * sizeof(int ))
1286- self .col_parent = < int * > sig_malloc(ncols * sizeof(int ))
1287- self .col_rank = < int * > sig_malloc(ncols * sizeof(int ))
1288- self .col_min_cell_rep = < int * > sig_malloc(ncols * sizeof(int ))
1289- self .col_size = < int * > sig_malloc(ncols * sizeof(int ))
1290- if (self .wd_parent is NULL or self .wd_rank is NULL
1291- or self .wd_min_cell_rep is NULL or self .wd_size is NULL
1292- or self .col_parent is NULL or self .col_rank is NULL
1293- or self .col_min_cell_rep is NULL or self .col_size is NULL ):
1294- if self .wd_parent is not NULL :
1295- sig_free(self .wd_parent)
1296- if self .wd_rank is not NULL :
1297- sig_free(self .wd_rank)
1298- if self .wd_min_cell_rep is not NULL :
1299- sig_free(self .wd_min_cell_rep)
1300- if self .wd_size is not NULL :
1301- sig_free(self .wd_size)
1302- if self .col_parent is not NULL :
1303- sig_free(self .col_parent)
1304- if self .col_rank is not NULL :
1305- sig_free(self .col_rank)
1306- if self .col_min_cell_rep is not NULL :
1307- sig_free(self .col_min_cell_rep)
1308- if self .col_size is not NULL :
1309- sig_free(self .col_size)
1310- raise MemoryError (" Memory." )
1277+ self .mem = MemoryAllocator()
1278+ self .wd_parent = < int * > self .mem.malloc(nwords * sizeof(int ))
1279+ self .wd_rank = < int * > self .mem.malloc(nwords * sizeof(int ))
1280+ self .wd_min_cell_rep = < int * > self .mem.malloc(nwords * sizeof(int ))
1281+ self .wd_size = < int * > self .mem.malloc(nwords * sizeof(int ))
1282+ self .col_parent = < int * > self .mem.malloc(ncols * sizeof(int ))
1283+ self .col_rank = < int * > self .mem.malloc(ncols * sizeof(int ))
1284+ self .col_min_cell_rep = < int * > self .mem.malloc(ncols * sizeof(int ))
1285+ self .col_size = < int * > self .mem.malloc(ncols * sizeof(int ))
13111286 for word from 0 <= word < nwords:
13121287 self .wd_parent[word] = word
13131288 self .wd_rank[word] = 0
@@ -1320,14 +1295,7 @@ cdef class OrbitPartition:
13201295 self .col_size[col] = 1
13211296
13221297 def __dealloc__ (self ):
1323- sig_free(self .wd_parent)
1324- sig_free(self .wd_rank)
1325- sig_free(self .wd_min_cell_rep)
1326- sig_free(self .wd_size)
1327- sig_free(self .col_parent)
1328- sig_free(self .col_rank)
1329- sig_free(self .col_min_cell_rep)
1330- sig_free(self .col_size)
1298+ pass
13311299
13321300 def __repr__ (self ):
13331301 """
@@ -1614,44 +1582,19 @@ cdef class PartitionStack:
16141582 self .flag = (1 << (self .radix- 1 ))
16151583
16161584 # data
1617- self .wd_ents = < int * > sig_malloc(self .nwords * sizeof_int)
1618- self .wd_lvls = < int * > sig_malloc(self .nwords * sizeof_int)
1619- self .col_ents = < int * > sig_malloc(self .ncols * sizeof_int)
1620- self .col_lvls = < int * > sig_malloc(self .ncols * sizeof_int)
1585+ self .mem = MemoryAllocator()
1586+ self .wd_ents = < int * > self .mem.malloc(self .nwords * sizeof_int)
1587+ self .wd_lvls = < int * > self .mem.malloc(self .nwords * sizeof_int)
1588+ self .col_ents = < int * > self .mem.malloc(self .ncols * sizeof_int)
1589+ self .col_lvls = < int * > self .mem.malloc(self .ncols * sizeof_int)
16211590
16221591 # scratch space
1623- self .col_degs = < int * > sig_malloc( self .ncols * sizeof_int )
1624- self .col_counts = < int * > sig_malloc( self .nwords * sizeof_int )
1625- self .col_output = < int * > sig_malloc( self .ncols * sizeof_int )
1626- self .wd_degs = < int * > sig_malloc( self .nwords * sizeof_int )
1627- self .wd_counts = < int * > sig_malloc( (self .ncols+ 1 ) * sizeof_int )
1628- self .wd_output = < int * > sig_malloc( self .nwords * sizeof_int )
1629-
1630- if self .wd_ents is NULL or self .wd_lvls is NULL or self .col_ents is NULL \
1631- or self .col_lvls is NULL or self .col_degs is NULL or self .col_counts is NULL \
1632- or self .col_output is NULL or self .wd_degs is NULL or self .wd_counts is NULL \
1633- or self .wd_output is NULL :
1634- if self .wd_ents is not NULL :
1635- sig_free(self .wd_ents)
1636- if self .wd_lvls is not NULL :
1637- sig_free(self .wd_lvls)
1638- if self .col_ents is not NULL :
1639- sig_free(self .col_ents)
1640- if self .col_lvls is not NULL :
1641- sig_free(self .col_lvls)
1642- if self .col_degs is not NULL :
1643- sig_free(self .col_degs)
1644- if self .col_counts is not NULL :
1645- sig_free(self .col_counts)
1646- if self .col_output is not NULL :
1647- sig_free(self .col_output)
1648- if self .wd_degs is not NULL :
1649- sig_free(self .wd_degs)
1650- if self .wd_counts is not NULL :
1651- sig_free(self .wd_counts)
1652- if self .wd_output is not NULL :
1653- sig_free(self .wd_output)
1654- raise MemoryError (" Memory." )
1592+ self .col_degs = < int * > self .mem.malloc( self .ncols * sizeof_int )
1593+ self .col_counts = < int * > self .mem.malloc( self .nwords * sizeof_int )
1594+ self .col_output = < int * > self .mem.malloc( self .ncols * sizeof_int )
1595+ self .wd_degs = < int * > self .mem.malloc( self .nwords * sizeof_int )
1596+ self .wd_counts = < int * > self .mem.malloc( (self .ncols+ 1 ) * sizeof_int )
1597+ self .wd_output = < int * > self .mem.malloc( self .nwords * sizeof_int )
16551598
16561599 nwords = self .nwords
16571600 ncols = self .ncols
@@ -1694,17 +1637,8 @@ cdef class PartitionStack:
16941637 wd_output[k]= 0
16951638
16961639 def __dealloc__ (self ):
1697- if self .basis_locations: sig_free(self .basis_locations)
1698- sig_free(self .wd_ents)
1699- sig_free(self .wd_lvls)
1700- sig_free(self .col_ents)
1701- sig_free(self .col_lvls)
1702- sig_free(self .col_degs)
1703- sig_free(self .col_counts)
1704- sig_free(self .col_output)
1705- sig_free(self .wd_degs)
1706- sig_free(self .wd_counts)
1707- sig_free(self .wd_output)
1640+ if self .basis_locations:
1641+ sig_free(self .basis_locations)
17081642
17091643 def print_data (self ):
17101644 """
@@ -3092,80 +3026,31 @@ cdef class BinaryCodeClassifier:
30923026 self .alpha_size = self .w_gamma_size + self .radix
30933027 self .Phi_size = self .w_gamma_size/ self .radix + 1
30943028
3095- self .w_gamma = < int * > sig_malloc( self .w_gamma_size * sizeof(int ) )
3096- self .alpha = < int * > sig_malloc( self .alpha_size * sizeof(int ) )
3097- self .Phi = < unsigned int * > sig_malloc( self .Phi_size * (self .L+ 1 ) * sizeof(unsigned int ) )
3098- self .Omega = < unsigned int * > sig_malloc( self .Phi_size * self .L * sizeof(unsigned int ) )
3099- self .W = < unsigned int * > sig_malloc( self .Phi_size * self .radix * 2 * sizeof(unsigned int ) )
3100-
3101- self .base = < int * > sig_malloc( self .radix * sizeof(int ) )
3102- self .aut_gp_gens = < int * > sig_malloc( self .aut_gens_size * sizeof(int ) )
3103- self .c_gamma = < int * > sig_malloc( self .radix * sizeof(int ) )
3104- self .labeling = < int * > sig_malloc( self .radix * 3 * sizeof(int ) )
3105- self .Lambda1 = < int * > sig_malloc( self .radix * 2 * sizeof(int ) )
3106- self .Lambda2 = < int * > sig_malloc( self .radix * 2 * sizeof(int ) )
3107- self .Lambda3 = < int * > sig_malloc( self .radix * 2 * sizeof(int ) )
3108- self .v = < int * > sig_malloc( self .radix * 2 * sizeof(int ) )
3109- self .e = < int * > sig_malloc( self .radix * 2 * sizeof(int ) )
3110-
3111- if self .Phi is NULL or self .Omega is NULL or self .W is NULL or self .Lambda1 is NULL \
3112- or self .Lambda2 is NULL or self .Lambda3 is NULL or self .w_gamma is NULL \
3113- or self .c_gamma is NULL or self .alpha is NULL or self .v is NULL or self .e is NULL \
3114- or self .aut_gp_gens is NULL or self .labeling is NULL or self .base is NULL :
3115- if self .Phi is not NULL :
3116- sig_free(self .Phi)
3117- if self .Omega is not NULL :
3118- sig_free(self .Omega)
3119- if self .W is not NULL :
3120- sig_free(self .W)
3121- if self .Lambda1 is not NULL :
3122- sig_free(self .Lambda1)
3123- if self .Lambda2 is not NULL :
3124- sig_free(self .Lambda2)
3125- if self .Lambda3 is not NULL :
3126- sig_free(self .Lambda3)
3127- if self .w_gamma is not NULL :
3128- sig_free(self .w_gamma)
3129- if self .c_gamma is not NULL :
3130- sig_free(self .c_gamma)
3131- if self .alpha is not NULL :
3132- sig_free(self .alpha)
3133- if self .v is not NULL :
3134- sig_free(self .v)
3135- if self .e is not NULL :
3136- sig_free(self .e)
3137- if self .aut_gp_gens is not NULL :
3138- sig_free(self .aut_gp_gens)
3139- if self .labeling is not NULL :
3140- sig_free(self .labeling)
3141- if self .base is not NULL :
3142- sig_free(self .base)
3143- raise MemoryError (" Memory." )
3029+ self .mem = MemoryAllocator()
3030+ self .w_gamma = < int * > self .mem.malloc(self .w_gamma_size * sizeof(int ))
3031+ self .alpha = < int * > self .mem.malloc(self .alpha_size * sizeof(int ))
3032+ self .Phi = < unsigned int * > self .mem.malloc(self .Phi_size * (self .L+ 1 ) * sizeof(unsigned int ))
3033+ self .Omega = < unsigned int * > self .mem.malloc(self .Phi_size * self .L * sizeof(unsigned int ))
3034+ self .W = < unsigned int * > self .mem.malloc(self .Phi_size * self .radix * 2 * sizeof(unsigned int ))
3035+
3036+ self .base = < int * > self .mem.malloc(self .radix * sizeof(int ))
3037+ self .aut_gp_gens = < int * > self .mem.malloc(self .aut_gens_size * sizeof(int ))
3038+ self .c_gamma = < int * > self .mem.malloc(self .radix * sizeof(int ))
3039+ self .labeling = < int * > self .mem.malloc(self .radix * 3 * sizeof(int ))
3040+ self .Lambda1 = < int * > self .mem.malloc(self .radix * 2 * sizeof(int ))
3041+ self .Lambda2 = < int * > self .mem.malloc(self .radix * 2 * sizeof(int ))
3042+ self .Lambda3 = < int * > self .mem.malloc(self .radix * 2 * sizeof(int ))
3043+ self .v = < int * > self .mem.malloc(self .radix * 2 * sizeof(int ))
3044+ self .e = < int * > self .mem.malloc(self .radix * 2 * sizeof(int ))
31443045
31453046 def __dealloc__ (self ):
3146- sig_free(self .ham_wts)
3147- sig_free(self .Phi)
3148- sig_free(self .Omega)
3149- sig_free(self .W)
3150- sig_free(self .Lambda1)
3151- sig_free(self .Lambda2)
3152- sig_free(self .Lambda3)
3153- sig_free(self .c_gamma)
3154- sig_free(self .w_gamma)
3155- sig_free(self .alpha)
3156- sig_free(self .v)
3157- sig_free(self .e)
3158- sig_free(self .aut_gp_gens)
3159- sig_free(self .labeling)
3160- sig_free(self .base)
3047+ pass
31613048
31623049 cdef void record_automorphism(self , int * gamma, int ncols) noexcept:
31633050 cdef int i, j
31643051 if self .aut_gp_index + ncols > self .aut_gens_size:
31653052 self .aut_gens_size *= 2
3166- self .aut_gp_gens = < int * > sig_realloc( self .aut_gp_gens, self .aut_gens_size * sizeof(int ) )
3167- if self .aut_gp_gens is NULL :
3168- raise MemoryError (" Memory." )
3053+ self .aut_gp_gens = < int * > self .mem.realloc(self .aut_gp_gens, self .aut_gens_size * sizeof(int ))
31693054 j = self .aut_gp_index
31703055 for i from 0 <= i < ncols:
31713056 self .aut_gp_gens[i+ j] = gamma[i]
@@ -3404,23 +3289,12 @@ cdef class BinaryCodeClassifier:
34043289 self .w_gamma_size *= 2
34053290 self .alpha_size = self .w_gamma_size + self .radix
34063291 self .Phi_size = self .w_gamma_size/ self .radix + 1
3407- self .w_gamma = < int * > sig_realloc(self .w_gamma, self .w_gamma_size * sizeof(int ))
3408- self .alpha = < int * > sig_realloc(self .alpha, self .alpha_size * sizeof(int ))
3409- self .Phi = < unsigned int * > sig_realloc(self .Phi, self .Phi_size * self .L * sizeof(int ))
3410- self .Omega = < unsigned int * > sig_realloc(self .Omega, self .Phi_size * self .L * sizeof(int ))
3411- self .W = < unsigned int * > sig_realloc(self .W, self .Phi_size * self .radix * 2 * sizeof(int ))
3412- if self .w_gamma is NULL or self .alpha is NULL or self .Phi is NULL or self .Omega is NULL or self .W is NULL :
3413- if self .w_gamma is not NULL :
3414- sig_free(self .w_gamma)
3415- if self .alpha is not NULL :
3416- sig_free(self .alpha)
3417- if self .Phi is not NULL :
3418- sig_free(self .Phi)
3419- if self .Omega is not NULL :
3420- sig_free(self .Omega)
3421- if self .W is not NULL :
3422- sig_free(self .W)
3423- raise MemoryError (" Memory." )
3292+ self .w_gamma = < int * > self .mem.realloc(self .w_gamma, self .w_gamma_size * sizeof(int ))
3293+ self .alpha = < int * > self .mem.realloc(self .alpha, self .alpha_size * sizeof(int ))
3294+ self .Phi = < unsigned int * > self .mem.realloc(self .Phi, self .Phi_size * self .L * sizeof(int ))
3295+ self .Omega = < unsigned int * > self .mem.realloc(self .Omega, self .Phi_size * self .L * sizeof(int ))
3296+ self .W = < unsigned int * > self .mem.realloc(self .W, self .Phi_size * self .radix * 2 * sizeof(int ))
3297+
34243298 for i from 0 <= i < self .Phi_size * self .L:
34253299 self .Omega[i] = 0
34263300 word_gamma = self .w_gamma
0 commit comments