Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/matrix/matrix_modn_dense_float.pyx
8815 views
1
"""
2
Dense matrices over `\ZZ/n\ZZ` for `n < 2^{11}` using LinBox's ``Modular<float>``
3
4
AUTHORS:
5
- Burcin Erocal
6
- Martin Albrecht
7
"""
8
###############################################################################
9
# SAGE: Open Source Mathematical Software
10
# Copyright (C) 2011 Burcin Erocal <[email protected]>
11
# Copyright (C) 2011 Martin Albrecht <[email protected]>
12
# Distributed under the terms of the GNU General Public License (GPL),
13
# version 2 or any later version. The full text of the GPL is available at:
14
# http://www.gnu.org/licenses/
15
###############################################################################
16
17
include "sage/ext/stdsage.pxi"
18
include "sage/ext/interrupt.pxi"
19
20
from sage.rings.finite_rings.stdint cimport *
21
from sage.libs.linbox.echelonform cimport BlasMatrixFloat as BlasMatrix
22
from sage.libs.linbox.modular cimport ModFloatField as ModField, ModFloatFieldElement as ModFieldElement
23
from sage.libs.linbox.echelonform cimport EchelonFormDomainFloat as EchelonFormDomain
24
25
from sage.libs.linbox.fflas cimport ModFloat_fgemm as Mod_fgemm, ModFloat_fgemv as Mod_fgemv, \
26
ModFloatDet as ModDet, \
27
ModFloatRank as ModRank, ModFloat_echelon as Mod_echelon, \
28
ModFloat_applyp as Mod_applyp, \
29
ModFloat_MinPoly as Mod_MinPoly, \
30
ModFloat_CharPoly as Mod_CharPoly
31
32
# LinBox supports up to 2^11 using float but that's double dog slow,
33
# so we pick a smaller value for crossover
34
MAX_MODULUS = 2**8
35
36
include "matrix_modn_dense_template.pxi"
37
38
cdef class Matrix_modn_dense_float(Matrix_modn_dense_template):
39
r"""
40
Dense matrices over `\ZZ/n\ZZ` for `n < 2^{11}` using LinBox's ``Modular<float>``
41
42
These are matrices with integer entries mod ``n`` represented as
43
floating-point numbers in a 32-bit word for use with LinBox routines.
44
This allows for ``n`` up to `2^{11}`. The
45
``Matrix_modn_dense_double`` class is used for larger moduli.
46
47
Routines here are for the most basic access, see the
48
`matrix_modn_dense_template.pxi` file for higher-level routines.
49
"""
50
def __cinit__(self):
51
"""
52
The Cython constructor
53
54
TESTS::
55
56
sage: A = random_matrix(GF(7), 4, 4)
57
sage: type(A[0,0])
58
<type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>
59
"""
60
self._get_template = self._base_ring.zero()
61
62
cdef set_unsafe_int(self, Py_ssize_t i, Py_ssize_t j, int value):
63
r"""
64
Set the (i,j) entry of self to the int value.
65
66
EXAMPLES::
67
68
sage: A = random_matrix(GF(7), 4, 4); A
69
[3 1 6 6]
70
[4 4 2 2]
71
[3 5 4 5]
72
[6 2 2 1]
73
sage: A[0,0] = 12; A
74
[5 1 6 6]
75
[4 4 2 2]
76
[3 5 4 5]
77
[6 2 2 1]
78
79
sage: B = random_matrix(Integers(100), 4, 4); B
80
[13 95 1 16]
81
[18 33 7 31]
82
[92 19 18 93]
83
[82 42 15 38]
84
sage: B[0,0] = 422; B
85
[22 95 1 16]
86
[18 33 7 31]
87
[92 19 18 93]
88
[82 42 15 38]
89
"""
90
self._matrix[i][j] = <float>value
91
92
cdef set_unsafe(self, Py_ssize_t i, Py_ssize_t j, x):
93
r"""
94
Set the (i,j) entry with no bounds-checking, or any other checks.
95
96
Assumes that `x` is in the base ring.
97
98
EXAMPLES::
99
100
sage: A = random_matrix(GF(13), 4, 4); A
101
[ 0 0 2 9]
102
[10 6 11 8]
103
[10 12 8 8]
104
[ 3 6 8 0]
105
sage: K = A.base_ring()
106
sage: x = K(27)
107
sage: A[0,0] = x; A
108
[ 1 0 2 9]
109
[10 6 11 8]
110
[10 12 8 8]
111
[ 3 6 8 0]
112
113
sage: B = random_matrix(Integers(200), 4, 4); B
114
[ 13 95 101 116]
115
[118 133 7 131]
116
[192 19 118 193]
117
[ 82 142 115 38]
118
sage: R = B.base_ring()
119
sage: x = R(311)
120
sage: B[0,0] = x; B
121
[111 95 101 116]
122
[118 133 7 131]
123
[192 19 118 193]
124
[ 82 142 115 38]
125
"""
126
self._matrix[i][j] = <float>(<IntegerMod_int>x).ivalue
127
128
cdef IntegerMod_int get_unsafe(self, Py_ssize_t i, Py_ssize_t j):
129
r"""
130
Return the (i,j) entry with no bounds-checking.
131
132
OUTPUT:
133
134
A :class:`sage.rings.finite_rings.integer_mod.IntegerMod_int`
135
object.
136
137
EXAMPLES::
138
139
sage: A = random_matrix(Integers(100), 4, 4); A
140
[ 4 95 83 47]
141
[44 57 91 53]
142
[75 53 15 39]
143
[26 25 10 74]
144
sage: a = A[0,0]; a
145
4
146
sage: a in A.base_ring()
147
True
148
149
sage: B = random_matrix(Integers(100), 4, 4); B
150
[13 95 1 16]
151
[18 33 7 31]
152
[92 19 18 93]
153
[82 42 15 38]
154
sage: b = B[0,0]; b
155
13
156
sage: b in B.base_ring()
157
True
158
"""
159
cdef float result = (<Matrix_modn_dense_template>self)._matrix[i][j]
160
return (<Matrix_modn_dense_float>self)._get_template._new_c(<int_fast32_t>result)
161
162