Skip to content

Commit

Permalink
Trac #33691: some care for pep8 in pyx in modular
Browse files Browse the repository at this point in the history
found using
{{{
pycodestyle --select
E111,E401,E701,E702,E703,W605,E711,E712,E713,E721,E722 --filename=*.pyx
src/sage/modular/
}}}

URL: https://trac.sagemath.org/33691
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed May 28, 2022
2 parents fbf034f + 2c956e2 commit 8d8c044
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/sage/modular/arithgroup/arithgroup_element.pyx
Expand Up @@ -194,7 +194,7 @@ cdef class ArithmeticSubgroupElement(MultiplicativeGroupElement):
return richcmp(self.__x, right.__x, op)

def __bool__(self):
"""
r"""
Return ``True``, since the ``self`` lives in SL(2,\Z), which does not
contain the zero matrix.
Expand Down
26 changes: 15 additions & 11 deletions src/sage/modular/arithgroup/congroup.pyx
@@ -1,18 +1,18 @@
"""
r"""
Cython helper functions for congruence subgroups
This file contains optimized Cython implementations of a few functions related
to the standard congruence subgroups `\Gamma_0, \Gamma_1, \Gamma_H`. These
functions are for internal use by routines elsewhere in the Sage library.
"""

#*****************************************************************************
# ****************************************************************************
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

from cysignals.memory cimport check_allocarray, sig_free

Expand All @@ -28,7 +28,7 @@ from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense
from sage.modular.modsym.p1list import lift_to_sl2z
from sage.matrix.matrix_space import MatrixSpace
from sage.rings.integer_ring import ZZ
Mat2Z = MatrixSpace(ZZ,2)
Mat2Z = MatrixSpace(ZZ, 2)

cdef Matrix_integer_dense genS, genT, genI
genS = Matrix_integer_dense(Mat2Z, [0,-1, 1, 0], True, True)
Expand Down Expand Up @@ -124,9 +124,11 @@ def degeneracy_coset_representatives_gamma0(int N, int M, int t):
cc = M*random.randrange(-halfmax, halfmax+1)
dd = random.randrange(-halfmax, halfmax+1)
g = arith_int.c_xgcd_int(-cc,dd,&bb,&aa)
if g == 0: continue
if g == 0:
continue
cc = cc / g
if cc % M != 0: continue
if cc % M != 0:
continue
dd = dd / g
# Test if we've found a new coset representative.
is_new = 1
Expand Down Expand Up @@ -212,7 +214,6 @@ def degeneracy_coset_representatives_gamma1(int N, int M, int t):
cdef int d, g, i, j, k, n, aa, bb, cc, dd, Ndivt, halfmax, is_new
cdef int* R


# total number of coset representatives that we'll find
n = Gamma1(N).index() / Gamma1(M).index()
d = arith_int.c_gcd_int(t, N/t)
Expand All @@ -226,11 +227,14 @@ def degeneracy_coset_representatives_gamma1(int N, int M, int t):
cc = M*random.randrange(-halfmax, halfmax+1)
dd = 1 + M*random.randrange(-halfmax, halfmax+1)
g = arith_int.c_xgcd_int(-cc,dd,&bb,&aa)
if g == 0: continue
if g == 0:
continue
cc = cc / g
if cc % M != 0: continue
if cc % M != 0:
continue
dd = dd / g
if M != 1 and dd % M != 1: continue
if M != 1 and dd % M != 1:
continue
# Test if we've found a new coset representative.
is_new = 1
for i from 0 <= i < k:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/modular/arithgroup/farey_symbol.pyx
Expand Up @@ -610,7 +610,7 @@ cdef class Farey:
if forced_format == 'plain':
# output not using xymatrix
s = r'\left( -\infty'
a = [x._latex_() for x in self.fractions()] + ['\infty']
a = [x._latex_() for x in self.fractions()] + [r'\infty']
b = self.pairings()
for i in xrange(len(a)):
u = b[i]
Expand All @@ -623,7 +623,7 @@ cdef class Farey:
else:
# output using xymatrix
s = r'\begin{xy}\xymatrix{& -\infty '
f = [x._latex_() for x in self.fractions()]+[r'\infty']
f = [x._latex_() for x in self.fractions()] + [r'\infty']
f.reverse()
for p in self.pairings():
if p >= 0:
Expand Down
35 changes: 24 additions & 11 deletions src/sage/modular/modsym/heilbronn.pyx
Expand Up @@ -211,7 +211,7 @@ cdef class Heilbronn:
sig_off()

cdef apply_to_polypart(self, fmpz_poly_t* ans, int i, int k):
"""
r"""
INPUT:
- ``ans`` - fmpz_poly_t\*; pre-allocated an
Expand Down Expand Up @@ -402,7 +402,11 @@ cdef class HeilbronnCremona(Heilbronn):
a = -b
b = c
x3 = q*x2 - x1
x1 = x2; x2 = x3; y3 = q*y2 - y1; y1 = y2; y2 = y3
x1 = x2
x2 = x3
y3 = q*y2 - y1
y1 = y2
y2 = y3
list_append4(L, x1,x2, y1,y2)
self.length = L.i/4
sig_off()
Expand Down Expand Up @@ -573,9 +577,11 @@ def hecke_images_gamma0_weight2(int u, int v, int N, indices, R):

# Allocate memory to hold images of (u,v) under all Heilbronn matrices
a = <int*> sig_malloc(sizeof(int)*H.length)
if not a: raise MemoryError
if not a:
raise MemoryError
b = <int*> sig_malloc(sizeof(int)*H.length)
if not b: raise MemoryError
if not b:
raise MemoryError

# Compute images of (u,v) under all Heilbronn matrices
H.apply_only(u, v, N, a, b)
Expand Down Expand Up @@ -708,9 +714,11 @@ def hecke_images_nonquad_character_weight2(int u, int v, int N, indices, chi, R)

# Allocate memory to hold images of (u,v) under all Heilbronn matrices
a = <int*> sig_malloc(sizeof(int)*H.length)
if not a: raise MemoryError
if not a:
raise MemoryError
b = <int*> sig_malloc(sizeof(int)*H.length)
if not b: raise MemoryError
if not b:
raise MemoryError

# Compute images of (u,v) under all Heilbronn matrices
H.apply_only(u, v, N, a, b)
Expand Down Expand Up @@ -798,16 +806,19 @@ def hecke_images_quad_character_weight2(int u, int v, int N, indices, chi, R):
# are the values of the character chi.
_chivals = chi.values()
cdef int *chi_vals = <int*>sig_malloc(sizeof(int)*len(_chivals))
if not chi_vals: raise MemoryError
if not chi_vals:
raise MemoryError
for i in range(len(_chivals)):
chi_vals[i] = _chivals[i]

for i, n in enumerate(indices):
H = HeilbronnCremona(n) if is_prime(n) else HeilbronnMerel(n)
a = <int*> sig_malloc(sizeof(int)*H.length)
if not a: raise MemoryError
if not a:
raise MemoryError
b = <int*> sig_malloc(sizeof(int)*H.length)
if not b: raise MemoryError
if not b:
raise MemoryError

H.apply_only(u, v, N, a, b)
for j in range(H.length):
Expand Down Expand Up @@ -893,9 +904,11 @@ def hecke_images_gamma0_weight_k(int u, int v, int i, int N, int k, indices, R):

# Allocate memory to hold images of (u,v) under all Heilbronn matrices
a = <int*> sig_malloc(sizeof(int)*H.length)
if not a: raise MemoryError
if not a:
raise MemoryError
b = <int*> sig_malloc(sizeof(int)*H.length)
if not b: raise MemoryError
if not b:
raise MemoryError

# Compute images of (u,v) under all Heilbronn matrices
H.apply_only(u, v, N, a, b)
Expand Down
4 changes: 1 addition & 3 deletions src/sage/modular/modsym/manin_symbol.pyx
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""
r"""
Manin symbols
This module defines the class ManinSymbol. A Manin symbol of
Expand All @@ -19,9 +19,7 @@ monomial Manin symbols to monomial Manin symbols, up to a scalar
factor. For general matrices (such as `T=[0,1,-1,-1]` and
`T^2=[-1,-1;0,1]`) the image of a monomial Manin symbol is expressed
as a formal sum of monomial Manin symbols, with integer coefficients.
"""

from sage.modular.cusps import Cusp
from sage.rings.all import Infinity, ZZ
from sage.rings.integer cimport Integer
Expand Down

0 comments on commit 8d8c044

Please sign in to comment.