Skip to content

Commit af0de6b

Browse files
author
Marie BONBOIRE
committed
removed _from_rows_and_columns from submatrix
1 parent 4b24dff commit af0de6b

File tree

1 file changed

+30
-47
lines changed

1 file changed

+30
-47
lines changed

src/sage/matrix/matrix_modn_dense_template.pxi

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ We test corner cases for multiplication::
9090
from libc.stdint cimport uint64_t
9191
from cpython.bytes cimport *
9292

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
9494
from cysignals.signals cimport sig_check, sig_on, sig_off
9595

9696
from sage.libs.gmp.mpz cimport *
@@ -123,7 +123,7 @@ from sage.structure.proof.proof import get_flag as get_proof_flag
123123
from sage.structure.richcmp cimport rich_to_bool
124124
from sage.misc.randstate cimport randstate, current_randstate
125125
import sage.matrix.matrix_space as matrix_space
126-
from .args cimport SparseEntry, MatrixArgs_init
126+
from .args cimport MatrixArgs_init
127127

128128

129129
from sage.cpython.string cimport char_to_str
@@ -447,8 +447,8 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
447447
if p >= MAX_MODULUS:
448448
raise OverflowError("p (=%s) must be < %s."%(p, MAX_MODULUS))
449449

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*))
452452

453453
cdef unsigned int k
454454
cdef Py_ssize_t i
@@ -518,49 +518,27 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
518518
"""
519519
ma = MatrixArgs_init(parent, entries)
520520
cdef long i, j
521-
it = ma.iter(convert=False, sparse=True)
521+
it = ma.iter(False)
522522
R = ma.base
523523
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)
537540
else:
538541
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
564542

565543
cdef long _hash_(self) except -1:
566544
"""
@@ -3034,14 +3012,19 @@ cdef class Matrix_modn_dense_template(Matrix_dense):
30343012
if nrows == -1:
30353013
nrows = self._nrows - row
30363014

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))
30393017

30403018
if nrows < 0 or row < 0 or row + nrows > self._nrows:
30413019
raise IndexError("rows out of range")
30423020

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)
30453028
return M
30463029

30473030
def _matrices_from_rows(self, Py_ssize_t nrows, Py_ssize_t ncols):

0 commit comments

Comments
 (0)