# HG changeset patch
# User Fredrik Johansson <fredrik.johansson@gmail.com>
# Date 1324249877 0
# Node ID d41c48599d0c5cbe6ec39d30e2b8a38bfe00a23d
# Parent eff613554034a6ea4aea3fc3d72d612da8fb2253
fix interface changes between flint1 and flint2 in fmpz and fmpz_poly functions (except for fmpz_poly.pxi and the rational polynomials module, which still need updating)
diff --git a/sage/algebras/quatalg/quaternion_algebra_element.pyx b/sage/algebras/quatalg/quaternion_algebra_element.pyx
a
|
b
|
|
1988 | 1988 | # Implementation-wise, we compute the GCD's one at a time, |
1989 | 1989 | # and quit if it ever becomes one |
1990 | 1990 | |
1991 | | cdef fmpz_t content = fmpz_init(fmpz_poly_max_limbs(self.x)) # TODO: think about how big this should be (probably the size of d) |
1992 | | # Note that we have to allocate this here, and not |
1993 | | # as a global variable, because fmpz_t's do not |
1994 | | # self allocate memory |
| 1991 | cdef fmpz_t content |
| 1992 | fmpz_init(content) |
1995 | 1993 | fmpz_poly_content(content, self.x) |
1996 | | fmpz_to_mpz(U1, content) |
| 1994 | fmpz_get_mpz(U1, content) |
1997 | 1995 | mpz_gcd(U1, self.d, U1) |
1998 | 1996 | if mpz_cmp_ui(U1, 1) != 0: |
1999 | 1997 | fmpz_poly_content(content, self.y) |
2000 | | fmpz_to_mpz(U2, content) |
| 1998 | fmpz_get_mpz(U2, content) |
2001 | 1999 | mpz_gcd(U1, U1, U2) |
2002 | 2000 | if mpz_cmp_ui(U1, 1) != 0: |
2003 | 2001 | fmpz_poly_content(content, self.z) |
2004 | | fmpz_to_mpz(U2, content) |
| 2002 | fmpz_get_mpz(U2, content) |
2005 | 2003 | mpz_gcd(U1, U1, U2) |
2006 | 2004 | if mpz_cmp_ui(U1, 1) != 0: |
2007 | 2005 | fmpz_poly_content(content, self.w) |
2008 | | fmpz_to_mpz(U2, content) |
| 2006 | fmpz_get_mpz(U2, content) |
2009 | 2007 | mpz_gcd(U1, U1, U2) |
2010 | 2008 | if mpz_cmp_ui(U1, 1) != 0: |
2011 | 2009 | fmpz_poly_scalar_div_mpz(self.x, self.x, U1) |
diff --git a/sage/graphs/matchpoly.pyx b/sage/graphs/matchpoly.pyx
a
|
b
|
|
350 | 350 | """ |
351 | 351 | cdef int i, j, k, edge1, edge2, new_edge1, new_edge2, new_nedges |
352 | 352 | cdef int *edges1, *edges2, *new_edges1, *new_edges2 |
353 | | cdef fmpz_t coeff |
| 353 | cdef fmpz * coeff |
354 | 354 | |
355 | 355 | if nverts == 3: |
356 | 356 | coeff = fmpz_poly_get_coeff_ptr(pol, 3) |
357 | 357 | if coeff is NULL: |
358 | 358 | fmpz_poly_set_coeff_ui(pol, 3, 1) |
359 | 359 | else: |
360 | | fmpz_add_ui_inplace(coeff, 1) |
| 360 | fmpz_add_ui(coeff, coeff, 1) |
361 | 361 | coeff = fmpz_poly_get_coeff_ptr(pol, 1) |
362 | 362 | if coeff is NULL: |
363 | 363 | fmpz_poly_set_coeff_ui(pol, 1, nedges) |
364 | 364 | else: |
365 | | fmpz_add_ui_inplace(coeff, nedges) |
| 365 | fmpz_add_ui(coeff, coeff, nedges) |
366 | 366 | return |
367 | 367 | |
368 | 368 | if nedges == 0: |
… |
… |
|
370 | 370 | if coeff is NULL: |
371 | 371 | fmpz_poly_set_coeff_ui(pol, nverts, 1) |
372 | 372 | else: |
373 | | fmpz_add_ui_inplace(coeff, 1) |
| 373 | fmpz_add_ui(coeff, coeff, 1) |
374 | 374 | return |
375 | 375 | |
376 | 376 | edges1 = edges[2*depth] |
diff --git a/sage/libs/flint/fmpz.pxi b/sage/libs/flint/fmpz.pxi
a
|
b
|
|
1 | 1 | include "../ntl/decl.pxi" |
2 | 2 | |
3 | 3 | cdef extern from "FLINT/fmpz.h": |
4 | | |
5 | | ctypedef void * fmpz_t |
| 4 | |
| 5 | ctypedef long fmpz |
| 6 | ctypedef fmpz * fmpz_t |
6 | 7 | ctypedef void * mpz_t |
7 | 8 | |
8 | | fmpz_t fmpz_init(unsigned long limbs) |
| 9 | void fmpz_init(fmpz_t f) |
9 | 10 | void fmpz_clear(fmpz_t f) |
10 | 11 | void fmpz_print(fmpz_t f) |
11 | 12 | int fmpz_is_one(fmpz_t f) |
12 | 13 | |
13 | | void fmpz_add_ui_inplace(fmpz_t output, unsigned long x) |
14 | | void fmpz_sub_ui_inplace(fmpz_t output, unsigned long x) |
15 | | |
16 | | void fmpz_to_mpz(mpz_t rop, fmpz_t op) |
| 14 | void fmpz_add_ui(fmpz_t f, fmpz_t g, fmpz_t h) |
| 15 | void fmpz_add_si(fmpz_t f, fmpz_t g, fmpz_t h) |
| 16 | |
| 17 | void fmpz_get_mpz(mpz_t rop, fmpz_t op) |
| 18 | void fmpz_set_fmpz(fmpz_t rop, mpz_t op) |
diff --git a/sage/libs/flint/fmpz_poly.pyx b/sage/libs/flint/fmpz_poly.pyx
a
|
b
|
|
52 | 52 | cdef long c |
53 | 53 | cdef Integer w |
54 | 54 | if PY_TYPE_CHECK(v, str): |
55 | | if fmpz_poly_from_string(self.poly, v): |
| 55 | if not fmpz_poly_set_string(self.poly, v): |
56 | 56 | return |
57 | 57 | else: |
58 | 58 | raise ValueError, "Unable to create Fmpz_poly from that string." |
… |
… |
|
114 | 114 | sage: f = Fmpz_poly([0,1]); f^7 |
115 | 115 | 8 0 0 0 0 0 0 0 1 |
116 | 116 | """ |
117 | | cdef char* ss = fmpz_poly_to_string(self.poly) |
| 117 | cdef char* ss = fmpz_poly_get_str(self.poly) |
118 | 118 | cdef object s = ss |
119 | 119 | sage_free(ss) |
120 | 120 | return s |
… |
… |
|
245 | 245 | if not PY_TYPE_CHECK(self, Fmpz_poly): |
246 | 246 | raise TypeError |
247 | 247 | cdef Fmpz_poly res = <Fmpz_poly>PY_NEW(Fmpz_poly) |
248 | | fmpz_poly_power(res.poly, (<Fmpz_poly>self).poly, nn) |
| 248 | fmpz_poly_pow(res.poly, (<Fmpz_poly>self).poly, nn) |
249 | 249 | return res |
250 | 250 | |
251 | 251 | def pow_truncate(self, exp, n): |
… |
… |
|
266 | 266 | raise ValueError, "Exponent must be at least 0" |
267 | 267 | cdef long exp_c = exp, nn = n |
268 | 268 | cdef Fmpz_poly res = <Fmpz_poly>PY_NEW(Fmpz_poly) |
269 | | fmpz_poly_power_trunc_n(res.poly, (<Fmpz_poly>self).poly, exp_c, nn) |
| 269 | fmpz_poly_pow_trunc(res.poly, (<Fmpz_poly>self).poly, exp_c, nn) |
270 | 270 | return res |
271 | 271 | |
272 | 272 | def __floordiv__(left, right): |
… |
… |
|
328 | 328 | """ |
329 | 329 | cdef Fmpz_poly res = <Fmpz_poly>PY_NEW(Fmpz_poly) |
330 | 330 | |
331 | | fmpz_poly_left_shift(res.poly, self.poly, n) |
| 331 | fmpz_poly_shift_left(res.poly, self.poly, n) |
332 | 332 | |
333 | 333 | return res |
334 | 334 | |
… |
… |
|
344 | 344 | """ |
345 | 345 | cdef Fmpz_poly res = <Fmpz_poly>PY_NEW(Fmpz_poly) |
346 | 346 | |
347 | | fmpz_poly_right_shift(res.poly, self.poly, n) |
| 347 | fmpz_poly_shift_right(res.poly, self.poly, n) |
348 | 348 | |
349 | 349 | return res |
350 | 350 | |
diff --git a/sage/modular/modsym/apply.pyx b/sage/modular/modsym/apply.pyx
a
|
b
|
|
54 | 54 | fmpz_poly_set_coeff_si(self.g, 1, c) |
55 | 55 | |
56 | 56 | # h = (f**i)*(g**(j-i)) |
57 | | fmpz_poly_power(self.ff, self.f, i) |
58 | | fmpz_poly_power(self.gg, self.g, j-i) |
| 57 | fmpz_poly_pow(self.ff, self.f, i) |
| 58 | fmpz_poly_pow(self.gg, self.g, j-i) |
59 | 59 | fmpz_poly_mul(ans, self.ff, self.gg) |
60 | 60 | |
61 | 61 | return 0 |
diff --git a/sage/rings/polynomial/polynomial_integer_dense_flint.pyx b/sage/rings/polynomial/polynomial_integer_dense_flint.pyx
a
|
b
|
|
285 | 285 | sage: (123456789123456789123456789123456789123456789*t).content() |
286 | 286 | 123456789123456789123456789123456789123456789 |
287 | 287 | """ |
288 | | cdef fmpz_t c = fmpz_init(fmpz_poly_limbs(self.__poly)) |
| 288 | cdef fmpz_t c |
| 289 | fmpz_init(c) |
289 | 290 | fmpz_poly_content(c, self.__poly) |
290 | 291 | cdef Integer z = PY_NEW(Integer) |
291 | | fmpz_to_mpz(z.value, c) |
| 292 | fmpz_get_mpz(z.value, c) |
292 | 293 | fmpz_clear(c) |
293 | 294 | return z |
294 | 295 | |
… |
… |
|
662 | 663 | """ |
663 | 664 | cdef Polynomial_integer_dense_flint ss = self._new() |
664 | 665 | cdef Polynomial_integer_dense_flint tt = self._new() |
665 | | cdef unsigned long bound = fmpz_poly_resultant_bound(self.__poly, |
666 | | (<Polynomial_integer_dense_flint>right).__poly) |
667 | | cdef fmpz_t r = fmpz_init(bound/FLINT_BITS+2) |
| 666 | cdef fmpz_t r |
| 667 | fmpz_init(r) |
668 | 668 | |
669 | 669 | sig_on() |
670 | 670 | fmpz_poly_xgcd(r, ss.__poly, tt.__poly, self.__poly, |
671 | 671 | (<Polynomial_integer_dense_flint>right).__poly) |
672 | 672 | sig_off() |
673 | 673 | cdef Integer rr = PY_NEW(Integer) |
674 | | fmpz_to_mpz(rr.value, r) |
| 674 | fmpz_get_mpz(rr.value, r) |
675 | 675 | fmpz_clear(r) |
676 | 676 | |
677 | 677 | if rr.is_zero(): |
… |
… |
|
780 | 780 | return res |
781 | 781 | if exp < 0: |
782 | 782 | sig_on() |
783 | | fmpz_poly_power(res.__poly, self.__poly, -nn) |
| 783 | fmpz_poly_pow(res.__poly, self.__poly, -nn) |
784 | 784 | sig_off() |
785 | 785 | return ~res |
786 | 786 | else: |
… |
… |
|
790 | 790 | sig_off() |
791 | 791 | else: |
792 | 792 | sig_on() |
793 | | fmpz_poly_power(res.__poly, self.__poly, nn) |
| 793 | fmpz_poly_pow(res.__poly, self.__poly, nn) |
794 | 794 | sig_off() |
795 | 795 | return res |
796 | 796 | |
… |
… |
|
1106 | 1106 | |
1107 | 1107 | if not ZZ_IsOne(content): |
1108 | 1108 | fac_py = self._new() |
1109 | | tcontent = fmpz_init(ZZ_limbs(content)) |
| 1109 | fmpz_init(tcontent) |
1110 | 1110 | ZZ_to_fmpz(tcontent, content) |
1111 | 1111 | fmpz_poly_set_coeff_fmpz(fac_py.__poly, 0, tcontent) |
1112 | 1112 | results.append( (fac_py,1) ) |
… |
… |
|
1278 | 1278 | elif self.parent() is not other.parent(): |
1279 | 1279 | raise TypeError |
1280 | 1280 | |
1281 | | cdef unsigned long bound = fmpz_poly_resultant_bound(self.__poly, |
1282 | | (<Polynomial_integer_dense_flint>other).__poly) |
1283 | | cdef fmpz_t res = fmpz_init(bound/FLINT_BITS + 2) |
| 1281 | cdef fmpz_t res |
| 1282 | fmpz_init(res) |
1284 | 1283 | cdef Integer x = PY_NEW(Integer) |
1285 | 1284 | |
1286 | 1285 | sig_on() |
1287 | 1286 | fmpz_poly_resultant(res, self.__poly, |
1288 | 1287 | (<Polynomial_integer_dense_flint>other).__poly) |
1289 | 1288 | sig_off() |
1290 | | fmpz_to_mpz(x.value, res) |
| 1289 | fmpz_get_mpz(x.value, res) |
1291 | 1290 | fmpz_clear(res) |
1292 | 1291 | return x |
1293 | 1292 | |