Skip to content

Commit d5f1a18

Browse files
committed
Switch to cdef for Precision manager
Also use int for eprec and edps, -1 is a special value replacing None
1 parent 02cde3e commit d5f1a18

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/flint/flint_base/flint_context.pyx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,14 @@ cdef class FlintContext:
154154
flint_cleanup()
155155

156156

157-
class PrecisionManager:
158-
def __init__(self, ctx, eprec=None, edps=None):
159-
if eprec is not None and edps is not None:
157+
cdef class PrecisionManager:
158+
cdef FlintContext ctx
159+
cdef int eprec
160+
cdef int edps
161+
cdef int _oldprec
162+
163+
def __init__(self, ctx, eprec=-1, edps=-1):
164+
if eprec != -1 and edps != -1:
160165
raise ValueError("two different precisions requested")
161166

162167
self.ctx = ctx
@@ -170,10 +175,10 @@ class PrecisionManager:
170175
_oldprec = self.ctx.prec
171176

172177
try:
173-
if self.eprec is not None:
178+
if self.eprec != -1:
174179
self.ctx.prec = self.eprec
175180

176-
if self.edps is not None:
181+
if self.edps != -1:
177182
self.ctx.dps = self.edps
178183

179184
return func(*args, **kwargs)
@@ -185,10 +190,10 @@ class PrecisionManager:
185190
def __enter__(self):
186191
self._oldprec = self.ctx.prec
187192

188-
if self.eprec is not None:
193+
if self.eprec != -1:
189194
self.ctx.prec = self.eprec
190195

191-
if self.edps is not None:
196+
if self.edps != -1:
192197
self.ctx.dps = self.edps
193198

194199
def __exit__(self, type, value, traceback):

0 commit comments

Comments
 (0)