Skip to content

Commit 597aefd

Browse files
committed
use memory allocator in sage/combinat/designs/evenly_distributed_sets.pyx
1 parent 7764003 commit 597aefd

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

src/sage/combinat/designs/designs_pyx.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def is_group_divisible_design(groups, blocks, v, G=None, K=None, lambd=1, verbos
471471
cdef MemoryAllocator mem = MemoryAllocator()
472472
cdef unsigned short * matrix = <unsigned short *> mem.calloc(n*n, sizeof(unsigned short))
473473
if matrix is NULL:
474-
raise MemoryError
474+
raise MemoryError(f"{n}")
475475

476476
# Counts the number of occurrences of each pair of points
477477
for b in blocks:

src/sage/combinat/designs/evenly_distributed_sets.pyx

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ Classes and methods
1818

1919
cimport cython
2020

21-
from sage.categories.fields import Fields
2221
from libc.limits cimport UINT_MAX
2322
from libc.string cimport memset, memcpy
24-
25-
from cysignals.memory cimport check_malloc, check_calloc, sig_free
23+
from memory_allocator cimport MemoryAllocator
2624

2725
from sage.rings.integer cimport smallInteger
2826

27+
from sage.categories.fields import Fields
28+
29+
2930
cdef class EvenlyDistributedSetsBacktracker:
3031
r"""
3132
Set of evenly distributed subsets in finite fields.
@@ -168,17 +169,11 @@ cdef class EvenlyDistributedSetsBacktracker:
168169
cdef unsigned int * cosets # e array: cosets of differences of elts in B
169170
cdef unsigned int * t # e array: temporary variable for updates
170171

172+
# MANAGEMENT OF MEMORY
173+
cdef MemoryAllocator mem
174+
171175
def __dealloc__(self):
172-
if self.diff != NULL:
173-
sig_free(self.diff[0])
174-
sig_free(self.diff)
175-
if self.ratio != NULL:
176-
sig_free(self.ratio[0])
177-
sig_free(self.ratio)
178-
sig_free(self.min_orb)
179-
sig_free(self.B)
180-
sig_free(self.cosets)
181-
sig_free(self.t)
176+
pass
182177

183178
def __init__(self, K, k, up_to_isomorphism=True, check=False):
184179
r"""
@@ -228,20 +223,21 @@ cdef class EvenlyDistributedSetsBacktracker:
228223
self.m = (q - 1) // e
229224
self.K = K
230225

231-
self.diff = <unsigned int **> check_calloc(q, sizeof(unsigned int *))
232-
self.diff[0] = <unsigned int *> check_malloc(q*q*sizeof(unsigned int))
226+
self.mem = MemoryAllocator()
227+
self.diff = <unsigned int **> self.mem.calloc(q, sizeof(unsigned int *))
228+
self.diff[0] = <unsigned int *> self.mem.malloc(q*q*sizeof(unsigned int))
233229
for i in range(1, self.q):
234230
self.diff[i] = self.diff[i-1] + q
235231

236-
self.ratio = <unsigned int **> check_calloc(q, sizeof(unsigned int *))
237-
self.ratio[0] = <unsigned int *> check_malloc(q*q*sizeof(unsigned int))
232+
self.ratio = <unsigned int **> self.mem.calloc(q, sizeof(unsigned int *))
233+
self.ratio[0] = <unsigned int *> self.mem.malloc(q*q*sizeof(unsigned int))
238234
for i in range(1, self.q):
239235
self.ratio[i] = self.ratio[i-1] + q
240236

241-
self.B = <unsigned int *> check_malloc(k*sizeof(unsigned int))
242-
self.min_orb = <unsigned int *> check_malloc(q*sizeof(unsigned int))
243-
self.cosets = <unsigned int *> check_malloc(e*sizeof(unsigned int))
244-
self.t = <unsigned int *> check_malloc(e*sizeof(unsigned int))
237+
self.B = <unsigned int *> self.mem.malloc(k*sizeof(unsigned int))
238+
self.min_orb = <unsigned int *> self.mem.malloc(q*sizeof(unsigned int))
239+
self.cosets = <unsigned int *> self.mem.malloc(e*sizeof(unsigned int))
240+
self.t = <unsigned int *> self.mem.malloc(e*sizeof(unsigned int))
245241

246242
x = K.multiplicative_generator()
247243
list_K = []

0 commit comments

Comments
 (0)