From 2d47da72837e4a4c065e77c0089f01457e2d333b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 12 Aug 2023 11:20:03 +0200 Subject: [PATCH 1/2] fix and activate pycodestyle E301 in pyx files --- src/sage/graphs/edge_connectivity.pyx | 1 - src/sage/libs/giac/giac.pyx | 49 +++++--------- src/sage/matrix/constructor.pyx | 3 + src/sage/matrix/matrix0.pyx | 46 ++++++------- src/sage/matrix/matrix1.pyx | 7 +- src/sage/matrix/matrix2.pyx | 2 + src/sage/matrix/matrix_cyclo_dense.pyx | 2 +- src/sage/matrix/matrix_integer_dense.pyx | 7 +- src/sage/matrix/matrix_mod2_dense.pyx | 2 + src/sage/matrix/matrix_rational_sparse.pyx | 25 ++++--- src/sage/matrix/strassen.pyx | 2 + src/sage/misc/binary_tree.pyx | 67 ++++++++++++------- src/sage/misc/c3_controlled.pyx | 1 + src/sage/misc/parser.pyx | 1 + src/sage/misc/weak_dict.pyx | 1 + src/sage/modules/vector_double_dense.pyx | 2 +- .../numerical/backends/generic_backend.pyx | 2 +- src/sage/rings/complex_double.pyx | 2 +- src/sage/rings/complex_mpfr.pyx | 2 - src/sage/rings/integer_ring.pyx | 4 +- .../number_field_element_quadratic.pyx | 7 +- .../padics/padic_capped_relative_element.pyx | 1 + .../padics/padic_floating_point_element.pyx | 1 + src/sage/rings/polynomial/hilbert.pyx | 2 + src/sage/rings/polynomial/plural.pyx | 7 +- .../rings/polynomial/polynomial_compiled.pyx | 19 ++++-- .../skew_polynomial_finite_field.pyx | 2 +- src/sage/rings/real_double.pyx | 3 - src/sage/structure/sage_object.pyx | 7 +- src/tox.ini | 2 +- 30 files changed, 142 insertions(+), 137 deletions(-) diff --git a/src/sage/graphs/edge_connectivity.pyx b/src/sage/graphs/edge_connectivity.pyx index 02326437a54..014e46f7500 100644 --- a/src/sage/graphs/edge_connectivity.pyx +++ b/src/sage/graphs/edge_connectivity.pyx @@ -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 # diff --git a/src/sage/libs/giac/giac.pyx b/src/sage/libs/giac/giac.pyx index a78e2199725..c5f738eadc0 100644 --- a/src/sage/libs/giac/giac.pyx +++ b/src/sage/libs/giac/giac.pyx @@ -1266,11 +1266,10 @@ cdef class Pygen(GiacMethods_base): GIAC_archive( encstring23(filename), (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. @@ -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 @@ -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((self).gptr[0],(other).gptr[0], op, context_ptr ) sig_off() @@ -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 @@ -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: @@ -1756,8 +1753,6 @@ cdef class Pygen(GiacMethods_base): def __get__(self): return self._help() - - ################################################### # Add the others methods ################################################### @@ -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], 1, context_ptr) - result=GIAC_ifactor(result, context_ptr) + result = GIAC_eval(self.gptr[0], 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 # diff --git a/src/sage/matrix/constructor.pyx b/src/sage/matrix/constructor.pyx index ae4652c45f8..744f8aaf3fd 100644 --- a/src/sage/matrix/constructor.pyx +++ b/src/sage/matrix/constructor.pyx @@ -645,10 +645,13 @@ def matrix(*args, **kwds): M.set_immutable() return M + Matrix = matrix + from .special import * + @matrix_method class options(GlobalOptions): r""" diff --git a/src/sage/matrix/matrix0.pyx b/src/sage/matrix/matrix0.pyx index 572936b9c42..950661b373a 100644 --- a/src/sage/matrix/matrix0.pyx +++ b/src/sage/matrix/matrix0.pyx @@ -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): """ @@ -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. @@ -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:: diff --git a/src/sage/matrix/matrix1.pyx b/src/sage/matrix/matrix1.pyx index 8983192931b..fb1e4ecb819 100644 --- a/src/sage/matrix/matrix1.pyx +++ b/src/sage/matrix/matrix1.pyx @@ -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) @@ -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): """ diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index 2053bca80c3..94378adc8a1 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -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 diff --git a/src/sage/matrix/matrix_cyclo_dense.pyx b/src/sage/matrix/matrix_cyclo_dense.pyx index 0b78bb7fd78..15ff6394951 100644 --- a/src/sage/matrix/matrix_cyclo_dense.pyx +++ b/src/sage/matrix/matrix_cyclo_dense.pyx @@ -814,7 +814,6 @@ cdef class Matrix_cyclo_dense(Matrix_dense): A._matrix = -self._matrix return A - ######################################################################## # LEVEL 3 functionality (Optional) # * __deepcopy__ @@ -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. diff --git a/src/sage/matrix/matrix_integer_dense.pyx b/src/sage/matrix/matrix_integer_dense.pyx index 7fe211835cc..a49c07b1010 100644 --- a/src/sage/matrix/matrix_integer_dense.pyx +++ b/src/sage/matrix/matrix_integer_dense.pyx @@ -1094,7 +1094,6 @@ cdef class Matrix_integer_dense(Matrix_dense): sig_off() return ans - ######################################################################## # LEVEL 3 functionality (Optional) # * __deepcopy__ @@ -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): @@ -5165,7 +5163,6 @@ cdef class Matrix_integer_dense(Matrix_dense): sig_free(T_rows) return res - ################################################################# # operations with matrices ################################################################# diff --git a/src/sage/matrix/matrix_mod2_dense.pyx b/src/sage/matrix/matrix_mod2_dense.pyx index d5a368d9b70..777ce0b409f 100644 --- a/src/sage/matrix/matrix_mod2_dense.pyx +++ b/src/sage/matrix/matrix_mod2_dense.pyx @@ -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 diff --git a/src/sage/matrix/matrix_rational_sparse.pyx b/src/sage/matrix/matrix_rational_sparse.pyx index 37576901d30..e1bb904949d 100644 --- a/src/sage/matrix/matrix_rational_sparse.pyx +++ b/src/sage/matrix/matrix_rational_sparse.pyx @@ -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 @@ -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. @@ -313,7 +313,6 @@ cdef class Matrix_rational_sparse(Matrix_sparse): self.cache('dict', d) return d - ######################################################################## # LEVEL 3 functionality (Optional) # * cdef _sub_ @@ -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). diff --git a/src/sage/matrix/strassen.pyx b/src/sage/matrix/strassen.pyx index ab392d66cb1..6cb88d596fd 100644 --- a/src/sage/matrix/strassen.pyx +++ b/src/sage/matrix/strassen.pyx @@ -48,6 +48,7 @@ def strassen_window_multiply(C, A,B, cutoff): """ strassen_window_multiply_c(C, A, B, cutoff) + cdef strassen_window_multiply_c(MatrixWindow C, MatrixWindow A, MatrixWindow B, Py_ssize_t cutoff): # todo -- I'm not sure how to interpret "cutoff". Should it be... @@ -312,6 +313,7 @@ def strassen_echelon(MatrixWindow A, cutoff): strassen_echelon_c(A, cutoff, A._matrix._strassen_default_cutoff(A._matrix)) sig_off() + cdef strassen_echelon_c(MatrixWindow A, Py_ssize_t cutoff, Py_ssize_t mul_cutoff): # The following notation will be used in the comments below, which should be understood to give # the general idea of what's going on, as if there were no inconvenient non-pivot columns. diff --git a/src/sage/misc/binary_tree.pyx b/src/sage/misc/binary_tree.pyx index 0266699d02b..214c6721d3d 100644 --- a/src/sage/misc/binary_tree.pyx +++ b/src/sage/misc/binary_tree.pyx @@ -1,13 +1,12 @@ """ Binary trees -Implements a binary tree in Cython. +This implements a binary tree in Cython. AUTHORS: - Tom Boothby (2007-02-15). Initial version free for any use (public domain). """ - from cysignals.memory cimport sig_malloc, sig_free from cpython.ref cimport PyObject, Py_INCREF, Py_XDECREF @@ -186,6 +185,7 @@ cdef class BinaryTree: """ def __cinit__(BinaryTree self): self.head = NULL + def __dealloc__(BinaryTree self): """ TESTS: @@ -212,8 +212,11 @@ cdef class BinaryTree: def insert(BinaryTree self, object key, object value = None): """ - Inserts a key-value pair into the BinaryTree. Duplicate keys are ignored. - The first parameter, key, should be an int, or coercible (one-to-one) into an int. + Insert a key-value pair into the BinaryTree. + + Duplicate keys are ignored. + The first parameter, key, should be an int, or coercible (one-to-one) + into an int. EXAMPLES:: @@ -234,9 +237,10 @@ cdef class BinaryTree: self.head = BinaryTreeNode(ckey, value) else: binary_tree_insert(self.head, ckey, value) + def delete(BinaryTree self, int key): """ - Removes a the node corresponding to key, and returns the value + Remove a the node corresponding to key, and return the value associated with it. EXAMPLES:: @@ -277,9 +281,10 @@ cdef class BinaryTree: return r else: return binary_tree_delete(self.head, key) + def get(BinaryTree self, int key): """ - Returns the value associated with the key given. + Return the value associated with the key given. EXAMPLES:: @@ -295,10 +300,11 @@ cdef class BinaryTree: return None else: return binary_tree_get(self.head, key) + def contains(BinaryTree self, int key): """ - Returns True if a node with the given key exists - in the tree, and False otherwise. + Return ``True`` if a node with the given key exists + in the tree, and ``False`` otherwise. EXAMPLES:: @@ -317,9 +323,10 @@ cdef class BinaryTree: return True else: return False + def get_max(BinaryTree self): """ - Returns the value of the node with the maximal key value. + Return the value of the node with the maximal key value. """ cdef binary_tree_node *cur if self.head == NULL: @@ -328,9 +335,10 @@ cdef class BinaryTree: while cur.right != NULL: cur = cur.right return cur.value + def get_min(BinaryTree self): """ - Returns the value of the node with the minimal key value. + Return the value of the node with the minimal key value. """ cdef binary_tree_node *cur if self.head == NULL: @@ -339,10 +347,11 @@ cdef class BinaryTree: while cur.left != NULL: cur = cur.left return cur.value + def pop_max(BinaryTree self): """ - Returns the value of the node with the maximal key value, - and removes that node from the tree. + Return the value of the node with the maximal key value, + and remove that node from the tree. EXAMPLES:: @@ -379,10 +388,11 @@ cdef class BinaryTree: max = cur.right.value cur.right = binary_tree_right_excise(cur.right) return max + def pop_min(BinaryTree self): """ - Returns the value of the node with the minimal key value, - and removes that node from the tree. + Return the value of the node with the minimal key value, + and remove that node from the tree. EXAMPLES:: @@ -422,7 +432,7 @@ cdef class BinaryTree: def is_empty(BinaryTree self): """ - Returns True if the tree has no nodes. + Return ``True`` if the tree has no nodes. EXAMPLES:: @@ -438,7 +448,9 @@ cdef class BinaryTree: def keys(BinaryTree self, order="inorder"): """ - Returns the keys sorted according to "order" parameter, which can be one of + Return the keys sorted according to "order" parameter. + + The order can be one of "inorder", "preorder", or "postorder" """ if self.head == NULL: @@ -455,7 +467,9 @@ cdef class BinaryTree: def values(BinaryTree self, order="inorder"): """ - Returns the keys sorted according to "order" parameter, which can be one of + Return the keys sorted according to "order" parameter. + + The order can be one of "inorder", "preorder", or "postorder" """ if self.head == NULL: @@ -473,13 +487,12 @@ cdef class BinaryTree: def _headkey_(BinaryTree self): """ Used by the stress tester. Don't think a user would care. + Email tom if you care what the headkey is. """ if self.head == NULL: return 0 - else: - return self.head.key - + return self.head.key class Test: @@ -488,11 +501,13 @@ class Test: def binary_tree(self, values = 100, cycles = 100000): """ - Performs a sequence of random operations, given random inputs - to stress test the binary tree structure. This was useful during - development to find memory leaks / segfaults. Cycles should be - at least 100 times as large as values, or the delete, contains, - and get methods won't hit very often. + Perform a sequence of random operations, given random inputs + to stress test the binary tree structure. + + This was useful during development to find memory leaks / + segfaults. Cycles should be at least 100 times as large as + values, or the delete, contains, and get methods won't hit + very often. INPUT: @@ -509,7 +524,7 @@ class Test: for i in range(cycles): r = randint(0, 8) s = randint(0, values) - if r==1: + if r == 1: t.insert(s) elif r == 2: t.delete(t._headkey_()) diff --git a/src/sage/misc/c3_controlled.pyx b/src/sage/misc/c3_controlled.pyx index ebadb070d1d..b3f4b701cd5 100644 --- a/src/sage/misc/c3_controlled.pyx +++ b/src/sage/misc/c3_controlled.pyx @@ -488,6 +488,7 @@ cdef class CmpKey: True """ cdef int count + def __init__(self): """ Sets the internal category counter to zero. diff --git a/src/sage/misc/parser.pyx b/src/sage/misc/parser.pyx index 78c2d6d0169..e944758a387 100644 --- a/src/sage/misc/parser.pyx +++ b/src/sage/misc/parser.pyx @@ -1043,6 +1043,7 @@ cdef class Parser: cdef class LookupNameMaker: cdef object names cdef object fallback + def __init__(self, names, fallback=None): """ This class wraps a dictionary as a callable for use in creating names. diff --git a/src/sage/misc/weak_dict.pyx b/src/sage/misc/weak_dict.pyx index 59a399fed20..977c3dc6e55 100644 --- a/src/sage/misc/weak_dict.pyx +++ b/src/sage/misc/weak_dict.pyx @@ -162,6 +162,7 @@ cdef class WeakValueDictEraser: - Nils Bruin (2013-11) """ cdef D + def __init__(self, D): """ INPUT: diff --git a/src/sage/modules/vector_double_dense.pyx b/src/sage/modules/vector_double_dense.pyx index 2d581606980..e6363c3b0a7 100644 --- a/src/sage/modules/vector_double_dense.pyx +++ b/src/sage/modules/vector_double_dense.pyx @@ -471,10 +471,10 @@ cdef class Vector_double_dense(Vector_numpy_dense): # p = 0 returns integer *count* of non-zero entries return RDF(n) - ############################# # statistics ############################# + def mean(self): """ Calculate the arithmetic mean of the vector. diff --git a/src/sage/numerical/backends/generic_backend.pyx b/src/sage/numerical/backends/generic_backend.pyx index 20eb36cbd00..f8e60694a1b 100644 --- a/src/sage/numerical/backends/generic_backend.pyx +++ b/src/sage/numerical/backends/generic_backend.pyx @@ -1288,8 +1288,8 @@ cdef class GenericBackend: del cp self._do_test_problem_data(tester, cpcp) - # TODO: We should have a more systematic way of generating MIPs for testing. + @classmethod def _test_copy_some_mips(cls, tester=None, **options): p = cls() # fresh instance of the backend diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 4a978027a87..132ae733eb9 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -1986,10 +1986,10 @@ cdef class ComplexDoubleElement(FieldElement): """ return self._new_c(gsl_complex_arcsec(self._complex)) - ####################################################################### # Complex Hyperbolic Functions ####################################################################### + def sinh(self): r""" This function returns the complex hyperbolic sine of the complex diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 866d5e50701..33d73d81b12 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -379,7 +379,6 @@ class ComplexField_class(sage.rings.abc.ComplexField): """ return ComplexField(prec) - # very useful to cache this. def _real_field(self): """ @@ -2070,7 +2069,6 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): return infinity.infinity raise NotImplementedError("order of element not known") - ######################################################################## # Plotting ######################################################################## diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index 8452beaa412..b4046098436 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -1455,10 +1455,10 @@ cdef class IntegerRing_class(PrincipalIdealDomain): return roots - ################################# - ## Coercions to interfaces + # Coercions to interfaces ################################# + def _gap_init_(self): """ Return a GAP representation of ``self``. diff --git a/src/sage/rings/number_field/number_field_element_quadratic.pyx b/src/sage/rings/number_field/number_field_element_quadratic.pyx index 4982fc0cd7d..6ca89a6aa4a 100644 --- a/src/sage/rings/number_field/number_field_element_quadratic.pyx +++ b/src/sage/rings/number_field/number_field_element_quadratic.pyx @@ -1996,10 +1996,9 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ return self * self.denominator() - -######################################################### -# Some things are so much easier to compute -######################################################### + ######################################################### + # Some things are so much easier to compute + ######################################################### def trace(self): """ diff --git a/src/sage/rings/padics/padic_capped_relative_element.pyx b/src/sage/rings/padics/padic_capped_relative_element.pyx index d393708979d..f09708db2c7 100644 --- a/src/sage/rings/padics/padic_capped_relative_element.pyx +++ b/src/sage/rings/padics/padic_capped_relative_element.pyx @@ -235,6 +235,7 @@ cdef class pAdicCappedRelativeElement(CRElement): self.prime_pow.prime.value, self.prime_pow.pow_mpz_t_tmp(self.relprec), self.unit) + def _integer_(self, Z=None): r""" Return an integer congruent to this element modulo diff --git a/src/sage/rings/padics/padic_floating_point_element.pyx b/src/sage/rings/padics/padic_floating_point_element.pyx index 13eb30a3abc..d6153a1f673 100644 --- a/src/sage/rings/padics/padic_floating_point_element.pyx +++ b/src/sage/rings/padics/padic_floating_point_element.pyx @@ -223,6 +223,7 @@ cdef class pAdicFloatingPointElement(FPElement): self.prime_pow.prime.value, self.prime_pow.pow_mpz_t_top(), self.unit) + def _integer_(self, Z=None): r""" Return an integer congruent to this element modulo diff --git a/src/sage/rings/polynomial/hilbert.pyx b/src/sage/rings/polynomial/hilbert.pyx index ccf5159dfac..642b8362641 100644 --- a/src/sage/rings/polynomial/hilbert.pyx +++ b/src/sage/rings/polynomial/hilbert.pyx @@ -45,10 +45,12 @@ cdef class Node: cdef fmpz_poly_t LMult cdef fmpz_poly_t RMult cdef fmpz_poly_t LeftFHS + def __cinit__(self): fmpz_poly_init(self.LMult) fmpz_poly_init(self.RMult) fmpz_poly_init(self.LeftFHS) + def __dealloc__(self): fmpz_poly_clear(self.LMult) fmpz_poly_clear(self.RMult) diff --git a/src/sage/rings/polynomial/plural.pyx b/src/sage/rings/polynomial/plural.pyx index ebc17a01e50..248953c89c9 100644 --- a/src/sage/rings/polynomial/plural.pyx +++ b/src/sage/rings/polynomial/plural.pyx @@ -964,10 +964,9 @@ cdef class NCPolynomialRing_plural(Ring): # W = self._list_to_ring(L) # return new_NRing(W, self.base_ring()) - - ### The following methods are handy for implementing Groebner - ### basis algorithms. They do only superficial type/sanity checks - ### and should be called carefully. + # The following methods are handy for implementing Groebner + # basis algorithms. They do only superficial type/sanity checks + # and should be called carefully. def monomial_quotient(self, NCPolynomial_plural f, NCPolynomial_plural g, coeff=False): r""" diff --git a/src/sage/rings/polynomial/polynomial_compiled.pyx b/src/sage/rings/polynomial/polynomial_compiled.pyx index b84275ef82f..f7568893309 100644 --- a/src/sage/rings/polynomial/polynomial_compiled.pyx +++ b/src/sage/rings/polynomial/polynomial_compiled.pyx @@ -392,8 +392,9 @@ cdef class var_pd(generic_pd): self.index = index cdef int eval(var_pd self, object vars, object coeffs) except -2: self.value = vars[self.index] + def __repr__(self): - return "x[%s]"%(self.index) + return "x[%s]" % (self.index) cdef class univar_pd(generic_pd): @@ -402,6 +403,7 @@ cdef class univar_pd(generic_pd): self.label = 1 cdef int eval(univar_pd self, object var, object coeffs) except -2: self.value = var + def __repr__(self): return "x" @@ -411,8 +413,9 @@ cdef class coeff_pd(generic_pd): self.index = index cdef int eval(coeff_pd self, object vars, object coeffs) except -2: self.value = coeffs[self.index] + def __repr__(self): - return "a%s"%(self.index) + return "a%s" % (self.index) cdef void reset(self): pass @@ -439,7 +442,7 @@ cdef class sqr_pd(unary_pd): pd_clean(self.operand) def __repr__(self): - return "(%s)^2"%(self.operand) + return "(%s)^2" % (self.operand) cdef class pow_pd(unary_pd): def __init__(unary_pd self, generic_pd base, object exponent): @@ -452,7 +455,7 @@ cdef class pow_pd(unary_pd): pd_clean(self.operand) def __repr__(self): - return "(%s^%s)"%(self.left, self.exponent) + return "(%s^%s)" % (self.left, self.exponent) @@ -481,8 +484,9 @@ cdef class add_pd(binary_pd): self.value = self.left.value + self.right.value pd_clean(self.left) pd_clean(self.right) + def __repr__(self): - return "(%s+%s)"%(self.left, self.right) + return "(%s+%s)" % (self.left, self.right) cdef class mul_pd(binary_pd): cdef int eval(mul_pd self, object vars, object coeffs) except -2: @@ -491,8 +495,9 @@ cdef class mul_pd(binary_pd): self.value = self.left.value * self.right.value pd_clean(self.left) pd_clean(self.right) + def __repr__(self): - return "(%s*%s)"%(self.left, self.right) + return "(%s*%s)" % (self.left, self.right) cdef class abc_pd(binary_pd): def __init__(abc_pd self, generic_pd left, generic_pd right, int index): @@ -500,7 +505,7 @@ cdef class abc_pd(binary_pd): self.index = index def __repr__(self): - return "(%s*%s+a%s)"%(self.left, self.right, self.index) + return "(%s*%s+a%s)" % (self.left, self.right, self.index) cdef int eval(abc_pd self, object vars, object coeffs) except -2: pd_eval(self.left, vars, coeffs) diff --git a/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx b/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx index 1d539c93f48..41951687939 100644 --- a/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx +++ b/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx @@ -1036,9 +1036,9 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense): count /= factorial(m) return count * factorial(summ) - # Not optimized: # many calls to reduced_norm, reduced_norm_factor, _rdivisor_c, which are slow + def factorizations(self): r""" Return an iterator over all factorizations (as a product diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index dba59ea0a7e..ec4af251254 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -1511,7 +1511,6 @@ cdef class RealDoubleElement(FieldElement): return 1 return -1 - ################### # Rounding etc ################### @@ -1692,7 +1691,6 @@ cdef class RealDoubleElement(FieldElement): from sage.libs.pari.convert_sage_real_double import new_gen_from_real_double_element return new_gen_from_real_double_element(self) - ########################################### # Comparisons: ==, !=, <, <=, >, >= ########################################### @@ -1799,7 +1797,6 @@ cdef class RealDoubleElement(FieldElement): else: return x >= y - ############################ # Special Functions ############################ diff --git a/src/sage/structure/sage_object.pyx b/src/sage/structure/sage_object.pyx index dd98ea5988d..3b84f67e991 100644 --- a/src/sage/structure/sage_object.pyx +++ b/src/sage/structure/sage_object.pyx @@ -528,14 +528,13 @@ cdef class SageObject: """ return type(self) - - ############################################################################# + ########################################################################## # Test framework - ############################################################################# + ########################################################################## def _tester(self, **options): """ - Returns a gadget attached to ``self`` providing testing utilities. + Return a gadget attached to ``self`` providing testing utilities. This is used by :class:`sage.misc.sage_unittest.TestSuite` and the ``_test_*`` methods. diff --git a/src/tox.ini b/src/tox.ini index abb855740ba..8d2ef29439d 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -127,7 +127,7 @@ description = # See https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes deps = pycodestyle commands = pycodestyle --select E111,E21,E222,E227,E25,E271,E303,E306,E401,E502,E701,E702,E703,E71,E72,W291,W293,W391,W605 {posargs:{toxinidir}/sage/} - pycodestyle --select E111,E271,E306,E401,E703,E712,E713,E714,E72,W29,W391,W605, --filename *.pyx {posargs:{toxinidir}/sage/} + pycodestyle --select E111,E271,E301,E306,E401,E703,E712,E713,E714,E72,W29,W391,W605, --filename *.pyx {posargs:{toxinidir}/sage/} [pycodestyle] max-line-length = 160 From acdcbb711d7e78392bd2bdd673b43fe9062a2240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 12 Aug 2023 20:58:07 +0200 Subject: [PATCH 2/2] suggested details --- src/sage/matrix/strassen.pyx | 2 -- src/sage/misc/binary_tree.pyx | 22 ++++++++-------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/sage/matrix/strassen.pyx b/src/sage/matrix/strassen.pyx index 6cb88d596fd..d97d3040c3a 100644 --- a/src/sage/matrix/strassen.pyx +++ b/src/sage/matrix/strassen.pyx @@ -254,13 +254,11 @@ def strassen_echelon(MatrixWindow A, cutoff): INPUT: - - ``A`` - matrix window - ``cutoff`` - size at which algorithm reverts to naive Gaussian elimination and multiplication must be at least 1. - OUTPUT: The list of pivot columns EXAMPLES:: diff --git a/src/sage/misc/binary_tree.pyx b/src/sage/misc/binary_tree.pyx index 214c6721d3d..cc577f4ed6a 100644 --- a/src/sage/misc/binary_tree.pyx +++ b/src/sage/misc/binary_tree.pyx @@ -128,14 +128,14 @@ cdef binary_tree_node *binary_tree_head_excise(binary_tree_node *self): if self.left == NULL: return self.right if right: - #move right branch to left, return left + # move right branch to left, return left cur = self.left while cur.right != NULL: cur = cur.right cur.right = self.right cur = self.left else: - #move left branch to right, return right + # move left branch to right, return right cur = self.right while cur.left != NULL: cur = cur.left @@ -206,15 +206,15 @@ cdef class BinaryTree: ....: return [(k,v) for (k,v) in post.items() if v>10] sage: test() # indirect doctest [] - """ binary_tree_dealloc(self.head) - def insert(BinaryTree self, object key, object value = None): + def insert(BinaryTree self, object key, object value=None): """ Insert a key-value pair into the BinaryTree. Duplicate keys are ignored. + The first parameter, key, should be an int, or coercible (one-to-one) into an int. @@ -298,13 +298,11 @@ cdef class BinaryTree: """ if self.head == NULL: return None - else: - return binary_tree_get(self.head, key) + return binary_tree_get(self.head, key) def contains(BinaryTree self, int key): """ - Return ``True`` if a node with the given key exists - in the tree, and ``False`` otherwise. + Return whether a node with the given key exists in the tree. EXAMPLES:: @@ -318,11 +316,7 @@ cdef class BinaryTree: """ if self.head == NULL: return False - else: - if binary_tree_get(self.head, key) is not None: - return True - else: - return False + return binary_tree_get(self.head, key) is not None def get_max(BinaryTree self): """ @@ -432,7 +426,7 @@ cdef class BinaryTree: def is_empty(BinaryTree self): """ - Return ``True`` if the tree has no nodes. + Return whether the tree has no nodes. EXAMPLES::