Skip to content

Modified iterator & counter type from int to Py_ssize_t throughout Matrix class #39965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sage/matrix/args.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ cdef class MatrixArgs:
# but do not check for positional row_keys, column_keys arguments
# -- we do not allow those, as they would be too easy to
# confuse with entries
cdef int k
cdef Py_ssize_t k
cdef long v
if self.nrows == -1 and self.ncols == -1:
for k in range(2):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/echelon_matrix.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def reduced_echelon_matrix_iterator(K, k, n, bint sparse=False, bint copy=True,
True
"""
cdef Matrix m0,m,mm
cdef int i
cdef Py_ssize_t i
n = int(n)
k = int(k)

Expand Down
5 changes: 3 additions & 2 deletions src/sage/matrix/matrix0.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3792,7 +3792,7 @@ cdef class Matrix(sage.structure.element.Matrix):
[1]
"""
cdef list L = []
cdef int i
cdef Py_ssize_t i

for i from 0 <= i < self._ncols:
if i not in d:
Expand Down Expand Up @@ -3854,7 +3854,8 @@ cdef class Matrix(sage.structure.element.Matrix):
"""
cdef dict d = {}
cdef list queue = list(range(self._ncols))
cdef int l, sign, i
cdef int l
cdef Py_ssize_t sign, i

if skew:
# testing the diagonal entries to be zero
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10584,7 +10584,7 @@ cdef class Matrix(Matrix1):
sage: a.density()
0
"""
cdef int x, y, k
cdef Py_ssize_t x, y, k
k = 0
nr = self.nrows()
nc = self.ncols()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix_cyclo_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
...
ValueError: echelon form mod 7 not defined
"""
cdef int i
cdef Py_ssize_t i

# Initialize variables
ls, _ = self._reductions(p)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix_gf2e_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
sage: A.list() == l # indirect doctest
True
"""
cdef int i,j
cdef Py_ssize_t i,j
l = []
for i from 0 <= i < self._nrows:
for j from 0 <= j < self._ncols:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix_gfpn_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ cdef class Matrix_gfpn_dense(Matrix_dense):
x = self.Data.Data
cdef int nr = self.Data.Nor
cdef int nc = self.Data.Noc
cdef int i, j
cdef Py_ssize_t i, j

FfSetField(fl)
FfSetNoc(nc)
Expand Down
5 changes: 3 additions & 2 deletions src/sage/matrix/matrix_integer_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ cdef class Matrix_integer_dense(Matrix_dense):
"""
# TODO: *maybe* redo this to use mpz_import and mpz_export
# from sec 5.14 of the GMP manual. ??
cdef int i, j, len_so_far, m, n
cdef Py_ssize_t i, j, len_so_far
cdef int m, n
cdef char *s
cdef char *t
cdef char *tmp
Expand Down Expand Up @@ -1530,7 +1531,7 @@ cdef class Matrix_integer_dense(Matrix_dense):
"""
cdef Integer h
cdef Matrix_integer_dense left = <Matrix_integer_dense>self
cdef int i, k
cdef Py_ssize_t i, k

nr = left._nrows
nc = right._ncols
Expand Down
16 changes: 9 additions & 7 deletions src/sage/matrix/matrix_mod2_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse
if self._nrows == 0 or self._ncols == 0:
return "[]"

cdef int i,j, last_i
cdef Py_ssize_t i,j, last_i
cdef list s = []
empty_row = b' '*(self._ncols*2-1)
cdef char *row_s
Expand Down Expand Up @@ -1040,7 +1040,7 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse
sage: A.list()
[]
"""
cdef int i,j
cdef Py_ssize_t i,j
l = []
for i from 0 <= i < self._nrows:
for j from 0 <= j < self._ncols:
Expand Down Expand Up @@ -1280,7 +1280,8 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse

cdef randstate rstate = current_randstate()

cdef int i, j, k
cdef Py_ssize_t i, j
cdef int k
cdef int nc
cdef unsigned int low, high
cdef m4ri_word mask = 0
Expand Down Expand Up @@ -1807,7 +1808,8 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse
610207
sage: assert l < 650000
"""
cdef int i,j, r,c, size
cdef Py_ssize_t i,j, r,c
cdef int size

r, c = self.nrows(), self.ncols()
if r == 0 or c == 0:
Expand Down Expand Up @@ -2497,7 +2499,7 @@ def unpickle_matrix_mod2_dense_v2(r, c, data, size, immutable=False):
from sage.matrix.constructor import Matrix
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF

cdef int i, j
cdef Py_ssize_t i, j
cdef Matrix_mod2_dense A

A = <Matrix_mod2_dense>Matrix(GF(2),r,c)
Expand Down Expand Up @@ -2563,7 +2565,7 @@ def from_png(filename):
from sage.matrix.constructor import Matrix
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF

cdef int i,j,r,c
cdef Py_ssize_t i,j,r,c
cdef Matrix_mod2_dense A

fn = open(filename,"r") # check filename
Expand Down Expand Up @@ -2608,7 +2610,7 @@ def to_png(Matrix_mod2_dense A, filename):
sage: A == B
True
"""
cdef int i,j, r,c
cdef Py_ssize_t i,j, r,c
r, c = A.nrows(), A.ncols()
if r == 0 or c == 0:
raise TypeError("Cannot write image with dimensions %d x %d"%(c,r))
Expand Down
6 changes: 3 additions & 3 deletions src/sage/matrix/matrix_modn_sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ cdef class Matrix_modn_sparse(Matrix_sparse):
[1 0 0]
[0 0 0]
"""
cdef int i, j
cdef Py_ssize_t i, j
cdef c_vector_modint row
cdef Matrix_modn_sparse B

Expand Down Expand Up @@ -594,7 +594,7 @@ cdef class Matrix_modn_sparse(Matrix_sparse):
[6 7 8]
[3 4 5]
"""
cdef int i,k
cdef Py_ssize_t i,k
cdef Matrix_modn_sparse A
cdef c_vector_modint row

Expand Down Expand Up @@ -632,7 +632,7 @@ cdef class Matrix_modn_sparse(Matrix_sparse):
[5 4]
[8 7]
"""
cdef int i,j
cdef Py_ssize_t i,j
cdef Matrix_modn_sparse A
cdef c_vector_modint row

Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix_mpolynomial_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ cdef class Matrix_mpolynomial_dense(Matrix_generic_dense):
"""
from sage.matrix.constructor import matrix

cdef int c, r, i, j, rc, start_row, nr, nc
cdef Py_ssize_t c, r, i, j, rc, start_row, nr, nc

x = self.fetch('in_echelon_form_row_reduction')
if x is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix_rational_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ cdef class Matrix_rational_dense(Matrix_dense):

cdef int fmpz_height(self, fmpz_t h) except -1:
cdef fmpz_t x
cdef int i, j
cdef Py_ssize_t i, j
sig_on()
fmpz_init(x)
fmpz_zero(h)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix_rational_sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ cdef class Matrix_rational_sparse(Matrix_sparse):
cdef mpz_t x, h
mpz_init(x)
mpz_init_set_si(h, 0)
cdef int i, j
cdef Py_ssize_t i, j
sig_on()
for i from 0 <= i < self._nrows:
for j from 0 <= j < self._matrix[i].num_nonzero:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix_sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ cdef class Matrix_sparse(matrix.Matrix):
sage: (v * m).parent() is m.row(0).parent()
True
"""
cdef int i, j
cdef Py_ssize_t i, j
if self._nrows != v._degree:
raise ArithmeticError("number of rows of matrix must equal degree of vector")
parent = self.row_ambient_module(base_ring=None, sparse=v.is_sparse_c())
Expand Down Expand Up @@ -1202,7 +1202,7 @@ cdef class Matrix_sparse(matrix.Matrix):
sage: M*w
(x*y)
"""
cdef int i, j
cdef Py_ssize_t i, j
if self._ncols != v._degree:
raise ArithmeticError("number of columns of matrix must equal degree of vector")
parent = self.column_ambient_module(base_ring=None, sparse=v.is_sparse_c())
Expand Down
Loading