diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8b9efdee1..ef12aaa16 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,6 +13,7 @@ jobs: run: | sudo apt-get install -y codespell sudo apt-get install -y pycodestyle + sudo pip install cython-lint - name: Run codespell shell: bash -l {0} run: codespell -L ans,arithmetics,inout,trough,compresser,rime,ba python @@ -22,6 +23,9 @@ jobs: run: | pycodestyle --select=E111,E21,E221,E222,E225,E227,E228,E241,E251,E262,E265,E271,E272,E30,E401,E701,E702,E703,E704,E711,E713,E714,E721,W2,W3,W6 python/ pycodestyle --filename=*.pyx --select=W2 cython/ + - name: Run cython-lint + shell: bash -l {0} + run: cython-lint --ignore=E501,E741 dev env: MAKEFLAGS: -j2 diff --git a/dev/Verify.pyx b/dev/Verify.pyx index 2a3592fc9..427bca666 100644 --- a/dev/Verify.pyx +++ b/dev/Verify.pyx @@ -12,13 +12,13 @@ from sage.matrix.matrix_generic_dense cimport Matrix_generic_dense from sage.matrix.matrix_space import MatrixSpace cdef struct SparseMatrixEntry: - int row_number - mpfi_t real - mpfi_t imag - + int row_number + mpfi_t real + mpfi_t imag + cdef struct SparseMatrixColumn: - SparseMatrixEntry * entries - int number_entries + SparseMatrixEntry * entries + int number_entries cdef class ComplexIntervalColumnSparseMatrix(): cdef int _nrows @@ -28,7 +28,7 @@ cdef class ComplexIntervalColumnSparseMatrix(): def __cinit__(ComplexIntervalColumnSparseMatrix self, list columns, int num_rows): - cdef int i, j, k, l + cdef int i, j, k, length cdef ComplexIntervalFieldElement z self._columns = NULL @@ -52,24 +52,24 @@ cdef class ComplexIntervalColumnSparseMatrix(): for i in range(self._ncols): column = columns[i] - l = len(column) - if l > 0: + length = len(column) + if length > 0: self._columns[i].entries = malloc( - l * sizeof(SparseMatrixEntry)); - self._columns[i].number_entries = l - for j in range(l): + length * sizeof(SparseMatrixEntry)) + self._columns[i].number_entries = length + for j in range(length): mpfi_init2(self._columns[i].entries[j].real, self._prec) mpfi_init2(self._columns[i].entries[j].imag, self._prec) - - for j in range(l): + + for j in range(length): k, z = column[j] - if not (k >= 0 and k < self._nrows): + if not (0 <= k < self._nrows): raise IndexError( "Invalid row index in column sparse matrix") self._columns[i].entries[j].row_number = k mpfi_set(self._columns[i].entries[j].real, z.__re) mpfi_set(self._columns[i].entries[j].imag, z.__im) - + def __rmul__(ComplexIntervalColumnSparseMatrix self, Matrix_complex_double_dense m): @@ -104,7 +104,7 @@ cdef class ComplexIntervalColumnSparseMatrix(): mpfi_add(z.__re, z.__re, tmp) mpfi_mul_d(tmp, self._columns[j].entries[k].imag, reim[1]) mpfi_sub(z.__re, z.__re, tmp) - + mpfi_mul_d(tmp, self._columns[j].entries[k].real, reim[1]) mpfi_add(z.__im, z.__im, tmp) mpfi_mul_d(tmp, self._columns[j].entries[k].imag, reim[0]) diff --git a/dev/min_cython/cython_code/cymodule_one.pyx b/dev/min_cython/cython_code/cymodule_one.pyx index 0c965e0c4..678963d46 100644 --- a/dev/min_cython/cython_code/cymodule_one.pyx +++ b/dev/min_cython/cython_code/cymodule_one.pyx @@ -1,25 +1,29 @@ cimport c_library + def timestwo(int x): return c_library.timestwo(x) + def square(int x): return c_library.square(x) + cdef copy_to_GL2RMatrix(M, c_library.GL2RMatrix* N): cdef int i, j for i in range(2): for j in range(2): N.entries[i][j] = M[i][j] + cdef class TwoByTwoMatrix(): # C attributes that are defined in the "pxd" header file. # # cdef c_library.GL2RMatrix matrix - + def __cinit__(self, matrix=None): if matrix is None: - matrix = [[0,0],[0,0]] + matrix = [[0, 0], [0, 0]] copy_to_GL2RMatrix(matrix, &self.matrix) def __mul__(TwoByTwoMatrix self, TwoByTwoMatrix other): @@ -27,11 +31,8 @@ cdef class TwoByTwoMatrix(): ans = TwoByTwoMatrix() c_library.multiply_GL2R(&self.matrix, &other.matrix, &ans.matrix) return ans - + def __repr__(self): a, b = self.matrix.entries[0][0], self.matrix.entries[0][1] c, d = self.matrix.entries[1][0], self.matrix.entries[1][1] return "TwoByTwoMatrix([(%d, %d), (%d, %d)])" % (a, b, c, d) - - - diff --git a/dev/min_cython/cython_code/cymodule_two.pyx b/dev/min_cython/cython_code/cymodule_two.pyx index 19b68ee40..f0f153e05 100644 --- a/dev/min_cython/cython_code/cymodule_two.pyx +++ b/dev/min_cython/cython_code/cymodule_two.pyx @@ -7,6 +7,7 @@ cdef add_GL2R_matrices(GL2RMatrix* A, GL2RMatrix* B, GL2RMatrix* C): for j in range(2): C.entries[i][j] = A.entries[i][j] + B.entries[i][j] + def add_matrices(TwoByTwoMatrix A, TwoByTwoMatrix B): cdef TwoByTwoMatrix C C = TwoByTwoMatrix() diff --git a/dev/min_cython/cython_headers/c_library.pxd b/dev/min_cython/cython_headers/c_library.pxd index 44df147c2..d97b14196 100644 --- a/dev/min_cython/cython_headers/c_library.pxd +++ b/dev/min_cython/cython_headers/c_library.pxd @@ -3,4 +3,4 @@ cdef extern from "c_library.h": int square(int) ctypedef struct GL2RMatrix: int entries[2][2] - void multiply_GL2R(GL2RMatrix* A, GL2RMatrix* B, GL2RMatrix* C) \ No newline at end of file + void multiply_GL2R(GL2RMatrix* A, GL2RMatrix* B, GL2RMatrix* C)