Skip to content

Commit

Permalink
Trac #30542: various flake8 fixes
Browse files Browse the repository at this point in the history
about E7 warnings (one command per line, etc)

in arith, calculus, homology, matroids, parallel

URL: https://trac.sagemath.org/30542
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Nov 7, 2020
2 parents c71679a + 48931bd commit 38bab5a
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 69 deletions.
14 changes: 8 additions & 6 deletions src/sage/arith/misc.py
Expand Up @@ -4546,7 +4546,7 @@ def hilbert_symbol(a, b, p, algorithm="pari"):
if algorithm == "pari":
if p == -1:
p = 0
return ZZ(pari(a).hilbert(b,p))
return ZZ(pari(a).hilbert(b, p))

elif algorithm == 'direct':
if a == 0 or b == 0:
Expand All @@ -4557,13 +4557,15 @@ def hilbert_symbol(a, b, p, algorithm="pari"):

if p != -1:
p_sqr = p**2
while a%p_sqr == 0: a //= p_sqr
while b%p_sqr == 0: b //= p_sqr
while a % p_sqr == 0:
a //= p_sqr
while b % p_sqr == 0:
b //= p_sqr

if p != 2 and True in ( kronecker(x,p) == 1 for x in (a,b,a+b) ):
if p != 2 and True in (kronecker(x, p) == 1 for x in (a, b, a + b)):
return one
if a%p == 0:
if b%p == 0:
if a % p == 0:
if b % p == 0:
return hilbert_symbol(p,-(b//p),p)*hilbert_symbol(a//p,b,p)
elif p == 2 and (b%4) == 3:
if kronecker(a+b,p) == -1:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/calculus/calculus.py
Expand Up @@ -2210,7 +2210,7 @@ def symbolic_expression_from_maxima_string(x, equals_sub=False, maxima=maxima):
#replace all instances of Maxima's scientific notation
#with regular notation
search = sci_not.search(s)
while not search is None:
while search is not None:
(start, end) = search.span()
r = create_RealNumber(s[start:end]).str(no_sci=2, truncate=True)
s = s.replace(s[start:end], r)
Expand Down
56 changes: 33 additions & 23 deletions src/sage/calculus/desolvers.py
Expand Up @@ -1054,7 +1054,8 @@ def eulers_method(f,x0,y0,h,x1,algorithm="table"):
if algorithm=="table":
print("%10s %20s %25s"%("x","y","h*f(x,y)"))
n=int((1.0)*(x1-x0)/h)
x00=x0; y00=y0
x00 = x0
y00 = y0
soln = [[x00,y00]]
for i in range(n+1):
if algorithm=="table":
Expand Down Expand Up @@ -1152,9 +1153,11 @@ def eulers_method_2x2(f,g, t0, x0, y0, h, t1,algorithm="table"):
"""
if algorithm=="table":
print("%10s %20s %25s %20s %20s"%("t", "x","h*f(t,x,y)","y", "h*g(t,x,y)"))
n=int((1.0)*(t1-t0)/h)
t00 = t0; x00 = x0; y00 = y0
soln = [[t00,x00,y00]]
n = int((1.0)*(t1-t0)/h)
t00 = t0
x00 = x0
y00 = y0
soln = [[t00, x00, y00]]
for i in range(n+1):
if algorithm=="table":
print("%10r %20r %25r %20r %20r"%(t00,x00,h*f(t00,x00,y00),y00,h*g(t00,x00,y00)))
Expand Down Expand Up @@ -1381,27 +1384,32 @@ def desolve_rk4(de, dvar, ics=None, ivar=None, end_points=None, step=0.1, output
sol.extend([[ics[0],ics[1]]])
sol.extend(sol_2)

if output=='list':
if output == 'list':
return sol
from sage.plot.plot import list_plot
from sage.plot.plot_field import plot_slope_field
R = list_plot(sol,plotjoined=True,**kwds)
if output=='plot':
R = list_plot(sol, plotjoined=True, **kwds)
if output == 'plot':
return R
if output=='slope_field':
XMIN=sol[0][0]
YMIN=sol[0][1]
XMAX=XMIN
YMAX=YMIN
for s,t in sol:
if s>XMAX:XMAX=s
if s<XMIN:XMIN=s
if t>YMAX:YMAX=t
if t<YMIN:YMIN=t
return plot_slope_field(de,(ivar,XMIN,XMAX),(dummy_dvar,YMIN,YMAX))+R
if output == 'slope_field':
XMIN = sol[0][0]
YMIN = sol[0][1]
XMAX = XMIN
YMAX = YMIN
for s, t in sol:
if s > XMAX:
XMAX = s
if s < XMIN:
XMIN = s
if t > YMAX:
YMAX = t
if t < YMIN:
YMIN = t
return plot_slope_field(de, (ivar,XMIN,XMAX), (dummy_dvar,YMIN,YMAX))+R

raise ValueError("Option output should be 'list', 'plot' or 'slope_field'.")


def desolve_system_rk4(des, vars, ics=None, ivar=None, end_points=None, step=0.1):
r"""
Solve numerically a system of first-order ordinary differential
Expand Down Expand Up @@ -1667,13 +1675,15 @@ def desolve_odeint(des, ics, times, dvars, ivar=None, compute_jac=False, args=()

# one-dimensional systems:
if is_SymbolicVariable(dvars):
func = fast_float(des,dvars,ivar)
func = fast_float(des, dvars, ivar)
if not compute_jac:
Dfun=None
Dfun = None
else:
J = diff(des,dvars)
J = fast_float(J,dvars,ivar)
Dfun = lambda y,t: [J(y,t)]
J = diff(des, dvars)
J = fast_float(J, dvars, ivar)

def Dfun(y, t):
return [J(y, t)]

# n-dimensional systems:
else:
Expand Down
16 changes: 9 additions & 7 deletions src/sage/calculus/functions.py
Expand Up @@ -77,7 +77,7 @@ def wronskian(*args):
- Dan Drake (2008-03-12)
"""
if len(args) == 0:
if not args:
raise TypeError('wronskian() takes at least one argument (0 given)')
elif len(args) == 1:
# a 1x1 Wronskian is just its argument
Expand All @@ -88,19 +88,21 @@ def wronskian(*args):
# differentiate the other args
v = args[-1]
fs = args[0:-1]
row = lambda n: [diff(f, v, n) for f in fs]

def row(n):
return [diff(f, v, n) for f in fs]
else:
# if the last argument isn't a variable, just run
# if the last argument is not a variable, just run
# .derivative on everything
fs = args
row = lambda n: [diff(f, n) for f in fs]

def row(n):
return [diff(f, n) for f in fs]
# NOTE: I rewrote the below as two lines to avoid a possible subtle
# memory management problem on some platforms (only VMware as far
# as we know?). See trac #2990.
# There may still be a real problem that this is just hiding for now.
A = matrix([row(_) for _ in range(len(fs))])
return A.determinant()
#return matrix(map(row, range(len(fs)))).determinant()
return matrix([row(r) for r in range(len(fs))]).determinant()


def jacobian(functions, variables):
Expand Down
8 changes: 5 additions & 3 deletions src/sage/homology/chain_complex.py
Expand Up @@ -263,7 +263,7 @@ def ChainComplex(data=None, base_ring=None, grading_group=None,

# make sure values in data_dict are appropriate matrices
for n in list(data_dict):
if not n in grading_group:
if n not in grading_group:
raise ValueError('one of the dictionary keys is not an element of the grading group')
mat = data_dict[n]
if not isinstance(mat, Matrix):
Expand Down Expand Up @@ -2156,9 +2156,11 @@ def tensor(self, *factors, **kwds):
ret = self

if self._grading_group is ZZ:
scalar = lambda a: (-1)**(a * deg_diff)
def scalar(a):
return (-1)**(a * deg_diff)
else:
scalar = lambda a: (-1)**(sum(a) * sum(deg_diff))
def scalar(a):
return (-1)**(sum(a) * sum(deg_diff))

for D in factors:
# Setup
Expand Down
8 changes: 4 additions & 4 deletions src/sage/homology/simplicial_complex_morphism.py
Expand Up @@ -173,7 +173,7 @@ def __init__(self,f,X,Y):
for j in tup:
fi.append(f[j])
v = Simplex(set(fi))
if not v in Y_faces[v.dimension()]:
if v not in Y_faces[v.dimension()]:
raise ValueError("f must be a dictionary from the vertices of X to the vertices of Y")
self._vertex_dictionary = f
Morphism.__init__(self, Hom(X,Y,SimplicialComplexes()))
Expand Down Expand Up @@ -247,10 +247,10 @@ def __call__(self,x,orientation=False):
((0, 1), -1)
"""
dim = self.domain().dimension()
if not isinstance(x,Simplex) or x.dimension() > dim or not x in self.domain().faces()[x.dimension()]:
if not isinstance(x, Simplex) or x.dimension() > dim or x not in self.domain().faces()[x.dimension()]:
raise ValueError("x must be a simplex of the source of f")
tup=x.tuple()
fx=[]
tup = x.tuple()
fx = []
for j in tup:
fx.append(self._vertex_dictionary[j])
if orientation:
Expand Down
6 changes: 3 additions & 3 deletions src/sage/homology/simplicial_set_morphism.py
Expand Up @@ -453,7 +453,7 @@ def __init__(self, data=None, domain=None, codomain=None,
if identity:
if codomain is None:
codomain = domain
elif not domain is codomain:
elif domain is not codomain:
raise TypeError("identity map is only defined for endomorphism sets")
self._is_identity = True
Morphism.__init__(self, Hom(domain, codomain, SimplicialSets()))
Expand All @@ -470,10 +470,10 @@ def __init__(self, data=None, domain=None, codomain=None,
if identity:
self._is_identity = True
check = False
if not domain is codomain:
if domain is not codomain:
raise TypeError("identity map is only defined for endomorphism sets")
data = {}
for i in range(domain.dimension()+1):
for i in range(domain.dimension() + 1):
for s in domain.n_cells(i):
data[s] = s
if constant is not None:
Expand Down

0 comments on commit 38bab5a

Please sign in to comment.