Ticket #12173: compose_eval.patch

File compose_eval.patch, 5.6 KB (added by jpflori, 10 years ago)

Take #10617 into account

  • sage/libs/flint/fmpz.pxi

    # HG changeset patch
    # User Jean-Pierre Flori <jean-pierre.flori@ssi.gouv.fr>
    # Date 1341325684 14400
    # Node ID c64a79af8e3d7da61ef811ee5a64860590ffb67b
    # Parent  f56b53b2570206522e01855c176985a3ccd4cc9a
    #12173: Rebase on #10617
    
    diff --git a/sage/libs/flint/fmpz.pxi b/sage/libs/flint/fmpz.pxi
    a b  
    22
    33cdef extern from "flint/fmpz.h":
    44
    5     ctypedef long fmpz   
     5    ctypedef long fmpz
    66    ctypedef long * fmpz_t
    77    ctypedef void * mpz_t
    88
     
    1010
    1111    void fmpz_set_ui(fmpz_t res, unsigned long x)
    1212    void fmpz_set_si(fmpz_t res, long x)
    13    
     13
    1414    void fmpz_clear(fmpz_t f)
    1515    void fmpz_print(fmpz_t f)
    1616    int fmpz_is_one(fmpz_t f)
    17    
     17
    1818    void fmpz_get_mpz(mpz_t rop, fmpz_t op)
    1919    void fmpz_set_mpz(fmpz_t rop, mpz_t op)
    2020
    2121    void fmpz_add_ui(fmpz_t f, fmpz_t g, unsigned long c)
    22 
    23     void mpz_to_fmpz(fmpz_t rop, mpz_t op)
    24 
  • sage/libs/flint/fmpz_poly.pxi

    diff --git a/sage/libs/flint/fmpz_poly.pxi b/sage/libs/flint/fmpz_poly.pxi
    a b  
    108108
    109109    void fmpz_poly_invmod(fmpz_t d, fmpz_poly_t H, fmpz_poly_t poly1, fmpz_poly_t poly2)
    110110    void fmpz_poly_derivative(fmpz_poly_t der, fmpz_poly_t poly)
    111     void fmpz_poly_evaluate(fmpz_t output, fmpz_poly_t poly, fmpz_t val)
     111    void fmpz_poly_evaluate_fmpz(fmpz_t output, fmpz_poly_t poly, fmpz_t val)
    112112    void fmpz_poly_compose(fmpz_poly_t output, fmpz_poly_t f, fmpz_poly_t g)
    113113    void fmpz_poly_scalar_div_ui(fmpz_poly_t output, fmpz_poly_t poly, unsigned long x)
    114114
  • sage/rings/polynomial/polynomial_integer_dense_flint.pyx

    diff --git a/sage/rings/polynomial/polynomial_integer_dense_flint.pyx b/sage/rings/polynomial/polynomial_integer_dense_flint.pyx
    a b  
    260260
    261261    def __call__(self, *x, **kwds):
    262262        """
    263         Calls this polynomial with the given parameters, which can be 
    264         interpreted as polynomial composition or evaluation by this 
     263        Calls this polynomial with the given parameters, which can be
     264        interpreted as polynomial composition or evaluation by this
    265265        method.
    266266
    267         If the argument is not simply an integer (``int``, ``long`` or 
    268         ``Integer``) or a polynomial (of the same type as ``self``), 
    269         the call is passed on to the generic implementation in the 
     267        If the argument is not simply an integer (``int``, ``long`` or
     268        ``Integer``) or a polynomial (of the same type as ``self``),
     269        the call is passed on to the generic implementation in the
    270270        ``Polynomial`` class.
    271271
    272272        EXAMPLES:
    273273
    274274        The first example illustrates polynomial composition::
    275        
     275
    276276            sage: R.<t> = ZZ[]
    277277            sage: f = t^2 - 1
    278278            sage: g = t + 1
    279279            sage: f(g)          # indirect doctest
    280280            t^2 + 2*t
    281                
    282         Now we illustrate how a polynomial can be evaluated at an 
     281
     282        Now we illustrate how a polynomial can be evaluated at an
    283283        integer::
    284        
     284
    285285            sage: f(2)          # indirect doctest
    286286            3
    287287        """
     
    291291        cdef unsigned long limbs
    292292        cdef fmpz_t a_fmpz
    293293        cdef fmpz_t z_fmpz
    294        
    295         if len(x) == 1: 
     294
     295        if len(x) == 1:
    296296            x0 = x[0]
    297297            if isinstance(x, Polynomial_integer_dense_flint):
    298298                f = self._new()
     
    311311                if mpz_sgn(a.value) == 0:
    312312                    return self[0]
    313313
    314                 # As of FLINT1.5, memory management for the fmpz_t type
    315                 # has to be done manually.  Without inspection of all
    316                 # coefficients, we can only naively bound the size of
    317                 # the answer by the very large value of "limbs" below. 
    318                 # If this number is too large, we move on to the generic
    319                 # polynomial evaluation code, which might either happen
    320                 # to work (in special cases) or simply run out of memory.
    321                 #
    322                 # It is expected that this workaround is unnecessary
    323                 # with FLINT2.
    324                 if fmpz_poly_length(self.__poly) <= ((1 << 25) / fmpz_poly_length(self.__poly) - fmpz_poly_limbs(self.__poly)) / mpz_size(a.value):
     314                z = PY_NEW(Integer)
    325315
    326                     z = PY_NEW(Integer)
     316                _sig_on
     317                fmpz_init(a_fmpz)
     318                fmpz_init(z_fmpz)
     319                fmpz_set_mpz(a_fmpz, a.value)
     320                fmpz_poly_evaluate_fmpz(z_fmpz, self.__poly, a_fmpz)
     321                fmpz_get_mpz(z.value, z_fmpz)
     322                fmpz_clear(a_fmpz)
     323                fmpz_clear(z_fmpz)
     324                _sig_off
    327325
    328                     _sig_on
    329                     limbs = fmpz_poly_length(self.__poly) * (fmpz_poly_limbs(self.__poly) + fmpz_poly_length(self.__poly) * mpz_size(a.value))
    330                     a_fmpz = fmpz_init(mpz_size(a.value))
    331                     z_fmpz = fmpz_init(limbs)
    332                     mpz_to_fmpz(a_fmpz, a.value)
     326                return z
    333327
    334                     fmpz_poly_evaluate(z_fmpz, self.__poly, a_fmpz)
    335 
    336                     fmpz_to_mpz(z.value, z_fmpz)
    337                     fmpz_clear(a_fmpz)
    338                     fmpz_clear(z_fmpz)
    339                     _sig_off
    340 
    341                     return z
    342 
    343         return Polynomial.__call__(self, *x, **kwds)
     328        return Polynomial.__call__(self, *x, **kwds)
    344329
    345330    cpdef Integer content(self):
    346331        r"""
    347332        Return the greatest common divisor of the coefficients of this
    348         polynomial. 
     333        polynomial.
    349334
    350335        EXAMPLES::
    351336