@@ -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 MatrixArgs_init
126
+ from .args cimport SparseEntry, MatrixArgs_init
127
127
128
128
129
129
from sage.cpython.string cimport char_to_str
@@ -518,27 +518,49 @@ 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(False )
521
+ it = ma.iter(convert = False , sparse = True )
522
522
R = ma.base
523
523
p = R.characteristic()
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)
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)
540
537
else :
541
538
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
542
564
543
565
cdef long _hash_(self ) except - 1 :
544
566
"""
0 commit comments