Skip to content

Commit 298bc5c

Browse files
committed
Various minor fixes
1 parent 1f3fca2 commit 298bc5c

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

autogen/args.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ def _typerepr(self):
7171
"""
7272
return "(generic)"
7373

74+
def ctype(self):
75+
"""
76+
The corresponding C type. This is used for auto-generating
77+
the declarations of the C function. In some cases, this is also
78+
used for passing the argument from Python to Cython.
79+
"""
80+
raise NotImplementedError
81+
7482
def always_default(self):
7583
"""
7684
If this returns not ``None``, it is a value which is always
@@ -156,9 +164,6 @@ class PariArgumentClass(PariArgument):
156164
157165
The C/Cython type is given by ``self.ctype()``.
158166
"""
159-
def ctype(self):
160-
raise NotImplementedError
161-
162167
def prototype_code(self):
163168
"""
164169
Return code to appear in the prototype of the Cython wrapper.

autogen/generator.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def can_handle_function(self, function, cname="", **kwds):
136136
return False
137137
return True
138138

139-
def handle_pari_function(self, function, cname="", prototype="", help="", obsolete=None, **kwds):
139+
def handle_pari_function(self, function, cname, prototype="", help="", obsolete=None, **kwds):
140140
r"""
141141
Handle one PARI function: decide whether or not to add the
142142
function, in which file (as method of :class:`Gen` or
@@ -155,6 +155,7 @@ def handle_pari_function(self, function, cname="", prototype="", help="", obsole
155155
... cname="bnfinit0", prototype="GD0,L,DGp",
156156
... help=r"bnfinit(P,{flag=0},{tech=[]}): compute...",
157157
... **{"class":"basic", "section":"number_fields"})
158+
GEN bnfinit0(GEN, long, GEN, long)
158159
def bnfinit(P, long flag=0, tech=None, long precision=0):
159160
...
160161
cdef GEN _P = P.g
@@ -172,7 +173,7 @@ def bnfinit(P, long flag=0, tech=None, long precision=0):
172173
... cname="ellmodulareqn", prototype="LDnDn",
173174
... help=r"ellmodulareqn(N,{x},{y}): return...",
174175
... **{"class":"basic", "section":"elliptic_curves"})
175-
GEN ellmodulareqn(long N, long x, long y)
176+
GEN ellmodulareqn(long, long, long)
176177
def ellmodulareqn(self, long N, x=None, y=None):
177178
...
178179
cdef long _x = -1
@@ -190,6 +191,7 @@ def ellmodulareqn(self, long N, x=None, y=None):
190191
... help=r"setrand(n): reset the seed...",
191192
... doc=r"reseeds the random number generator...",
192193
... **{"class":"basic", "section":"programming/specific"})
194+
void setrand(GEN)
193195
def setrand(n):
194196
r'''
195197
Reseeds the random number generator using the seed :math:`n`. No value is
@@ -209,7 +211,7 @@ def setrand(n):
209211
... help="bernvec(x): this routine is obsolete, use bernfrac repeatedly.",
210212
... obsolete="2007-03-30",
211213
... **{"class":"basic", "section":"transcendental"})
212-
GEN bernvec(long x)
214+
GEN bernvec(long)
213215
def bernvec(self, long x):
214216
r'''
215217
This routine is obsolete, kept for backward compatibility only.
@@ -221,32 +223,43 @@ def bernvec(self, long x):
221223
return new_gen(_ret)
222224
<BLANKLINE>
223225
"""
224-
if not cname:
225-
raise ValueError('function {} has no associated C name'.format(function))
226226
try:
227227
args, ret = parse_prototype(prototype, help)
228228
except NotImplementedError:
229229
return # Skip unsupported prototype codes
230230

231231
doc = get_rest_doc(function)
232232

233+
self.write_declaration(cname, args, ret, self.decl_file)
234+
233235
if len(args) > 0 and isinstance(args[0], PariArgumentGEN):
234236
# If the first argument is a GEN, write a method of the
235237
# Gen class.
236238
self.write_method(function, cname, args, ret, args,
237239
self.gen_file, doc, obsolete)
238240

239-
# In any case, write a declaration and a method of the Pari class.
240-
self.write_header(cname, args, ret, self.decl_file)
241-
241+
# In any case, write a method of the Pari class.
242242
# Parse again with an extra "self" argument.
243243
args, ret = parse_prototype(prototype, help, [PariInstanceArgument()])
244244
self.write_method(function, cname, args, ret, args[1:],
245245
self.instance_file, doc, obsolete)
246246

247-
def write_header(self, cname, args, ret, file):
248-
args = ", ".join('{} {}'.format(a.ctype(), a.name) for a in args)
249-
print(' {ret} {function}({args})'.format(ret=ret.ctype(), function=cname, args=args), file=file)
247+
def write_declaration(self, cname, args, ret, file):
248+
"""
249+
Write a .pxd declaration of a PARI library function.
250+
251+
INPUT:
252+
253+
- ``cname`` -- name of the PARI C library call
254+
255+
- ``args``, ``ret`` -- output from ``parse_prototype``
256+
257+
- ``file`` -- a file object where the declaration should be
258+
written to
259+
"""
260+
args = ", ".join(a.ctype() for a in args)
261+
s = ' {ret} {function}({args})'.format(ret=ret.ctype(), function=cname, args=args)
262+
print(s, file=file)
250263

251264
def write_method(self, function, cname, args, ret, cargs, file, doc, obsolete):
252265
"""

0 commit comments

Comments
 (0)