Skip to content

Commit e92f0ba

Browse files
authored
Merge pull request #99 from videlec
Support for pari 2.13.0
2 parents 56446e3 + e76c517 commit e92f0ba

File tree

11 files changed

+419
-166
lines changed

11 files changed

+419
-166
lines changed

.travis.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ env:
1818
- PARI_VERSION=pari-2.9.5
1919
URLDIR=OLD/2.9
2020
- PARI_VERSION=pari-2.11.0
21-
URLDIR=unix
21+
URLDIR=OLD/2.11
2222
- PARI_VERSION=pari-2.11.1
23-
URLDIR=unix
23+
URLDIR=OLD/2.11
2424
- PARI_VERSION=pari-2.11.2
25-
URLDIR=unix
25+
URLDIR=OLD/2.11
2626
- PARI_VERSION=pari-2.11.3
27+
URLDIR=OLD/2.11
28+
- PARI_VERSION=pari-2.11.4
29+
URLDIR=OLD/2.11
30+
- PARI_VERSION=pari-2.13.0
2731
URLDIR=unix
28-
- PARI_VERSION=pari-2.12.0.alpha
32+
- PARI_VERSION=pari-2.12.1.beta
2933
URLDIR=unstable
3034
- PARI_VERSION=snapshot
3135
URLDIR=snapshots

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ install:
1414

1515
check:
1616
ulimit -s 8192; $(PYTHON) -u tests/rundoctest.py
17+
ulimit -s 8192; $(PYTHON) tests/test_integers.py
18+
ulimit -s 8192; $(PYTHON) tests/test_backward.py
1719

1820
dist:
1921
chmod go+rX-w -R .

autogen/args.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import unicode_literals
1616

1717
# Some replacements for reserved words
18-
replacements = {'char': 'character'}
18+
replacements = {'char': 'character', 'return': 'return_value'}
1919

2020
class PariArgument(object):
2121
"""
@@ -339,6 +339,29 @@ def c_convert_code(self):
339339
s += " {name} = precdl # Global PARI series precision\n"
340340
return s.format(name=self.name)
341341

342+
class PariArgumentGENPointer(PariArgumentObject):
343+
default = "NULL"
344+
def _typerepr(self):
345+
return "GEN*"
346+
def ctype(self):
347+
return "GEN*"
348+
def convert_code(self):
349+
"""
350+
Conversion to NULL or Gen
351+
"""
352+
s = " cdef bint _have_{name} = ({name} is not None)\n"
353+
s += " if _have_{name}:\n"
354+
s += " raise NotImplementedError(\"optional argument {name} not available\")\n"
355+
return s.format(name=self.name)
356+
def c_convert_code(self):
357+
"""
358+
Conversion Gen -> GEN
359+
"""
360+
s = " cdef GEN * {tmp} = NULL\n"
361+
return s.format(name=self.name, tmp=self.tmpname)
362+
def call_code(self):
363+
return self.tmpname
364+
342365

343366
pari_arg_types = {
344367
'G': PariArgumentGEN,
@@ -351,9 +374,9 @@ def c_convert_code(self):
351374
'p': PariArgumentPrec,
352375
'b': PariArgumentBitprec,
353376
'P': PariArgumentSeriesPrec,
377+
'&': PariArgumentGENPointer,
354378

355379
# Codes which are known but not actually supported yet
356-
'&': None,
357380
'V': None,
358381
'I': None,
359382
'E': None,

autogen/doc.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,7 @@ def get_raw_doc(function):
263263
<BLANKLINE>
264264
@[label se:cos]
265265
Cosine of @[dollar]x@[dollar].
266-
<BLANKLINE>
267-
<BLANKLINE>
268-
The library syntax is @[startcode]GEN @[startbold]gcos@[endbold](GEN x, long prec)@[endcode].
269-
<BLANKLINE>
270-
<BLANKLINE>
271-
<BLANKLINE>
266+
...
272267
>>> get_raw_doc("abcde")
273268
Traceback (most recent call last):
274269
...

autogen/parser.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .paths import pari_share
2222

2323
paren_re = re.compile(r"[(](.*)[)]")
24-
argname_re = re.compile(r"[ {]*([A-Za-z_][A-Za-z0-9_]*)")
24+
argname_re = re.compile(r"[ {]*&?([A-Za-z_][A-Za-z0-9_]*)")
2525

2626
def read_pari_desc():
2727
"""
@@ -35,9 +35,12 @@ def read_pari_desc():
3535
3636
>>> from autogen.parser import read_pari_desc
3737
>>> D = read_pari_desc()
38-
>>> D["cos"] == { 'class': 'basic',
38+
>>> Dcos = D["cos"]
39+
>>> if "description" in Dcos: _ = Dcos.pop("description")
40+
>>> Dcos.pop("doc").startswith('cosine of $x$.')
41+
True
42+
>>> Dcos == { 'class': 'basic',
3943
... 'cname': 'gcos',
40-
... 'doc': 'cosine of $x$.',
4144
... 'function': 'cos',
4245
... 'help': 'cos(x): cosine of x.',
4346
... 'prototype': 'Gp',
@@ -101,6 +104,10 @@ def parse_prototype(proto, help, initial_args=[]):
101104
>>> help = 'qfbred(x,{flag=0},{d},{isd},{sd})'
102105
>>> parse_prototype(proto, help)
103106
([GEN x, long flag=0, GEN d=NULL, GEN isd=NULL, GEN sd=NULL], GEN)
107+
>>> proto = "GD&"
108+
>>> help = "sqrtint(x,{&r})"
109+
>>> parse_prototype(proto, help)
110+
([GEN x, GEN* r=NULL], GEN)
104111
>>> parse_prototype("lp", "foo()", [str("TEST")])
105112
(['TEST', prec precision=0], long)
106113
"""

cypari2/gen.pyx

Lines changed: 27 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,14 @@ cdef extern from *:
134134
#endif
135135
136136
#if PARI_VERSION_CODE >= PARI_VERSION(2, 12, 0)
137-
#define nfbasis(x, yptr, p) nfbasis(mkvec2(x, p), yptr)
137+
#define old_nfbasis(x, yptr, p) nfbasis(mkvec2(x, p), yptr)
138+
#else
139+
#define old_nfbasis nfbasis
138140
#endif
139141
"""
140142
GEN new_nf_nfzk(GEN nf, GEN rnfeq)
141143
GEN new_nfeltup(GEN nf, GEN x, GEN zknf)
144+
GEN old_nfbasis(GEN x, GEN * y, GEN p)
142145

143146

144147
cdef class Gen(Gen_base):
@@ -2611,24 +2614,6 @@ cdef class Gen(Gen_base):
26112614
"""
26122615
return self.new_ref(gel(self.fixGEN(), 2))
26132616

2614-
def precision(x, long n=-1):
2615-
"""
2616-
Change the precision of `x` to be `n`, where `n` is an integer.
2617-
If `n` is omitted, output the real precision of `x`.
2618-
2619-
INPUT:
2620-
2621-
- ``x`` - gen
2622-
2623-
- ``n`` - (optional) int
2624-
2625-
OUTPUT: gen
2626-
"""
2627-
if n <= 0:
2628-
return precision(x.g)
2629-
sig_on()
2630-
return new_gen(precision0(x.g, n))
2631-
26322617
def round(x, bint estimate=False):
26332618
"""
26342619
round(x,estimate=False): If x is a real number, returns x rounded
@@ -3686,6 +3671,19 @@ cdef class Gen(Gen_base):
36863671
[1, 1/10000000019*x]
36873672
>>> pari(f).nfbasis(fa=[2,p]) # Equivalent with the above
36883673
[1, 1/10000000019*x]
3674+
3675+
The following alternative syntax closer to PARI/GP can be used
3676+
3677+
>>> pari.nfbasis([f, 1])
3678+
[1, x]
3679+
>>> pari.nfbasis(f)
3680+
[1, 1/10000000019*x]
3681+
>>> pari.nfbasis([f, 10**6])
3682+
[1, x]
3683+
>>> pari.nfbasis([f, "[2,2; %s,2]"%p])
3684+
[1, 1/10000000019*x]
3685+
>>> pari.nfbasis([f, [2,p]])
3686+
[1, 1/10000000019*x]
36893687
"""
36903688
cdef Gen t0
36913689
cdef GEN g0
@@ -3697,7 +3695,7 @@ cdef class Gen(Gen_base):
36973695
else:
36983696
g0 = NULL
36993697
sig_on()
3700-
return new_gen(nfbasis(self.g, NULL, g0))
3698+
return new_gen(old_nfbasis(self.g, NULL, g0))
37013699

37023700
def nfbasis_d(self, long flag=0, fa=None):
37033701
"""
@@ -3731,7 +3729,7 @@ cdef class Gen(Gen_base):
37313729
else:
37323730
g0 = NULL
37333731
sig_on()
3734-
ans = nfbasis(self.g, &disc, g0)
3732+
ans = old_nfbasis(self.g, &disc, g0)
37353733
return new_gens2(ans, disc)
37363734

37373735
def nfbasistoalg_lift(nf, x):
@@ -4115,38 +4113,6 @@ cdef class Gen(Gen_base):
41154113
sig_on()
41164114
return new_gen(factorpadic(self.g, t0.g, r))
41174115

4118-
def poldegree(self, var=None):
4119-
"""
4120-
Return the degree of this polynomial.
4121-
"""
4122-
sig_on()
4123-
n = poldegree(self.g, get_var(var))
4124-
sig_off()
4125-
return n
4126-
4127-
def polisirreducible(self):
4128-
"""
4129-
f.polisirreducible(): Returns True if f is an irreducible
4130-
non-constant polynomial, or False if f is reducible or constant.
4131-
"""
4132-
sig_on()
4133-
t = polisirreducible(self.g)
4134-
clear_stack()
4135-
return t != 0
4136-
4137-
def polroots(self, unsigned long precision=0):
4138-
"""
4139-
Complex roots of the given polynomial using Schonhage's method,
4140-
as modified by Gourdon.
4141-
"""
4142-
sig_on()
4143-
return new_gen(cleanroots(self.g, prec_bits_to_words(precision)))
4144-
4145-
def rnfisnorm(self, T, long flag=0):
4146-
cdef Gen t0 = objtogen(T)
4147-
sig_on()
4148-
return new_gen(rnfisnorm(t0.g, self.g, flag))
4149-
41504116
def ncols(self):
41514117
"""
41524118
Return the number of columns of self.
@@ -4699,20 +4665,14 @@ cpdef Gen objtogen(s):
46994665
47004666
Conversion from reals uses the real's own precision:
47014667
4702-
>>> a = pari(1.2); a, a.type()
4703-
(1.20000000000000, 't_REAL')
4704-
>>> import sys
4705-
>>> bitness = '64' if sys.maxsize > (1 << 32) else '32'
4706-
>>> a.precision() == (4 if bitness == '32' else 3)
4707-
True
4668+
>>> a = pari(1.2); a, a.type(), a.bitprecision()
4669+
(1.20000000000000, 't_REAL', 64)
47084670
47094671
Conversion from strings uses the current PARI real precision.
47104672
By default, this is 64 bits:
47114673
4712-
>>> a = pari('1.2'); a, a.type()
4713-
(1.20000000000000, 't_REAL')
4714-
>>> a.precision() == (4 if bitness == '32' else 3)
4715-
True
4674+
>>> a = pari('1.2'); a, a.type(), a.bitprecision()
4675+
(1.20000000000000, 't_REAL', 64)
47164676
47174677
Unicode and bytes work fine:
47184678
@@ -4725,11 +4685,10 @@ cpdef Gen objtogen(s):
47254685
47264686
>>> pari.set_real_precision(35) # precision in decimal digits
47274687
15
4728-
>>> a = pari('1.2'); a, a.type()
4729-
(1.2000000000000000000000000000000000, 't_REAL')
4730-
>>> bitness = '64' if sys.maxsize > (1 << 32) else '32'
4731-
>>> a.precision() == (6 if bitness == '32' else 4)
4732-
True
4688+
>>> a = pari('Pi'); a, a.type(), a.bitprecision()
4689+
(3.1415926535897932384626433832795029, 't_REAL', 128)
4690+
>>> a = pari('1.2'); a, a.type(), a.bitprecision()
4691+
(1.2000000000000000000000000000000000, 't_REAL', 128)
47334692
47344693
Set the precision to 15 digits for the remaining tests:
47354694

cypari2/pari_instance.pyx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ cdef class Pari(Pari_auto):
491491

492492
# Take 1MB as minimal stack. Use maxprime=0, which PARI will
493493
# internally increase to some small value like 65537.
494-
pari_init_opts(1000000, 0, INIT_DFTm)
494+
# (see function initprimes in src/language/forprime.c)
495+
pari_init_opts(1000000 * sizeof(long), 0, INIT_DFTm)
495496
after_resize()
496497

497498
# Disable PARI's stack overflow checking which is incompatible
@@ -557,7 +558,7 @@ cdef class Pari(Pari_auto):
557558
558559
When the PARI system is already initialized, the PARI stack is only
559560
grown if ``size`` is greater than the current stack, and the table
560-
of primes is only computed is ``maxprime`` is larger than the current
561+
of primes is only computed if ``maxprime`` is larger than the current
561562
bound.
562563
563564
Examples:
@@ -575,6 +576,11 @@ cdef class Pari(Pari_auto):
575576
>>> pari.stacksize(), pari2.stacksize()
576577
(10000000, 10000000)
577578
579+
>>> Pari().default("primelimit")
580+
500000
581+
>>> Pari(maxprime=20000).default("primelimit")
582+
20000
583+
578584
For more information about how precision works in the PARI
579585
interface, see :mod:`cypari2.pari_instance`.
580586
@@ -603,6 +609,7 @@ cdef class Pari(Pari_auto):
603609
set_pari_stack_size(size, sizemax)
604610

605611
# Increase the table of primes if needed
612+
GP_DATA.primelimit = maxprime
606613
self.init_primes(maxprime)
607614

608615
# Initialize some constants
@@ -1042,15 +1049,15 @@ cdef class Pari(Pari_auto):
10421049
>>> pari = cypari2.Pari()
10431050
>>> pari.init_primes(200000)
10441051
1045-
We make sure that ticket :trac:`11741` has been fixed::
1052+
We make sure that ticket :trac:`11741` has been fixed:
10461053
1047-
>>> pari.init_primes(2**30)
1048-
Traceback (most recent call last):
1049-
...
1050-
ValueError: Cannot compute primes beyond 436273290
1054+
>>> pari.init_primes(2**30)
1055+
Traceback (most recent call last):
1056+
...
1057+
ValueError: Cannot compute primes beyond 436273290
10511058
"""
1052-
# Hardcoded bound in PARI sources
1053-
if M > 436273290:
1059+
# Hardcoded bound in PARI sources (language/forprime.c)
1060+
if M > 436273289:
10541061
raise ValueError("Cannot compute primes beyond 436273290")
10551062

10561063
if M <= maxprime():

0 commit comments

Comments
 (0)