Skip to content

Commit

Permalink
use cython-lint for dev/
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Aug 3, 2023
1 parent 3803f52 commit 083fcfe
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
34 changes: 17 additions & 17 deletions dev/Verify.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 = <SparseMatrixEntry *> 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):

Expand Down Expand Up @@ -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])
Expand Down
13 changes: 7 additions & 6 deletions dev/min_cython/cython_code/cymodule_one.pyx
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
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):
cdef TwoByTwoMatrix ans
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)



1 change: 1 addition & 0 deletions dev/min_cython/cython_code/cymodule_two.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion dev/min_cython/cython_headers/c_library.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
void multiply_GL2R(GL2RMatrix* A, GL2RMatrix* B, GL2RMatrix* C)

0 comments on commit 083fcfe

Please sign in to comment.