Skip to content

Commit

Permalink
fix and activate pycodestyle E301 in pyx files
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Aug 12, 2023
1 parent 0fd5967 commit 2d47da7
Show file tree
Hide file tree
Showing 30 changed files with 142 additions and 137 deletions.
1 change: 0 additions & 1 deletion src/sage/graphs/edge_connectivity.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,6 @@ cdef class GabowEdgeConnectivity:
raise ValueError("the value of the edge connectivity has not been "
"properly computed. This may result from an interruption")


#
# Packing arborescences
#
Expand Down
49 changes: 18 additions & 31 deletions src/sage/libs/giac/giac.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,10 @@ cdef class Pygen(GiacMethods_base):
GIAC_archive( <string>encstring23(filename), (<Pygen>self).gptr[0], context_ptr)
sig_off()
# NB: with giac <= 1.2.3-57 redim doesn't have a non evaluated for so Pygen('redim') fails.
# hence replacement for redim:
def redim(self,a,b=None):
def redim(self, a, b=None):
"""
Increase the size of a matrix when possible, otherwise return self.
Expand Down Expand Up @@ -1677,11 +1676,11 @@ cdef class Pygen(GiacMethods_base):
xyplot=[[(u.real())._double,(u.im())._double] for u in l]
if (xyscat != []):
result=scatter_plot(xyscat)
if xyscat:
result = scatter_plot(xyscat)
else:
result=line(xyplot)
result = line(xyplot)
sig_off()
return result
Expand All @@ -1695,11 +1694,11 @@ cdef class Pygen(GiacMethods_base):
#
# # # # # # # # # # # # # # # # # # # # # # # # #
def __richcmp__( self, other,op):
def __richcmp__(self, other, op):
if not isinstance(other, Pygen):
other=Pygen(other)
other = Pygen(other)
if not isinstance(self, Pygen):
self=Pygen(self)
self = Pygen(self)
sig_on()
result= giacgenrichcmp((<Pygen>self).gptr[0],(<Pygen>other).gptr[0], op, context_ptr )
sig_off()
Expand All @@ -1708,10 +1707,11 @@ cdef class Pygen(GiacMethods_base):
#
# Some attributes of the gen class:
#
property _type:
def __get__(self):
sig_on()
result=self.gptr.type
result = self.gptr.type
sig_off()
return result
Expand All @@ -1723,30 +1723,27 @@ cdef class Pygen(GiacMethods_base):
sig_off()
return result
property _val: # immediate int (type _INT_)
"""
immediate int value of an _INT_ type gen.
"""
def __get__(self):
if(self._type == 0):
if self._type == 0:
sig_on()
result=self.gptr.val
result = self.gptr.val
sig_off()
return result
else:
raise TypeError("cannot convert non _INT_ giac gen")
property _double: # immediate double (type _DOUBLE_)
"""
immediate conversion to float for a gen of _DOUBLE_ type.
"""
def __get__(self):
if(self._type == 1):
if self._type == 1:
sig_on()
result=self.gptr._DOUBLE_val
result = self.gptr._DOUBLE_val
sig_off()
return result
else:
Expand All @@ -1756,8 +1753,6 @@ cdef class Pygen(GiacMethods_base):
def __get__(self):
return self._help()
###################################################
# Add the others methods
###################################################
Expand All @@ -1767,30 +1762,22 @@ cdef class Pygen(GiacMethods_base):
#
# def __getattr__(self, name):
# return GiacMethods[str(name)](self)
##
# test
#test
def giacAiry_Ai(self, *args):
cdef gen result=GIAC_Airy_Ai(self.gptr[0], context_ptr)
cdef gen result = GIAC_Airy_Ai(self.gptr[0], context_ptr)
return _wrap_gen(result)
def giacifactor(self, *args):
cdef gen result
sig_on()
result=GIAC_eval(self.gptr[0], <int>1, context_ptr)
result=GIAC_ifactor(result, context_ptr)
result = GIAC_eval(self.gptr[0], <int>1, context_ptr)
result = GIAC_ifactor(result, context_ptr)
sig_off()
return _wrap_gen(result)
##
################################################################
# A wrapper from a cpp element of type giac gen to create #
# the Python object #
Expand Down
3 changes: 3 additions & 0 deletions src/sage/matrix/constructor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,13 @@ def matrix(*args, **kwds):
M.set_immutable()
return M


Matrix = matrix


from .special import *


@matrix_method
class options(GlobalOptions):
r"""
Expand Down
46 changes: 21 additions & 25 deletions src/sage/matrix/matrix0.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -581,26 +581,25 @@ cdef class Matrix(sage.structure.element.Matrix):

self.set_unsafe(i, j, elt + self.get_unsafe(i, j))


## def _get_very_unsafe(self, i, j):
## r"""
## Entry access, but potentially fast since it might be without
## bounds checking. (I know of no cases where this is actually
## faster.)

## This function it can very easily !! SEG FAULT !! if you call
## it with invalid input. Use with *extreme* caution.

## EXAMPLES::
##
## sage: a = matrix(ZZ,2,range(4))
## sage: a._get_very_unsafe(0,1)
## 1

## If you do \code{a.\_get\_very\_unsafe(0,10)} you'll very likely crash Sage
## completely.
## """
## return self.get_unsafe(i, j)
## def _get_very_unsafe(self, i, j):
## r"""
## Entry access, but potentially fast since it might be without
## bounds checking. (I know of no cases where this is actually
## faster.)

## This function it can very easily !! SEG FAULT !! if you call
## it with invalid input. Use with *extreme* caution.

## EXAMPLES::
##
## sage: a = matrix(ZZ,2,range(4))
## sage: a._get_very_unsafe(0,1)
## 1

## If you do \code{a.\_get\_very\_unsafe(0,10)} you'll very likely crash Sage
## completely.
## """
## return self.get_unsafe(i, j)

def __iter__(self):
"""
Expand Down Expand Up @@ -2239,11 +2238,10 @@ cdef class Matrix(sage.structure.element.Matrix):

return "\\left" + matrix_delimiters[0] + "\\begin{array}{%s}\n"%format + s + "\n\\end{array}\\right" + matrix_delimiters[1]



###################################################
## Basic Properties
###################################################

def ncols(self):
"""
Return the number of columns of this matrix.
Expand Down Expand Up @@ -2311,22 +2309,20 @@ cdef class Matrix(sage.structure.element.Matrix):
"""
return (self._nrows,self._ncols)


###################################################
# Functions
###################################################

def act_on_polynomial(self, f):
r"""
Return the polynomial f(self\*x).
INPUT:
- ``self`` - an nxn matrix
- ``f`` - a polynomial in n variables x=(x1,...,xn)
OUTPUT: The polynomial f(self\*x).
EXAMPLES::
Expand Down
7 changes: 3 additions & 4 deletions src/sage/matrix/matrix1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1461,10 +1461,10 @@ cdef class Matrix(Matrix0):
tmp = [self.get_unsafe(i,j) for j in range(self._ncols)]
return V(tmp, coerce=False, copy=False, check=False)


###########################################################################
# Building matrices out of other matrices, rows, or columns
###########################################################################

def stack(self, bottom, subdivide=False):
r"""
Return a new matrix formed by appending the matrix (or vector)
Expand Down Expand Up @@ -2521,10 +2521,9 @@ cdef class Matrix(Matrix0):
M.set_unsafe(i, j, one)
return M


####################################################################################
######################################################################
# Change of representation between dense and sparse.
####################################################################################
######################################################################

def dense_matrix(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ def ideal_or_fractional(R, *args):
R = R.number_field()
return R.ideal(*args)


_Fields = Fields()


cdef class Matrix(Matrix1):
"""
Base class for matrices, part 2
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 @@ -814,7 +814,6 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
A._matrix = -self._matrix
return A


########################################################################
# LEVEL 3 functionality (Optional)
# * __deepcopy__
Expand All @@ -824,6 +823,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense):
# * Specialized echelon form
# * tensor product
########################################################################

def set_immutable(self):
"""
Change this matrix so that it is immutable.
Expand Down
7 changes: 2 additions & 5 deletions src/sage/matrix/matrix_integer_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,6 @@ cdef class Matrix_integer_dense(Matrix_dense):
sig_off()
return ans


########################################################################
# LEVEL 3 functionality (Optional)
# * __deepcopy__
Expand Down Expand Up @@ -2743,10 +2742,9 @@ cdef class Matrix_integer_dense(Matrix_dense):
import sage.libs.ntl.ntl_mat_ZZ
return sage.libs.ntl.ntl_mat_ZZ.ntl_mat_ZZ(self._nrows,self._ncols, self.list())


####################################################################################
#######################################################################
# LLL
####################################################################################
#######################################################################

def BKZ(self, delta=None, algorithm="fpLLL", fp=None, block_size=10, prune=0,
use_givens=False, precision=0, proof=None, **kwds):
Expand Down Expand Up @@ -5165,7 +5163,6 @@ cdef class Matrix_integer_dense(Matrix_dense):
sig_free(T_rows)
return res


#################################################################
# operations with matrices
#################################################################
Expand Down
2 changes: 2 additions & 0 deletions src/sage/matrix/matrix_mod2_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2057,11 +2057,13 @@ def unpickle_matrix_mod2_dense_v2(r, c, data, size, immutable=False):

return A


from sage.misc.persist import register_unpickle_override
register_unpickle_override('sage.matrix.matrix_mod2_dense',
'unpickle_matrix_mod2_dense_v1',
unpickle_matrix_mod2_dense_v2)


def from_png(filename):
"""
Returns a dense matrix over GF(2) from a 1-bit PNG image read from
Expand Down
25 changes: 12 additions & 13 deletions src/sage/matrix/matrix_rational_sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ cdef class Matrix_rational_sparse(Matrix_sparse):
mpq_clear(s)
return ans


########################################################################
# def _pickle(self):
# def _unpickle(self, data, int version): # use version >= 0
Expand All @@ -281,20 +280,21 @@ cdef class Matrix_rational_sparse(Matrix_sparse):
# def _multiply_classical(left, matrix.Matrix _right):
# def _list(self):

# TODO
## cpdef _lmul_(self, Element right):
## """
## EXAMPLES::
##
## sage: a = matrix(QQ,2,range(6))
## sage: (3/4) * a
## [ 0 3/4 3/2]
## [ 9/4 3 15/4]
## """
# TODO
## cpdef _lmul_(self, Element right):
## """
## EXAMPLES::
##
## sage: a = matrix(QQ,2,range(6))
## sage: (3/4) * a
## [ 0 3/4 3/2]
## [ 9/4 3 15/4]
## """

def _dict(self):
"""
Unsafe version of the dict method, mainly for internal use.
This may return the dict of elements, but as an *unsafe*
reference to the underlying dict of the object. It might
be dangerous if you change entries of the returned dict.
Expand All @@ -313,7 +313,6 @@ cdef class Matrix_rational_sparse(Matrix_sparse):
self.cache('dict', d)
return d


########################################################################
# LEVEL 3 functionality (Optional)
# * cdef _sub_
Expand All @@ -325,7 +324,7 @@ cdef class Matrix_rational_sparse(Matrix_sparse):

def _nonzero_positions_by_row(self, copy=True):
"""
Returns the list of pairs (i,j) such that self[i,j] != 0.
Return the list of pairs (i,j) such that self[i,j] != 0.
It is safe to change the resulting list (unless you give the option copy=False).
Expand Down
Loading

0 comments on commit 2d47da7

Please sign in to comment.