Path: blob/master/sage/matrix/matrix_modn_dense_double.pyx
4077 views
"""1Dense matrices over `\ZZ/n\ZZ` for `n < 2^{23}` using LinBox's ``Modular<float>``23AUTHORS:4- Burcin Erocal5- Martin Albrecht6"""7###############################################################################8# SAGE: Open Source Mathematical Software9# Copyright (C) 2011 Burcin Erocal <[email protected]>10# Copyright (C) 2011 Martin Albrecht <[email protected]>11# Distributed under the terms of the GNU General Public License (GPL),12# version 2 or any later version. The full text of the GPL is available at:13# http://www.gnu.org/licenses/14###############################################################################1516include "../ext/stdsage.pxi"17include "../ext/interrupt.pxi"1819# randstate in template needs this20include '../ext/random.pxi'2122from sage.libs.linbox.echelonform cimport BlasMatrix2324from sage.libs.linbox.modular cimport ModDoubleField as ModField, ModDoubleFieldElement as ModFieldElement25from sage.libs.linbox.echelonform cimport EchelonFormDomainDouble as EchelonFormDomain2627from sage.libs.linbox.fflas cimport ModDouble_fgemm as Mod_fgemm, ModDouble_fgemv as Mod_fgemv, \28ModDoubleDet as ModDet, \29ModDoubleRank as ModRank, ModDouble_echelon as Mod_echelon, \30ModDouble_applyp as Mod_applyp, \31ModDouble_MinPoly as Mod_MinPoly, \32ModDouble_CharPoly as Mod_CharPoly3334MAX_MODULUS = 2**233536cdef extern from "../rings/finite_rings/stdint.h":37ctypedef int int_fast32_t38ctypedef int int_fast64_t39int_fast32_t INTEGER_MOD_INT32_LIMIT40int_fast64_t INTEGER_MOD_INT64_LIMIT4142from sage.rings.finite_rings.integer_mod cimport IntegerMod_int644344include "matrix_modn_dense_template.pxi"454647cdef class Matrix_modn_dense_double(Matrix_modn_dense_template):48r"""49Dense matrices over `\ZZ/n\ZZ` for `n < 2^{23}` using LinBox's ``Modular<float>``5051These are matrices with integer entries mod ``n`` represented as52floating-point numbers in a 64-bit word for use with LinBox routines.53This allows for ``n`` up to `2^{23}`. The54``Matrix_modn_dense_float`` class specializes to smaller moduli.5556Routines here are for the most basic access, see the57`matrix_modn_dense_template.pxi` file for higher-level routines.58"""59cdef set_unsafe_int(self, Py_ssize_t i, Py_ssize_t j, int value):60r"""61Set the (i,j) entry of self to the int value.6263EXAMPLE::6465sage: A = random_matrix(GF(3016963), 4, 4); A66[ 220081 2824836 765701 2282256]67[1795330 767112 2967421 1373921]68[2757699 1142917 2720973 2877160]69[1674049 1341486 2641133 2173280]70sage: A[0,0] = 220082r; A71[ 220082 2824836 765701 2282256]72[1795330 767112 2967421 1373921]73[2757699 1142917 2720973 2877160]74[1674049 1341486 2641133 2173280]75sage: a = A[0,0]; a7622008277sage: ~a7828593587980sage: A = random_matrix(Integers(5099106), 4, 4); A81[2629491 1237101 2033003 3788106]82[4649912 1157595 4928315 4382585]83[4252686 978867 2601478 1759921]84[1303120 1860486 3405811 2203284]85sage: A[0,0] = 220082r; A86[ 220082 1237101 2033003 3788106]87[4649912 1157595 4928315 4382585]88[4252686 978867 2601478 1759921]89[1303120 1860486 3405811 2203284]90sage: a = A[0,0]; a9122008292sage: a*a93477793694"""95self._matrix[i][j] = <double>value9697cdef set_unsafe(self, Py_ssize_t i, Py_ssize_t j, x):98r"""99Set the (i,j) entry with no bounds-checking, or any other checks.100101Assumes that `x` is in the base ring.102103EXAMPLE::104105sage: A = random_matrix(GF(3016963), 4, 4); A106[ 220081 2824836 765701 2282256]107[1795330 767112 2967421 1373921]108[2757699 1142917 2720973 2877160]109[1674049 1341486 2641133 2173280]110sage: K = A.base_ring()111sage: A[0,0] = K(220082); A112[ 220082 2824836 765701 2282256]113[1795330 767112 2967421 1373921]114[2757699 1142917 2720973 2877160]115[1674049 1341486 2641133 2173280]116sage: a = A[0,0]; a117220082118sage: ~a1192859358120121sage: A = random_matrix(Integers(5099106), 4, 4); A122[2629491 1237101 2033003 3788106]123[4649912 1157595 4928315 4382585]124[4252686 978867 2601478 1759921]125[1303120 1860486 3405811 2203284]126sage: K = A.base_ring()127sage: A[0,0] = K(220081)128sage: a = A[0,0]; a129220081130sage: a*a1314337773132"""133# note that INTEGER_MOD_INT32_LIMIT is ceil(sqrt(2^31-1)) < 2^23134if (<Matrix_modn_dense_template>self).p <= INTEGER_MOD_INT32_LIMIT:135self._matrix[i][j] = <double>(<IntegerMod_int>x).ivalue136else:137self._matrix[i][j] = <double>(<IntegerMod_int64>x).ivalue138139cdef IntegerMod_abstract get_unsafe(self, Py_ssize_t i, Py_ssize_t j):140r"""141Return the (i,j) entry with no bounds-checking.142143EXAMPLE::144145sage: A = random_matrix(GF(3016963), 4, 4); A146[ 220081 2824836 765701 2282256]147[1795330 767112 2967421 1373921]148[2757699 1142917 2720973 2877160]149[1674049 1341486 2641133 2173280]150sage: a = A[0,0]; a151220081152sage: ~a153697224154sage: K = A.base_ring()155sage: ~K(220081)156697224157158sage: A = random_matrix(Integers(5099106), 4, 4); A159[2629491 1237101 2033003 3788106]160[4649912 1157595 4928315 4382585]161[4252686 978867 2601478 1759921]162[1303120 1860486 3405811 2203284]163sage: a = A[0,1]; a1641237101165sage: a*a1663803997167sage: K = A.base_ring()168sage: K(1237101)^21693803997170"""171# note that INTEGER_MOD_INT32_LIMIT is ceil(sqrt(2^31-1)) < 2^23172if (<Matrix_modn_dense_template>self).p <= INTEGER_MOD_INT32_LIMIT:173return IntegerMod_int(self._base_ring, <mod_int>(<Matrix_modn_dense_template>self)._matrix[i][j])174else:175return IntegerMod_int64(self._base_ring, <mod_int>(<Matrix_modn_dense_template>self)._matrix[i][j])176177178179