@@ -90,7 +90,7 @@ We test corner cases for multiplication::
90
90
from libc.stdint cimport uint64_t
91
91
from cpython.bytes cimport *
92
92
93
- from cysignals.memory cimport check_malloc, check_allocarray, check_calloc, sig_malloc, sig_free
93
+ from cysignals.memory cimport check_malloc, check_allocarray, sig_malloc, sig_free
94
94
from cysignals.signals cimport sig_check, sig_on, sig_off
95
95
96
96
from sage.libs.gmp.mpz cimport *
@@ -123,7 +123,7 @@ from sage.structure.proof.proof import get_flag as get_proof_flag
123
123
from sage.structure.richcmp cimport rich_to_bool
124
124
from sage.misc.randstate cimport randstate, current_randstate
125
125
import sage.matrix.matrix_space as matrix_space
126
- from .args cimport SparseEntry, MatrixArgs_init
126
+ from .args cimport MatrixArgs_init
127
127
128
128
129
129
from sage.cpython.string cimport char_to_str
@@ -447,8 +447,8 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
447
447
if p >= MAX_MODULUS:
448
448
raise OverflowError (" p (=%s ) must be < %s ." % (p, MAX_MODULUS))
449
449
450
- self ._entries = < celement * > check_calloc (self ._nrows * self ._ncols, sizeof(celement))
451
- self ._matrix = < celement ** > check_calloc (self ._nrows, sizeof(celement* ))
450
+ self ._entries = < celement * > check_allocarray (self ._nrows * self ._ncols, sizeof(celement))
451
+ self ._matrix = < celement ** > check_allocarray (self ._nrows, sizeof(celement* ))
452
452
453
453
cdef unsigned int k
454
454
cdef Py_ssize_t i
@@ -518,49 +518,27 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
518
518
"""
519
519
ma = MatrixArgs_init(parent, entries)
520
520
cdef long i, j
521
- it = ma.iter(convert = False , sparse = True )
521
+ it = ma.iter(False )
522
522
R = ma.base
523
523
p = R.characteristic()
524
-
525
- for t in it:
526
- se = < SparseEntry> t
527
- x = se.entry
528
- v = self ._matrix[se.i]
529
- if type (x) is int :
530
- tmp = (< long > x) % p
531
- v[se.j] = tmp + (tmp< 0 )* p
532
- elif type (x) is IntegerMod_int and (< IntegerMod_int> x)._parent is R:
533
- v[se.j] = < celement> (< IntegerMod_int> x).ivalue
534
- elif type (x) is Integer:
535
- if coerce :
536
- v[se.j] = mpz_fdiv_ui((< Integer> x).value, p)
524
+ for i in range (ma.nrows):
525
+ v = self ._matrix[i]
526
+ for j in range (ma.ncols):
527
+ x = next(it)
528
+ if type (x) is int :
529
+ tmp = (< long > x) % p
530
+ v[j] = tmp + (tmp< 0 )* p
531
+ elif type (x) is IntegerMod_int and (< IntegerMod_int> x)._parent is R:
532
+ v[j] = < celement> (< IntegerMod_int> x).ivalue
533
+ elif type (x) is Integer:
534
+ if coerce :
535
+ v[j] = mpz_fdiv_ui((< Integer> x).value, p)
536
+ else :
537
+ v[j] = mpz_get_ui((< Integer> x).value)
538
+ elif coerce :
539
+ v[j] = R(x)
537
540
else :
538
541
v[j] = < celement> x
539
- v[se.j] = mpz_get_ui((< Integer> x).value)
540
- elif coerce :
541
- v[se.j] = R(x)
542
- else :
543
- v[se.j] = < celement> x
544
-
545
-
546
- # for i in range(ma.nrows):
547
- # v = self._matrix[i]
548
- # for j in range(ma.ncols):
549
- # x = next(it)
550
- # if type(x) is int:
551
- # tmp = (<long>x) % p
552
- # v[j] = tmp + (tmp<0)*p
553
- # elif type(x) is IntegerMod_int and (<IntegerMod_int>x)._parent is R:
554
- # v[j] = <celement>(<IntegerMod_int>x).ivalue
555
- # elif type(x) is Integer:
556
- # if coerce:
557
- # v[j] = mpz_fdiv_ui((<Integer>x).value, p)
558
- # else:
559
- # v[j] = mpz_get_ui((<Integer>x).value)
560
- # elif coerce:
561
- # v[j] = R(x)
562
- # else:
563
- # v[j] = <celement>x
564
542
565
543
cdef long _hash_(self ) except - 1 :
566
544
"""
@@ -3034,14 +3012,19 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
3034
3012
if nrows == - 1 :
3035
3013
nrows = self ._nrows - row
3036
3014
3037
- if col != 0 or ncols != self ._ncols:
3038
- return self .matrix_from_rows_and_columns(range (row, row+ nrows), range (col, col+ ncols))
3015
+ # if col != 0 or ncols != self._ncols:
3016
+ # return self.matrix_from_rows_and_columns(range(row, row+nrows), range(col, col+ncols))
3039
3017
3040
3018
if nrows < 0 or row < 0 or row + nrows > self ._nrows:
3041
3019
raise IndexError (" rows out of range" )
3042
3020
3043
- cdef Matrix_modn_dense_template M = self .new_matrix(nrows = nrows, ncols = self ._ncols)
3044
- memcpy(M._entries, self ._entries+ row* ncols, sizeof(celement)* ncols* nrows)
3021
+ cdef Matrix_modn_dense_template M = self .new_matrix(nrows = nrows, ncols = ncols)
3022
+ cdef Py_ssize_t i,r
3023
+ for i,r in enumerate (range (row, row+ nrows)) :
3024
+ memcpy(M._entries + (i* ncols), self ._entries+ self ._ncols* r+ col, sizeof(celement)* ncols)
3025
+
3026
+ # cdef Matrix_modn_dense_template M = self.new_matrix(nrows=nrows, ncols=self._ncols)
3027
+ # memcpy(M._entries, self._entries+row*ncols, sizeof(celement)*ncols*nrows)
3045
3028
return M
3046
3029
3047
3030
def _matrices_from_rows (self , Py_ssize_t nrows , Py_ssize_t ncols ):
0 commit comments