Path: blob/master/src/sage/matrix/matrix_modn_dense_float.pyx
8815 views
"""1Dense matrices over `\ZZ/n\ZZ` for `n < 2^{11}` 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 "sage/ext/stdsage.pxi"17include "sage/ext/interrupt.pxi"1819from sage.rings.finite_rings.stdint cimport *20from sage.libs.linbox.echelonform cimport BlasMatrixFloat as BlasMatrix21from sage.libs.linbox.modular cimport ModFloatField as ModField, ModFloatFieldElement as ModFieldElement22from sage.libs.linbox.echelonform cimport EchelonFormDomainFloat as EchelonFormDomain2324from sage.libs.linbox.fflas cimport ModFloat_fgemm as Mod_fgemm, ModFloat_fgemv as Mod_fgemv, \25ModFloatDet as ModDet, \26ModFloatRank as ModRank, ModFloat_echelon as Mod_echelon, \27ModFloat_applyp as Mod_applyp, \28ModFloat_MinPoly as Mod_MinPoly, \29ModFloat_CharPoly as Mod_CharPoly3031# LinBox supports up to 2^11 using float but that's double dog slow,32# so we pick a smaller value for crossover33MAX_MODULUS = 2**83435include "matrix_modn_dense_template.pxi"3637cdef class Matrix_modn_dense_float(Matrix_modn_dense_template):38r"""39Dense matrices over `\ZZ/n\ZZ` for `n < 2^{11}` using LinBox's ``Modular<float>``4041These are matrices with integer entries mod ``n`` represented as42floating-point numbers in a 32-bit word for use with LinBox routines.43This allows for ``n`` up to `2^{11}`. The44``Matrix_modn_dense_double`` class is used for larger moduli.4546Routines here are for the most basic access, see the47`matrix_modn_dense_template.pxi` file for higher-level routines.48"""49def __cinit__(self):50"""51The Cython constructor5253TESTS::5455sage: A = random_matrix(GF(7), 4, 4)56sage: type(A[0,0])57<type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>58"""59self._get_template = self._base_ring.zero()6061cdef set_unsafe_int(self, Py_ssize_t i, Py_ssize_t j, int value):62r"""63Set the (i,j) entry of self to the int value.6465EXAMPLES::6667sage: A = random_matrix(GF(7), 4, 4); A68[3 1 6 6]69[4 4 2 2]70[3 5 4 5]71[6 2 2 1]72sage: A[0,0] = 12; A73[5 1 6 6]74[4 4 2 2]75[3 5 4 5]76[6 2 2 1]7778sage: B = random_matrix(Integers(100), 4, 4); B79[13 95 1 16]80[18 33 7 31]81[92 19 18 93]82[82 42 15 38]83sage: B[0,0] = 422; B84[22 95 1 16]85[18 33 7 31]86[92 19 18 93]87[82 42 15 38]88"""89self._matrix[i][j] = <float>value9091cdef set_unsafe(self, Py_ssize_t i, Py_ssize_t j, x):92r"""93Set the (i,j) entry with no bounds-checking, or any other checks.9495Assumes that `x` is in the base ring.9697EXAMPLES::9899sage: A = random_matrix(GF(13), 4, 4); A100[ 0 0 2 9]101[10 6 11 8]102[10 12 8 8]103[ 3 6 8 0]104sage: K = A.base_ring()105sage: x = K(27)106sage: A[0,0] = x; A107[ 1 0 2 9]108[10 6 11 8]109[10 12 8 8]110[ 3 6 8 0]111112sage: B = random_matrix(Integers(200), 4, 4); B113[ 13 95 101 116]114[118 133 7 131]115[192 19 118 193]116[ 82 142 115 38]117sage: R = B.base_ring()118sage: x = R(311)119sage: B[0,0] = x; B120[111 95 101 116]121[118 133 7 131]122[192 19 118 193]123[ 82 142 115 38]124"""125self._matrix[i][j] = <float>(<IntegerMod_int>x).ivalue126127cdef IntegerMod_int get_unsafe(self, Py_ssize_t i, Py_ssize_t j):128r"""129Return the (i,j) entry with no bounds-checking.130131OUTPUT:132133A :class:`sage.rings.finite_rings.integer_mod.IntegerMod_int`134object.135136EXAMPLES::137138sage: A = random_matrix(Integers(100), 4, 4); A139[ 4 95 83 47]140[44 57 91 53]141[75 53 15 39]142[26 25 10 74]143sage: a = A[0,0]; a1444145sage: a in A.base_ring()146True147148sage: B = random_matrix(Integers(100), 4, 4); B149[13 95 1 16]150[18 33 7 31]151[92 19 18 93]152[82 42 15 38]153sage: b = B[0,0]; b15413155sage: b in B.base_ring()156True157"""158cdef float result = (<Matrix_modn_dense_template>self)._matrix[i][j]159return (<Matrix_modn_dense_float>self)._get_template._new_c(<int_fast32_t>result)160161162