Ticket #12173: 15-integer_to_mod.patch
File 15-integer_to_mod.patch, 6.8 KB (added by , 10 years ago) |
---|
-
module_list.py
# HG changeset patch # User Jean-Pierre Flori <jean-pierre.flor@ssi.gouv.fr> # Date 1343669787 -7200 # Node ID 7618bca3828c84134e9a3a0434dd36f4bcdbc4dc # Parent be48f3c58b14641f470a363012cf2a77f5d9c820 #12173: Faster conversion from interger polynomial to mod polynomial diff --git a/module_list.py b/module_list.py
a b 1357 1357 1358 1358 Extension('sage.rings.fraction_field_FpT', 1359 1359 sources = ['sage/rings/fraction_field_FpT.pyx'], 1360 language = 'c++', 1360 1361 libraries = ["csage", "flint", "gmp", "gmpxx", "ntl", "zn_poly"], 1361 1362 extra_compile_args=["-std=c99", "-D_XPG6"], 1362 1363 include_dirs = [SAGE_INC + 'flint/'], … … 1627 1628 1628 1629 Extension('sage.rings.polynomial.polynomial_zmod_flint', 1629 1630 sources = ['sage/rings/polynomial/polynomial_zmod_flint.pyx'], 1631 language = 'c++', 1630 1632 libraries = ["csage", "flint", "gmp", "gmpxx", "ntl", "zn_poly"], 1631 1633 extra_compile_args=["-std=c99", "-D_XPG6"], 1632 1634 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 3 3 4 4 cdef extern from "flint/fmpz_poly.h": 5 5 6 ctypedef void* fmpz_poly_t 7 6 ctypedef struct fmpz_poly_struct: 7 fmpz * coeffs 8 9 ctypedef void * fmpz_poly_t 10 8 11 void fmpz_poly_init(fmpz_poly_t poly) 9 12 void fmpz_poly_init2(fmpz_poly_t poly, unsigned long alloc) 10 13 void fmpz_poly_realloc(fmpz_poly_t poly, unsigned long alloc) -
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 1 1 r""" 2 Linkage for arithmetic with FLINT's zmod_poly_t elements.2 Linkage for arithmetic with FLINT's nmod_poly_t elements. 3 3 4 4 This file provides the backend for \class{Polynomial_zmod_flint} via 5 5 templating. -
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 1 1 from sage.libs.flint.zmod_poly cimport nmod_poly_t, nmod_poly_struct 2 2 from sage.structure.parent cimport Parent 3 from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint 3 4 4 5 ctypedef nmod_poly_struct celement 5 6 … … 7 8 8 9 cdef class Polynomial_zmod_flint(Polynomial_template): 9 10 cdef Polynomial_template _new(self) 10 cdef _set_list(self, x) 11 cdef void _set_list(self, x) 12 cdef void _set_fmpz_poly(self, Polynomial_integer_dense_flint, bint) 11 13 cpdef _mul_trunc(self, Polynomial_zmod_flint other, length) 12 14 cpdef _mul_trunc_opposite(self, Polynomial_zmod_flint other, length) 13 15 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 36 36 from sage.libs.ntl.ntl_lzz_pX import ntl_zz_pX 37 37 from sage.structure.factorization import Factorization 38 38 from sage.structure.element import coerce_binop, parent 39 from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint 39 40 40 41 # We need to define this stuff before including the templating stuff 41 42 # to make sure the function get_cparent is found since it is used in … … 62 63 cdef void zn_mod_clear(zn_mod_struct *mod) 63 64 cdef void zn_array_mul(unsigned long* res, unsigned long* op1, size_t n1, unsigned long* op2, size_t n2, zn_mod_struct *mod) 64 65 66 include "../../libs/flint/fmpz.pxi" 67 68 cdef extern from "flint/fmpz.h": 69 cdef unsigned long fmpz_get_ui(fmpz_t) 70 cdef unsigned long fmpz_fdiv_ui(fmpz_t, unsigned long) 71 72 include "../../libs/flint/fmpz_poly.pxi" 73 65 74 cdef class Polynomial_zmod_flint(Polynomial_template): 66 75 def __init__(self, parent, x=None, check=True, is_gen=False, construct=False): 67 76 """ … … 86 95 Polynomial_template.__init__(self, parent, 0, check, is_gen, construct) 87 96 self._set_list(lst) 88 97 return 98 elif PY_TYPE_CHECK(x, Polynomial_integer_dense_flint): 99 Polynomial_template.__init__(self, parent, 0, check, is_gen, construct) 100 self._set_fmpz_poly(x, check) 101 return 89 102 else: 90 103 if PY_TYPE_CHECK(x, ntl_zz_pX): 91 104 x = x.list() … … 139 152 celement_set_si(&r.x, int(x), get_cparent(P)) 140 153 return r 141 154 142 cdef _set_list(self, x):155 cdef void _set_list(self, x): 143 156 """ 157 Set the coefficients of ``self`` from a list of coefficients. 158 159 INPUT: 160 161 - ``x`` - a list of coefficients 162 144 163 EXAMPLES:: 145 164 146 165 sage: P.<a>=GF(7)[] … … 164 183 nmod_poly_realloc(&self.x, length) 165 184 sig_off() 166 185 186 sig_on() 167 187 for i from 0 <= i < length: 168 188 nmod_poly_set_coeff_ui(&self.x, i, l_in[i]) 189 sig_off() 190 191 cdef void _set_fmpz_poly(self, Polynomial_integer_dense_flint x, bint check): 192 """ 193 Set the coefficients of ``self`` from the coefficients of a :class:`Polynomial_integer_dense_flint` element. 194 195 INPUT: 196 197 - ``x`` - a :class:`Polynomial_integer_dense_flint` element 198 199 - ``check`` - whether to reduce the coefficients of `x` or not 200 201 EXAMPLES:: 202 203 sage: a = ZZ['x'](range(17)) 204 sage: R = Integers(7)['x'] 205 sage: R(a) 206 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 207 208 TESTS: 209 210 The following test from :trac:`12173` used to be horribly slow:: 211 212 sage: a = ZZ['x'](range(100000)) 213 sage: R = Integers(3)['x'] 214 sage: R(a) 215 2*x^99998 + ... + x 216 """ 217 cdef unsigned long length = fmpz_poly_length(x.__poly) 218 cdef unsigned long modulus = nmod_poly_modulus(&self.x) 219 cdef fmpz *coeffs = (<fmpz_poly_struct>(x.__poly[0])).coeffs 220 cdef int i 221 if length == 0: 222 nmod_poly_zero(&self.x) 223 return 224 225 # resize to length of list 226 sig_on() 227 nmod_poly_realloc(&self.x, length) 228 sig_off() 229 230 if check: 231 sig_on() 232 for i from 0 <= i < length: 233 nmod_poly_set_coeff_ui(&self.x, i, fmpz_fdiv_ui(&coeffs[i], modulus)) 234 sig_off() 235 return 236 else: 237 sig_on() 238 for i from 0 <= i < length: 239 nmod_poly_set_coeff_ui(&self.x, i, fmpz_get_ui(&coeffs[i])) 240 sig_off() 241 return 169 242 170 243 def __getitem__(self, i): 171 244 """