Skip to content

Commit 8ad1ae6

Browse files
author
Release Manager
committed
gh-39413: Fix compilation and doctests with flintlib 3.2 Tested with flintlib 3.2-rc1. May not work with flintlib 3.1. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #39413 Reported by: Gonzalo Tornaría Reviewer(s): Gonzalo Tornaría, Tobias Diez, user202729
2 parents 2b842ce + 5e2704a commit 8ad1ae6

File tree

9 files changed

+67
-57
lines changed

9 files changed

+67
-57
lines changed

src/sage/libs/flint/flint.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ cdef extern from "flint_wrap.h":
1919
void * flint_realloc(void * ptr, size_t size) noexcept
2020
void * flint_calloc(size_t num, size_t size) noexcept
2121
void flint_free(void * ptr) noexcept
22-
flint_rand_s * flint_rand_alloc() noexcept
23-
void flint_rand_free(flint_rand_s * state) noexcept
22+
flint_rand_struct * flint_rand_alloc() noexcept
23+
void flint_rand_free(flint_rand_struct * state) noexcept
2424
void flint_randinit(flint_rand_t state) noexcept
2525
void flint_randclear(flint_rand_t state) noexcept
2626
void flint_set_num_threads(int num_threads) noexcept

src/sage/libs/flint/flint_wrap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#pragma push_macro("I")
3131
#define I Iv
3232

33+
/* flint 3.2 will rename flint_rand_s to flint_rand_struct
34+
* the following line can be removed when flint 3.1 is gone */
35+
#define flint_rand_s flint_rand_struct
36+
3337
#include <flint/flint.h>
3438

3539
/* If flint was already previously included via another header (e.g.

src/sage/libs/flint/types.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ cdef extern from "flint_wrap.h":
266266

267267

268268
# flint/flint.h
269-
ctypedef struct flint_rand_s:
269+
ctypedef struct flint_rand_struct:
270270
pass
271-
ctypedef flint_rand_s flint_rand_t[1]
271+
ctypedef flint_rand_struct flint_rand_t[1]
272272

273273
cdef long FLINT_BITS
274274
cdef long FLINT_D_BITS

src/sage/rings/complex_arb.pyx

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -788,27 +788,28 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField):
788788
...
789789
ValueError: polynomial with interval coefficients, use multiplicities=False
790790
791-
sage: (x^4 - 1/3).roots(multiplicities=False) # indirect doctest
792-
[[-0.759835685651593 +/- ...e-16] + [+/- ...e-16]*I,
793-
[0.759835685651593 +/- ...e-16] + [+/- ...e-16]*I,
794-
[+/- ...e-16] + [0.759835685651593 +/- ...e-16]*I,
795-
[+/- ...e-16] + [-0.759835685651593 +/- ...e-16]*I]
791+
sage: set((x^4 - 1/3).roots(multiplicities=False)) # indirect doctest
792+
{[+/- 1.27e-16] + [-0.759835685651593 +/- 5.90e-16]*I,
793+
[+/- 1.27e-16] + [0.759835685651593 +/- 5.90e-16]*I,
794+
[-0.759835685651593 +/- 5.90e-16] + [+/- 1.27e-16]*I,
795+
[0.759835685651593 +/- 5.90e-16] + [+/- 1.27e-16]*I}
796796
797-
sage: (x^4 - 1/3).roots(RBF, multiplicities=False)
798-
[[-0.759835685651593 +/- ...e-16], [0.759835685651593 +/- ...e-16]]
797+
sage: set((x^4 - 1/3).roots(RBF, multiplicities=False))
798+
{[-0.759835685651593 +/- 5.90e-16], [0.759835685651593 +/- 5.90e-16]}
799799
800-
sage: (x^4 - 3).roots(RealBallField(100), multiplicities=False)
801-
[[-1.316074012952492460819218901797 +/- ...e-34],
802-
[1.316074012952492460819218901797 +/- ...e-34]]
800+
sage: set((x^4 - 3).roots(RealBallField(100), multiplicities=False))
801+
{[-1.316074012952492460819218901797 +/- 9.7e-34],
802+
[1.316074012952492460819218901797 +/- 9.7e-34]}
803803
804-
sage: (x^4 - 3).roots(ComplexIntervalField(100), multiplicities=False)
804+
sage: sorted((x^4 - 3).roots(ComplexIntervalField(100),
805+
....: multiplicities=False), key=repr)
805806
[-1.31607401295249246081921890180? + 0.?e-37*I,
806-
1.31607401295249246081921890180? + 0.?e-37*I,
807807
0.?e-37 + 1.31607401295249246081921890180?*I,
808-
0.?e-37 - 1.31607401295249246081921890180?*I]
808+
0.?e-37 - 1.31607401295249246081921890180?*I,
809+
1.31607401295249246081921890180? + 0.?e-37*I]
809810
810-
sage: (x^2 - i/3).roots(ComplexBallField(2), multiplicities=False)
811-
[[+/- 0.409] + [+/- 0.409]*I, [+/- 0.409] + [+/- 0.409]*I]
811+
sage: set((x^2 - i/3).roots(ComplexBallField(2), multiplicities=False))
812+
{[+/- 0.409] + [+/- 0.409]*I, [+/- 0.409] + [+/- 0.409]*I}
812813
813814
sage: ((x - 1)^2).roots(multiplicities=False)
814815
Traceback (most recent call last):
@@ -818,8 +819,8 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField):
818819
sage: ((x - 1)^2).roots(multiplicities=False, proof=False)
819820
doctest:...
820821
UserWarning: roots may have been lost...
821-
[[1.00000000000 +/- ...e-12] + [+/- ...e-11]*I,
822-
[1.0000000000 +/- ...e-12] + [+/- ...e-12]*I]
822+
[[1.000000000... +/- ...] + [+/- ...]*I,
823+
[1.000000000... +/- ...] + [+/- ...]*I]
823824
824825
sage: pol = x^7 - 2*(1000*x - 1)^2 # Mignotte polynomial
825826
sage: pol.roots(multiplicities=False)
@@ -844,7 +845,7 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField):
844845
sage: ((x - 1)^2 + 2^(-70)*i/3).roots(RBF, multiplicities=False)
845846
Traceback (most recent call last):
846847
...
847-
ValueError: unable to determine which roots are real
848+
ValueError: ...
848849
849850
TESTS::
850851
@@ -4261,14 +4262,14 @@ cdef class ComplexBall(RingElement):
42614262
42624263
EXAMPLES::
42634264
4264-
sage: CBF(1, 1).Ei()
4265-
[1.76462598556385 +/- ...e-15] + [2.38776985151052 +/- ...e-15]*I
4265+
sage: CBF(1, 1).Ei() # abs tol 6e-15
4266+
[1.76462598556385 +/- 6.03e-15] + [2.38776985151052 +/- 4.23e-15]*I
42664267
sage: CBF(0).Ei()
4267-
nan
4268+
nan...
42684269
42694270
TESTS:
42704271
4271-
sage: CBF(Ei(I)) # abs tol 1e-16 # needs sage.symbolic
4272+
sage: CBF(Ei(I)) # abs tol 2e-15 # needs sage.symbolic
42724273
[0.337403922900968 +/- 3.76e-16] + [2.51687939716208 +/- 2.01e-15]*I
42734274
"""
42744275
cdef ComplexBall result = self._new()
@@ -4283,14 +4284,14 @@ cdef class ComplexBall(RingElement):
42834284
42844285
EXAMPLES::
42854286
4286-
sage: CBF(1, 1).Si()
4287-
[1.10422265823558 +/- ...e-15] + [0.88245380500792 +/- ...e-15]*I
4287+
sage: CBF(1, 1).Si() # abs tol 3e-15
4288+
[1.10422265823558 +/- 2.48e-15] + [0.88245380500792 +/- 3.36e-15]*I
42884289
sage: CBF(0).Si()
42894290
0
42904291
42914292
TESTS:
42924293
4293-
sage: CBF(Si(I)) # needs sage.symbolic
4294+
sage: CBF(Si(I)) # abs tol 3e-15 # needs sage.symbolic
42944295
[1.05725087537573 +/- 2.77e-15]*I
42954296
"""
42964297
cdef ComplexBall result = self._new()
@@ -4307,14 +4308,14 @@ cdef class ComplexBall(RingElement):
43074308
43084309
EXAMPLES::
43094310
4310-
sage: CBF(1, 1).Ci()
4311-
[0.882172180555936 +/- ...e-16] + [0.287249133519956 +/- ...e-16]*I
4311+
sage: CBF(1, 1).Ci() # abs tol 5e-16
4312+
[0.882172180555936 +/- 5.89e-16] + [0.287249133519956 +/- 3.37e-16]*I
43124313
sage: CBF(0).Ci()
43134314
nan + nan*I
43144315
43154316
TESTS:
43164317
4317-
sage: CBF(Ci(I)) # abs tol 1e-17 # needs sage.symbolic
4318+
sage: CBF(Ci(I)) # abs tol 5e-16 # needs sage.symbolic
43184319
[0.837866940980208 +/- 4.72e-16] + [1.570796326794897 +/- 5.54e-16]*I
43194320
"""
43204321
cdef ComplexBall result = self._new()
@@ -4331,8 +4332,8 @@ cdef class ComplexBall(RingElement):
43314332
43324333
EXAMPLES::
43334334
4334-
sage: CBF(1, 1).Shi()
4335-
[0.88245380500792 +/- ...e-15] + [1.10422265823558 +/- ...e-15]*I
4335+
sage: CBF(1, 1).Shi() # abs tol 3e-15
4336+
[0.88245380500792 +/- 3.36e-15] + [1.10422265823558 +/- 2.48e-15]*I
43364337
sage: CBF(0).Shi()
43374338
0
43384339
@@ -4355,14 +4356,14 @@ cdef class ComplexBall(RingElement):
43554356
43564357
EXAMPLES::
43574358
4358-
sage: CBF(1, 1).Chi()
4359-
[0.882172180555936 +/- ...e-16] + [1.28354719327494 +/- ...e-15]*I
4359+
sage: CBF(1, 1).Chi() # abs tol 1e-15
4360+
[0.882172180555936 +/- 5.89e-16] + [1.28354719327494 +/- 1.01e-15]*I
43604361
sage: CBF(0).Chi()
43614362
nan + nan*I
43624363
43634364
TESTS:
43644365
4365-
sage: CBF(Chi(I)) # abs tol 1e-16 # needs sage.symbolic
4366+
sage: CBF(Chi(I)) # abs tol 5e-16 # needs sage.symbolic
43664367
[0.337403922900968 +/- 3.25e-16] + [1.570796326794897 +/- 5.54e-16]*I
43674368
"""
43684369
cdef ComplexBall result = self._new()
@@ -4381,8 +4382,8 @@ cdef class ComplexBall(RingElement):
43814382
43824383
EXAMPLES::
43834384
4384-
sage: CBF(1, 1).li()
4385-
[0.61391166922120 +/- ...e-15] + [2.05958421419258 +/- ...e-15]*I
4385+
sage: CBF(1, 1).li() # abs tol 6e-15
4386+
[0.61391166922120 +/- 6.23e-15] + [2.05958421419258 +/- 5.59e-15]*I
43864387
sage: CBF(0).li()
43874388
0
43884389
sage: CBF(0).li(offset=True)

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8451,19 +8451,19 @@ cdef class Polynomial(CommutativePolynomial):
84518451
84528452
sage: # needs sage.libs.flint
84538453
sage: Pol.<x> = CBF[]
8454-
sage: (x^2 + 2).roots(multiplicities=False)
8455-
[[+/- ...e-19] + [-1.414213562373095 +/- ...e-17]*I,
8456-
[+/- ...e-19] + [1.414213562373095 +/- ...e-17]*I]
8454+
sage: set((x^2 + 2).roots(multiplicities=False))
8455+
{[+/- ...e-19] + [-1.414213562373095 +/- ...e-17]*I,
8456+
[+/- ...e-19] + [1.414213562373095 +/- ...e-17]*I}
84578457
sage: (x^3 - 1/2).roots(RBF, multiplicities=False)
84588458
[[0.7937005259840997 +/- ...e-17]]
84598459
sage: ((x - 1)^2).roots(multiplicities=False, proof=False)
84608460
doctest:...
84618461
UserWarning: roots may have been lost...
8462-
[[1.00000000000 +/- ...e-12] + [+/- ...e-11]*I,
8463-
[1.0000000000 +/- ...e-12] + [+/- ...e-12]*I]
8462+
[[1.000000000... +/- ...] + [+/- ...]*I,
8463+
[1.000000000... +/- ...] + [+/- ...]*I]
84648464
sage: ((x - 1)^2).roots(multiplicities=False, proof=False, warn=False)
8465-
[[1.00000000000 +/- ...e-12] + [+/- ...e-11]*I,
8466-
[1.0000000000 +/- ...e-12] + [+/- ...e-12]*I]
8465+
[[1.000000000... +/- ...] + [+/- ...]*I,
8466+
[1.000000000... +/- ...] + [+/- ...]*I]
84678467
84688468
Note that coefficients in a number field with defining polynomial
84698469
`x^2 + 1` are considered to be Gaussian rationals (with the

src/sage/rings/real_arb.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3531,12 +3531,12 @@ cdef class RealBall(RingElement):
35313531
35323532
EXAMPLES::
35333533
3534-
sage: RBF(1).Ei() # abs tol 5e-16
3534+
sage: RBF(1).Ei() # abs tol 5e-15
35353535
[1.89511781635594 +/- 4.94e-15]
35363536
35373537
TESTS::
35383538
3539-
sage: RBF(Ei(1)) # abs tol 5e-16 # needs sage.symbolic
3539+
sage: RBF(Ei(1)) # abs tol 5e-15 # needs sage.symbolic
35403540
[1.89511781635594 +/- 4.94e-15]
35413541
"""
35423542
cdef RealBall res = self._new()
@@ -3595,12 +3595,12 @@ cdef class RealBall(RingElement):
35953595
35963596
EXAMPLES::
35973597
3598-
sage: RBF(1).Shi()
3598+
sage: RBF(1).Shi() # abs tol 5e-15
35993599
[1.05725087537573 +/- 2.77e-15]
36003600
36013601
TESTS::
36023602
3603-
sage: RBF(Shi(1)) # needs sage.symbolic
3603+
sage: RBF(Shi(1)) # abs tol 5e-15 # needs sage.symbolic
36043604
[1.05725087537573 +/- 2.77e-15]
36053605
"""
36063606
cdef RealBall res = self._new()
@@ -3617,12 +3617,12 @@ cdef class RealBall(RingElement):
36173617
36183618
EXAMPLES::
36193619
3620-
sage: RBF(1).Chi() # abs tol 1e-17
3620+
sage: RBF(1).Chi() # abs tol 5e-16
36213621
[0.837866940980208 +/- 4.72e-16]
36223622
36233623
TESTS::
36243624
3625-
sage: RBF(Chi(1)) # abs tol 1e-17 # needs sage.symbolic
3625+
sage: RBF(Chi(1)) # abs tol 5e-16 # needs sage.symbolic
36263626
[0.837866940980208 +/- 4.72e-16]
36273627
"""
36283628
cdef RealBall res = self._new()
@@ -3639,14 +3639,14 @@ cdef class RealBall(RingElement):
36393639
36403640
EXAMPLES::
36413641
3642-
sage: RBF(3).li() # abs tol 1e-15
3642+
sage: RBF(3).li() # abs tol 5e-15
36433643
[2.16358859466719 +/- 4.72e-15]
36443644
36453645
TESTS::
36463646
36473647
sage: RBF(li(0)) # needs sage.symbolic
36483648
0
3649-
sage: RBF(Li(0)) # needs sage.symbolic
3649+
sage: RBF(Li(0)) # abs tol 5e-15 # needs sage.symbolic
36503650
[-1.04516378011749 +/- 4.23e-15]
36513651
"""
36523652
cdef RealBall res = self._new()
@@ -3663,7 +3663,7 @@ cdef class RealBall(RingElement):
36633663
36643664
EXAMPLES::
36653665
3666-
sage: RBF(3).Li() # abs tol 1e-15
3666+
sage: RBF(3).Li() # abs tol 5e-15
36673667
[1.11842481454970 +/- 7.61e-15]
36683668
"""
36693669
cdef RealBall res = self._new()

src/sage/symbolic/ginac/numeric.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
#define PY_SSIZE_T_CLEAN
5353
#include <Python.h>
54+
#include "gmp.h"
5455
#include "flint/fmpz.h"
5556
#include "flint/fmpz_factor.h"
5657

src/sage_setup/autogen/flint/templates/flint_wrap.h.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#pragma push_macro("I")
3131
#define I Iv
3232

33+
/* flint 3.2 will rename flint_rand_s to flint_rand_struct
34+
* the following line can be removed when flint 3.1 is gone */
35+
#define flint_rand_s flint_rand_struct
36+
3337
#include <flint/flint.h>
3438

3539
/* If flint was already previously included via another header (e.g.

src/sage_setup/autogen/flint/templates/types.pxd.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ cdef extern from "flint_wrap.h":
269269

270270

271271
# flint/flint.h
272-
ctypedef struct flint_rand_s:
272+
ctypedef struct flint_rand_struct:
273273
pass
274-
ctypedef flint_rand_s flint_rand_t[1]
274+
ctypedef flint_rand_struct flint_rand_t[1]
275275
ctypedef enum flint_err_t:
276276
# flint_autogen.py does not support parsing .. enum:: yet
277277
FLINT_ERROR

0 commit comments

Comments
 (0)