Skip to content

Commit

Permalink
linting : some fixes for pyx files in modular
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Dec 6, 2024
1 parent 8a972c4 commit 5875eaf
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 95 deletions.
16 changes: 9 additions & 7 deletions src/sage/modular/arithgroup/congroup.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from sage.rings.integer_ring import ZZ
Mat2Z = MatrixSpace(ZZ, 2)

cdef Matrix_integer_dense genS, genT, genI
genS = Matrix_integer_dense(Mat2Z, [0,-1, 1, 0], True, True)
genS = Matrix_integer_dense(Mat2Z, [0, -1, 1, 0], True, True)
genT = Matrix_integer_dense(Mat2Z, [1, 1, 0, 1], True, True)
genI = Matrix_integer_dense(Mat2Z, [1, 0, 0, 1], True, True)

Expand Down Expand Up @@ -123,7 +123,7 @@ def degeneracy_coset_representatives_gamma0(int N, int M, int t):
# try to find another coset representative.
cc = M*random.randrange(-halfmax, halfmax+1)
dd = random.randrange(-halfmax, halfmax+1)
g = arith_int.c_xgcd_int(-cc,dd,&bb,&aa)
g = arith_int.c_xgcd_int(-cc, dd, &bb, &aa)
if g == 0:
continue
cc = cc // g
Expand Down Expand Up @@ -297,22 +297,24 @@ def generators_helper(coset_reps, level):
[21 5], [ 7 -1], [-7 1]
]
"""
cdef Matrix_integer_dense x,y,z,v,vSmod,vTmod
cdef Matrix_integer_dense x, y, z, v, vSmod, vTmod

crs = coset_reps.list()
try:
reps = [Matrix_integer_dense(Mat2Z,lift_to_sl2z(c, d, level),False,True) for c,d in crs]
reps = [Matrix_integer_dense(Mat2Z, lift_to_sl2z(c, d, level),
False, True) for c, d in crs]
except Exception:
raise ArithmeticError("Error lifting to SL2Z: level=%s crs=%s" % (level, crs))
ans = []
cdef Py_ssize_t i
for i in range(len(crs)):
x = reps[i]
v = Matrix_integer_dense(Mat2Z,[crs[i][0],crs[i][1],0,0],False,True)
v = Matrix_integer_dense(Mat2Z, [crs[i][0], crs[i][1], 0, 0],
False, True)
vSmod = (v*genS)
vTmod = (v*genT)
y_index = coset_reps.normalize(vSmod[0,0],vSmod[0,1])
z_index = coset_reps.normalize(vTmod[0,0],vTmod[0,1])
y_index = coset_reps.normalize(vSmod[0, 0], vSmod[0, 1])
z_index = coset_reps.normalize(vTmod[0, 0], vTmod[0, 1])
y_index = crs.index(y_index)
z_index = crs.index(z_index)
y = reps[y_index]
Expand Down
32 changes: 16 additions & 16 deletions src/sage/modular/arithgroup/farey_symbol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ based on the *KFarey* package by Chris Kurth. Implemented as C++ module
for speed.
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2011 Hartmut Monien <monien@th.physik.uni-bonn.de>
#
# 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 cpython.object cimport PyObject_RichCompare
from itertools import groupby
Expand Down Expand Up @@ -206,11 +206,11 @@ cdef class Farey:
self.this_ptr = new cpp_farey(data)
sig_off()
return
## to accelerate the calculation of the FareySymbol
## we implement the tests for the standard congruence groups
## in the c++ module. For a general group the test if an element
## of SL2Z is in the group the python __contains__ attribute
## of the group is called
# to accelerate the calculation of the FareySymbol
# we implement the tests for the standard congruence groups
# in the c++ module. For a general group the test if an element
# of SL2Z is in the group the python __contains__ attribute
# of the group is called
cdef int p
if hasattr(group, "level"):
p = group.level()
Expand Down Expand Up @@ -285,19 +285,19 @@ cdef class Farey:
a, b, c, d = pm.matrix().list()
newval = gens_dict.get(SL2Z([a, b, c, d]))
if newval is not None:
ans.append((newval,1))
ans.append((newval, 1))
continue
newval = gens_dict.get(SL2Z([-a, -b, -c, -d]))
if newval is not None:
ans.append((newval,-1))
ans.append((newval, -1))
continue
newval = gens_dict.get(SL2Z([d, -b, -c, a]))
if newval is not None:
ans.append((-newval,1))
ans.append((-newval, 1))
continue
newval = gens_dict.get(SL2Z([-d, b, c, -a]))
if newval is not None:
ans.append((-newval,-1))
ans.append((-newval, -1))
continue
raise RuntimeError("This should have not happened")
return ans
Expand Down Expand Up @@ -453,7 +453,7 @@ cdef class Farey:
result = self.this_ptr.word_problem(a.value, b.value, c.value, d.value, cpp_beta)
sig_off()
beta = convert_to_SL2Z(cpp_beta[0])**-1
mbeta = SL2Z([-beta.a(),-beta.b(),-beta.c(),-beta.d()])
mbeta = SL2Z([-beta.a(), -beta.b(), -beta.c(), -beta.d()])
V = self.pairing_matrices_to_tietze_index()
sgn = 1
tietze = []
Expand Down Expand Up @@ -500,7 +500,7 @@ cdef class Farey:
tietze.reverse()
gens = self.generators()
if check:
tmp = SL2Z([1,0,0,1])
tmp = SL2Z([1, 0, 0, 1])
for i in range(len(tietze)):
t = tietze[i]
tmp = tmp * gens[t-1] if t > 0 else tmp * gens[-t-1]**-1
Expand Down Expand Up @@ -1009,7 +1009,7 @@ cdef class Farey:
fill=options['fill'],
linestyle=options['linestyle'],
thickness=options['thickness'])
## show pairings
# show pairings
p = self.pairings()
x = self.fractions()
if options['show_pairing']:
Expand All @@ -1033,7 +1033,7 @@ cdef class Farey:
return g


#--- conversions ------------------------------------------------------------
# ----- conversions ---------------------------------

cdef public long convert_to_long(n) noexcept:
cdef long m = n
Expand Down
44 changes: 22 additions & 22 deletions src/sage/modular/modsym/heilbronn.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ cdef class Heilbronn:
b[i] = (u * self.list.v[4*i+1]) % N + (v * self.list.v[4*i+3]) % N
else:
for i in range(self.length):
a[i] = llong_prod_mod(u,self.list.v[4*i],N) + llong_prod_mod(v,self.list.v[4*i+2], N)
b[i] = llong_prod_mod(u,self.list.v[4*i+1],N) + llong_prod_mod(v,self.list.v[4*i+3], N)
a[i] = llong_prod_mod(u, self.list.v[4*i], N) + llong_prod_mod(v, self.list.v[4*i+2], N)
b[i] = llong_prod_mod(u, self.list.v[4*i+1], N) + llong_prod_mod(v, self.list.v[4*i+3], N)
sig_off()

cdef apply_to_polypart(self, fmpz_poly_t* ans, int i, int k):
Expand Down Expand Up @@ -283,8 +283,8 @@ cdef class Heilbronn:
else:
for i in range(self.length):
sig_check()
a = llong_prod_mod(u,self.list.v[4*i],N) + llong_prod_mod(v,self.list.v[4*i+2], N)
b = llong_prod_mod(u,self.list.v[4*i+1],N) + llong_prod_mod(v,self.list.v[4*i+3], N)
a = llong_prod_mod(u, self.list.v[4*i], N) + llong_prod_mod(v, self.list.v[4*i+2], N)
b = llong_prod_mod(u, self.list.v[4*i+1], N) + llong_prod_mod(v, self.list.v[4*i+3], N)
export.c_p1_normalize_llong(N, a, b, &c, &d, &s, 0)
X = (c, d)
if X in M:
Expand Down Expand Up @@ -368,15 +368,15 @@ cdef class HeilbronnCremona(Heilbronn):
L = &self.list
p = self.p

list_append4(L, 1,0,0,p)
list_append4(L, 1, 0, 0, p)

# When p==2, then Heilbronn matrices are
# [[1,0,0,2], [2,0,0,1], [2,1,0,1], [1,0,1,2]]
# which are not given by the algorithm below.
if p == 2:
list_append4(L, 2,0,0,1)
list_append4(L, 2,1,0,1)
list_append4(L, 1,0,1,2)
list_append4(L, 2, 0, 0, 1)
list_append4(L, 2, 1, 0, 1)
list_append4(L, 1, 0, 1, 2)
self.length = 4
return

Expand Down Expand Up @@ -489,20 +489,20 @@ cdef class HeilbronnMerel(Heilbronn):

sig_on()
for a in range(1, n+1):
## We have ad-bc=n so c=0 and ad=n, or b=(ad-n)/c
## Must have ad - n >= 0, so d must be >= Ceiling(n/a).
# We have ad-bc=n so c=0 and ad=n, or b=(ad-n)/c
# Must have ad - n >= 0, so d must be >= Ceiling(n/a).
q = n // a
if q*a == n:
d = q
for b in range(a):
list_append4(L, a,b,0,d)
list_append4(L, a, b, 0, d)
for c in range(1, d):
list_append4(L, a,0,c,d)
list_append4(L, a, 0, c, d)
for d in range(q+1, n+1):
bc = (<llong>a) * (<llong>d) - (<llong>n)
## Divisor c of bc must satisfy Floor(bc/c) lt a and c lt d.
## c ge (bc div a + 1) <=> Floor(bc/c) lt a (for integers)
## c le d - 1 <=> c lt d
# Divisor c of bc must satisfy Floor(bc/c) lt a and c lt d.
# c ge (bc div a + 1) <=> Floor(bc/c) lt a (for integers)
# c le d - 1 <=> c lt d
for c in range(bc // a + 1, d):
if bc % c == 0:
list_append4(L, a, bc // c, c, d)
Expand Down Expand Up @@ -569,7 +569,7 @@ def hecke_images_gamma0_weight2(int u, int v, int N, indices, R):
cdef Heilbronn H

t = verbose("computing non-reduced images of symbol under Hecke operators",
level=1, caller_name='hecke_images_gamma0_weight2')
level=1, caller_name='hecke_images_gamma0_weight2')
for i, n in enumerate(indices):
# List the Heilbronn matrices of determinant n defined by Cremona or Merel
H = HeilbronnCremona(n) if is_prime(n) else HeilbronnMerel(n)
Expand Down Expand Up @@ -601,25 +601,25 @@ def hecke_images_gamma0_weight2(int u, int v, int N, indices, R):
sig_free(b)

t = verbose("finished computing non-reduced images",
t, level=1, caller_name='hecke_images_gamma0_weight2')
t, level=1, caller_name='hecke_images_gamma0_weight2')

t = verbose("Now reducing images of symbol",
level=1, caller_name='hecke_images_gamma0_weight2')
level=1, caller_name='hecke_images_gamma0_weight2')

# Return the product T * R, whose rows are the image of (u,v) under
# the Hecke operators T_n for n in indices.
if max(indices) <= 30: # In this case T tends to be very sparse
ans = T.sparse_matrix()._matrix_times_matrix_dense(R)
verbose("did reduction using sparse multiplication",
t, level=1, caller_name='hecke_images_gamma0_weight2')
t, level=1, caller_name='hecke_images_gamma0_weight2')
elif R.is_sparse():
ans = T * R.dense_matrix()
verbose("did reduction using dense multiplication",
t, level=1, caller_name='hecke_images_gamma0_weight2')
t, level=1, caller_name='hecke_images_gamma0_weight2')
else:
ans = T * R
verbose("did reduction using dense multiplication",
t, level=1, caller_name='hecke_images_gamma0_weight2')
t, level=1, caller_name='hecke_images_gamma0_weight2')

if original_base_ring != QQ:
ans = ans.change_ring(original_base_ring)
Expand Down Expand Up @@ -700,7 +700,7 @@ def hecke_images_nonquad_character_weight2(int u, int v, int N, indices, chi, R)
cdef Heilbronn H

t = verbose("computing non-reduced images of symbol under Hecke operators",
level=1, caller_name='hecke_images_character_weight2')
level=1, caller_name='hecke_images_character_weight2')

# Make a matrix over the rational numbers each of whose columns
# are the values of the character chi.
Expand Down
5 changes: 2 additions & 3 deletions src/sage/modular/modsym/manin_symbol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ cdef class ManinSymbol(Element):
N=int(N)
if N < 1:
raise ArithmeticError("N must be positive")
a,b,c,d = self.lift_to_sl2z()
a, b, c, d = self.lift_to_sl2z()
return Cusp(b, d), Cusp(a, c)

def weight(self):
Expand Down Expand Up @@ -453,8 +453,7 @@ cdef class ManinSymbol(Element):
# TODO: It would likely be much better to do this slightly more directly
from sage.modular.modsym.modular_symbols import ModularSymbol
x = ModularSymbol(self.parent(), self.i, 0, Infinity)
a,b,c,d = self.lift_to_sl2z()
return x.apply([a,b,c,d])
return x.apply(self.lift_to_sl2z())


def _print_polypart(i, j):
Expand Down
8 changes: 4 additions & 4 deletions src/sage/modular/modsym/p1list.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ cdef class export:
int compute_s) except -1

cdef int c_p1_normalize_llong(self, int N, int u, int v,
int* uu, int* vv, int* ss,
int compute_s) except -1
int* uu, int* vv, int* ss,
int compute_s) except -1


cdef class P1List:
Expand All @@ -22,7 +22,7 @@ cdef class P1List:
# for normalizing an element does not need to be used
# every time the user calls the normalize function.
cdef int (*_normalize)(int N, int u, int v,
int* uu, int* vv, int* ss,
int compute_s) except -1
int* uu, int* vv, int* ss,
int compute_s) except -1
cpdef index(self, int u, int v)
cdef index_and_scalar(self, int u, int v, int* i, int* s)
Loading

0 comments on commit 5875eaf

Please sign in to comment.