Ticket #12173: 15-integer_to_mod-v2.patch

File 15-integer_to_mod-v2.patch, 6.1 KB (added by jpflori, 10 years ago)
  • module_list.py

    # HG changeset patch
    # User Jean-Pierre Flori <jean-pierre.flor@ssi.gouv.fr>
    # Date 1343669787 -7200
    # Node ID 2de1cd2709d4fcad2abd65a08e76f46a48302cb9
    # Parent  be48f3c58b14641f470a363012cf2a77f5d9c820
    #12173: Faster conversion from interger polynomial to mod polynomial
    
    diff --git a/module_list.py b/module_list.py
    a b  
    13571357   
    13581358    Extension('sage.rings.fraction_field_FpT',
    13591359              sources = ['sage/rings/fraction_field_FpT.pyx'],
     1360              language = 'c++',
    13601361              libraries = ["csage", "flint", "gmp", "gmpxx", "ntl", "zn_poly"],
    13611362              extra_compile_args=["-std=c99", "-D_XPG6"],
    13621363              include_dirs = [SAGE_INC + 'flint/'],
     
    16271628
    16281629    Extension('sage.rings.polynomial.polynomial_zmod_flint',
    16291630              sources = ['sage/rings/polynomial/polynomial_zmod_flint.pyx'],
     1631              language = 'c++',
    16301632              libraries = ["csage", "flint", "gmp", "gmpxx", "ntl", "zn_poly"],
    16311633              extra_compile_args=["-std=c99", "-D_XPG6"],
    16321634              include_dirs = [SAGE_INC + 'flint/'],
  • sage/libs/flint/fmpz_poly.pxi

    diff --git a/sage/libs/flint/fmpz_poly.pxi b/sage/libs/flint/fmpz_poly.pxi
    a b  
    11include "fmpz.pxi"
    22include "../ntl/decl.pxi"
    33
     4from sage.libs.flint.zmod_poly cimport nmod_poly_t
     5
    46cdef extern from "flint/fmpz_poly.h":
    57   
    68    ctypedef void* fmpz_poly_t
     
    3234    void fmpz_poly_get_coeff_mpz_read_only(mpz_t x, fmpz_poly_t poly, unsigned long n)
    3335    fmpz_t fmpz_poly_get_coeff_ptr(fmpz_poly_t poly, unsigned long n)
    3436
     37    void fmpz_poly_get_nmod_poly(nmod_poly_t res, fmpz_poly_t poly)
     38
    3539    void fmpz_poly_add(fmpz_poly_t output, fmpz_poly_t input1, \
    3640            fmpz_poly_t input2)
    3741    void fmpz_poly_sub(fmpz_poly_t output, fmpz_poly_t input1, \
  • sage/libs/flint/zmod_poly_linkage.pxi

    diff --git a/sage/libs/flint/zmod_poly_linkage.pxi b/sage/libs/flint/zmod_poly_linkage.pxi
    a b  
    11r"""
    2 Linkage for arithmetic with FLINT's zmod_poly_t elements.
     2Linkage for arithmetic with FLINT's nmod_poly_t elements.
    33
    44This file provides the backend for \class{Polynomial_zmod_flint} via
    55templating.
  • sage/rings/polynomial/polynomial_zmod_flint.pxd

    diff --git a/sage/rings/polynomial/polynomial_zmod_flint.pxd b/sage/rings/polynomial/polynomial_zmod_flint.pxd
    a b  
    11from sage.libs.flint.zmod_poly cimport nmod_poly_t, nmod_poly_struct
     2from sage.libs.flint.fmpz_poly cimport fmpz_poly_t
    23from sage.structure.parent cimport Parent
     4from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint
    35
    46ctypedef nmod_poly_struct celement
    57
     
    79
    810cdef class Polynomial_zmod_flint(Polynomial_template):
    911    cdef Polynomial_template _new(self)
    10     cdef _set_list(self, x)
     12    cdef void _set_list(self, x)
     13    cdef void _set_fmpz_poly(self, fmpz_poly_t)
    1114    cpdef _mul_trunc(self, Polynomial_zmod_flint other, length)
    1215    cpdef _mul_trunc_opposite(self, Polynomial_zmod_flint other, length)
    1316    cpdef rational_reconstruct(self, m, n_deg=?, d_deg=?)
  • sage/rings/polynomial/polynomial_zmod_flint.pyx

    diff --git a/sage/rings/polynomial/polynomial_zmod_flint.pyx b/sage/rings/polynomial/polynomial_zmod_flint.pyx
    a b  
    3636from sage.libs.ntl.ntl_lzz_pX import ntl_zz_pX
    3737from sage.structure.factorization import Factorization
    3838from sage.structure.element import coerce_binop, parent
     39from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint
    3940
    4041# We need to define this stuff before including the templating stuff
    4142# to make sure the function get_cparent is found since it is used in
     
    6263    cdef void zn_mod_clear(zn_mod_struct *mod)
    6364    cdef void zn_array_mul(unsigned long* res, unsigned long* op1, size_t n1, unsigned long* op2, size_t n2, zn_mod_struct *mod)
    6465
     66include "../../libs/flint/fmpz_poly.pxi"
     67
    6568cdef class Polynomial_zmod_flint(Polynomial_template):
    6669    def __init__(self, parent, x=None, check=True, is_gen=False, construct=False):
    6770        """
     
    8689            Polynomial_template.__init__(self, parent, 0, check, is_gen, construct)
    8790            self._set_list(lst)
    8891            return
     92        elif PY_TYPE_CHECK(x, Polynomial_integer_dense_flint):
     93            Polynomial_template.__init__(self, parent, 0, check, is_gen, construct)
     94            self._set_fmpz_poly((<Polynomial_integer_dense_flint>x).__poly)
     95            return
    8996        else:
    9097            if PY_TYPE_CHECK(x, ntl_zz_pX):
    9198                x = x.list()
     
    139146        celement_set_si(&r.x, int(x), get_cparent(P))
    140147        return r
    141148
    142     cdef _set_list(self, x):
     149    cdef void _set_list(self, x):
    143150        """
     151        Set the coefficients of ``self`` from a list of coefficients.
     152
     153        INPUT:
     154
     155        - ``x`` - a list of coefficients
     156
    144157        EXAMPLES::
    145158
    146159            sage: P.<a>=GF(7)[]
     
    164177        nmod_poly_realloc(&self.x, length)
    165178        sig_off()
    166179
     180        sig_on()
    167181        for i from 0 <= i < length:
    168182            nmod_poly_set_coeff_ui(&self.x, i, l_in[i])
     183        sig_off()
     184
     185    cdef void _set_fmpz_poly(self, fmpz_poly_t x):
     186        """
     187        Set the coefficients of ``self`` from the coefficients of an ``fmpz_poly_t`` element.
     188
     189        INPUT:
     190
     191        - ``x`` - an ``fmpz_poly_t`` element
     192
     193        EXAMPLES::
     194
     195            sage: a = ZZ['x'](range(17))
     196            sage: R = Integers(7)['x']
     197            sage: R(a)
     198            2*x^16 + x^15 + 6*x^13 + 5*x^12 + 4*x^11 + 3*x^10 + 2*x^9 + x^8 + 6*x^6 + 5*x^5 + 4*x^4 + 3*x^3 + 2*x^2 + x
     199
     200        TESTS:
     201
     202        The following test from :trac:`12173` used to be horribly slow::
     203
     204            sage: a = ZZ['x'](range(100000))
     205            sage: R = Integers(3)['x']
     206            sage: R(a)
     207            2*x^99998 + ... + x
     208        """
     209        sig_on()
     210        fmpz_poly_get_nmod_poly(&self.x, x)
     211        sig_off()
    169212
    170213    def __getitem__(self, i):
    171214        """