# HG changeset patch
# User Jean-Pierre Flori <jean-pierre.flor@ssi.gouv.fr>
# Date 1338995192 -7200
# Node ID 0e54bdd5e7ffdb6a1af41950eed4031e7a1e7353
# Parent cf7dd793632be4de03ca3621bbe4da44aa29706d
#12173: Make __getitem__ for slices faster
diff --git a/sage/rings/polynomial/polynomial_rational_flint.pyx b/sage/rings/polynomial/polynomial_rational_flint.pyx
a
|
b
|
|
61 | 61 | sage: g = 2/3 + t^2 |
62 | 62 | sage: _ = f * g # indirect doctest |
63 | 63 | """ |
| 64 | # Trac #12173: check that the degree is greater than 1000 before computing |
| 65 | # the max limb size |
64 | 66 | return fmpq_poly_length(op) > 0 and \ |
65 | | (_fmpz_vec_max_limbs(fmpq_poly_numref(op), fmpq_poly_length(op)) > 1 \ |
66 | | or fmpq_poly_degree(op) > 1000) |
| 67 | (fmpq_poly_degree(op) > 1000 or |
| 68 | _fmpz_vec_max_limbs(fmpq_poly_numref(op), fmpq_poly_length(op)) > 1) |
67 | 69 | |
68 | 70 | cdef class Polynomial_rational_flint(Polynomial): |
69 | 71 | """ |
… |
… |
|
189 | 191 | |
190 | 192 | sage: f = ZZ['x']([1..10^6]) |
191 | 193 | sage: g = f.change_ring(QQ) |
192 | | sage: g[:10] # long time (5s on sage.math, 2012) |
| 194 | sage: g[:10] # not long anymore thanks to trac #12173 |
193 | 195 | 10*x^9 + 9*x^8 + 8*x^7 + 7*x^6 + 6*x^5 + 5*x^4 + 4*x^3 + 3*x^2 + 2*x + 1 |
194 | 196 | """ |
195 | 197 | cdef long deg |
… |
… |
|
390 | 392 | cdef Polynomial_rational_flint res = self._new() |
391 | 393 | cdef bint do_sig = _do_sig(self.__poly) |
392 | 394 | if isinstance(n, slice): |
393 | | start, stop, step = n.indices(len(list(self))) |
| 395 | start, stop, step = n.indices(self.degree() + 1) |
394 | 396 | if do_sig: sig_on() |
395 | 397 | fmpq_poly_get_slice(res.__poly, self.__poly, start, stop) |
396 | 398 | if do_sig: sig_off() |