# Ticket #12173: slice.patch

File slice.patch, 1.8 KB (added by jpflori, 10 years ago)

Make getitem for slices faster

• ## sage/rings/polynomial/polynomial_rational_flint.pyx

```# 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 sage: g = 2/3 + t^2 sage: _ = f * g      # indirect doctest """ # Trac #12173: check that the degree is greater than 1000 before computing # the max limb size return fmpq_poly_length(op) > 0 and \ (_fmpz_vec_max_limbs(fmpq_poly_numref(op), fmpq_poly_length(op)) > 1 \ or fmpq_poly_degree(op) > 1000) (fmpq_poly_degree(op) > 1000 or _fmpz_vec_max_limbs(fmpq_poly_numref(op), fmpq_poly_length(op)) > 1) cdef class Polynomial_rational_flint(Polynomial): """ sage: f = ZZ['x']([1..10^6]) sage: g = f.change_ring(QQ) sage: g[:10]  # long time (5s on sage.math, 2012) sage: g[:10] # not long anymore thanks to trac #12173 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 """ cdef long deg cdef Polynomial_rational_flint res = self._new() cdef bint do_sig = _do_sig(self.__poly) if isinstance(n, slice): start, stop, step = n.indices(len(list(self))) start, stop, step = n.indices(self.degree() + 1) if do_sig: sig_on() fmpq_poly_get_slice(res.__poly, self.__poly, start, stop) if do_sig: sig_off()