Skip to content

Commit 0cadf89

Browse files
committed
many fixes (python3, ruff, pycodestyle, rst, imports, etc)
1 parent 7592347 commit 0cadf89

12 files changed

Lines changed: 153 additions & 190 deletions

File tree

drg/array3d.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __repr__(self):
7878
String representation of the array.
7979
"""
8080
l = len(repr(self.n - 1))
81-
fmt = '%{}d: '.format(l)
81+
fmt = f'%{l}d: '
8282
return '\n\n'.join((fmt % i) + repr(M).replace('\n',
8383
'\n' + (' ' * (l+2)))
8484
for i, M in enumerate(self.A))
@@ -96,7 +96,7 @@ def _ascii_art_(self):
9696
ASCII art representation of the array.
9797
"""
9898
l = len(repr(self.n - 1))
99-
fmt = '%{}d: '.format(l)
99+
fmt = f'%{l}d: '
100100
art = [ascii_art(M) for M in self.A]
101101
return ascii_art("\n".join((fmt % i) + "\n"*a.height()
102102
for i, a in enumerate(art))) + \
@@ -115,7 +115,7 @@ def _unicode_art_(self):
115115
Unicode art representation of the array.
116116
"""
117117
l = len(repr(self.n - 1))
118-
fmt = '%{}d: '.format(l)
118+
fmt = f'%{l}d: '
119119
art = [unicode_art(M) for M in self.A]
120120
return unicode_art("\n".join((fmt % i) + "\n"*a.height()
121121
for i, a in enumerate(art))) + \
@@ -179,7 +179,7 @@ def subs(self, *exp):
179179

180180
def variables(self):
181181
"""
182-
Return the variables occuring in the array.
182+
Return the variables occurring in the array.
183183
"""
184184
return tuple(set(sum((variables(x)
185185
for M in self for r in M for x in r), ())))
@@ -255,8 +255,8 @@ def __repr__(self):
255255
String representation of the array.
256256
"""
257257
l = len(repr(self.n - 1))
258-
fmt = '%{}d'.format(l)
259-
return '\n\n'.join(('(%s, %s): ' % (fmt % i, fmt % j)) +
258+
fmt = f'%{l}d'
259+
return '\n\n'.join((f'({fmt % i}, {fmt % j}): ') +
260260
repr(M).replace('\n', '\n' + (' ' * (2*l+6)))
261261
for i, A in enumerate(self.A)
262262
for j, M in enumerate(A))
@@ -274,8 +274,8 @@ def _ascii_art_(self):
274274
ASCII art representation of the array.
275275
"""
276276
l = len(repr(self.n - 1))
277-
fmt = '%{}d'.format(l)
278-
art = [("(%s, %s): " % (fmt % i, fmt % j), ascii_art(M))
277+
fmt = f'%{l}d'
278+
art = [(f"({fmt % i}, {fmt % j}): ", ascii_art(M))
279279
for i, A in enumerate(self.A) for j, M in enumerate(A)]
280280
return ascii_art("\n".join(i + "\n"*a.height() for i, a in art)) + \
281281
ascii_art("\n".join(sum([a._matrix + [""] for i, a in art], [])))
@@ -294,8 +294,8 @@ def _unicode_art_(self):
294294
Unicode art representation of the array.
295295
"""
296296
l = len(repr(self.n - 1))
297-
fmt = '%{}d'.format(l)
298-
art = [("(%s, %s): " % (fmt % i, fmt % j), unicode_art(M))
297+
fmt = f'%{l}d'
298+
art = [(f"({fmt % i}, {fmt % j}): ", unicode_art(M))
299299
for i, A in enumerate(self.A) for j, M in enumerate(A)]
300300
return unicode_art("\n".join(i + "\n"*a.height() for i, a in art)) + \
301301
unicode_art("\n".join(sum([a._matrix + [""] for i, a in art],
@@ -363,7 +363,7 @@ def subs(self, *exp):
363363

364364
def variables(self):
365365
"""
366-
Return the variables occuring in the array.
366+
Return the variables occurring in the array.
367367
"""
368368
return tuple(set(sum((variables(x)
369369
for A in self for M in A for r in M for x in r),

drg/assoc_scheme.py

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# -*- coding: utf-8 -*-
2-
import six
31
from copy import copy
42
from warnings import warn
5-
from sage.all import pi
3+
4+
from sage.symbolic.constants import pi
65
from sage.calculus.functional import expand as _expand
76
from sage.calculus.functional import simplify as _simplify
87
from sage.combinat.set_partition import SetPartitions
@@ -14,7 +13,7 @@
1413
from sage.matrix.constructor import identity_matrix
1514
from sage.misc.latex import latex
1615
from sage.misc.latex import LatexExpr
17-
from sage.misc.misc import subsets
16+
from sage.combinat.subset import subsets
1817
from sage.rings.integer import Integer
1918
from sage.structure.sage_object import SageObject
2019
from sage.symbolic.relation import solve as _solve
@@ -397,9 +396,9 @@ def _compute_parameters(self, p, P, m, integral=False, name=None,
397396
for i in range(self._.d + 1):
398397
for j in range(self._.d + 1):
399398
p[h, i, j] = full_simplify(
400-
sum(m[t] * P[t, h] * P[t, i] * P[t, j]
401-
for t in range(self._.d + 1))
402-
/ (self._.n * P[0, h]))
399+
sum(m[t] * P[t, h] * P[t, i] * P[t, j]
400+
for t in range(self._.d + 1))
401+
/ (self._.n * P[0, h]))
403402
self._check_parameter(h, i, j, p[h, i, j],
404403
integral=integral,
405404
name=name, sym=sym)
@@ -443,7 +442,7 @@ def _compute_pTable(self, expand=False, factor=False,
443442

444443
def _copy(self, p):
445444
"""
446-
Copy fields to the given obejct.
445+
Copy fields to the given object.
447446
"""
448447
p._.d = self._.d
449448
p._.n = self._.n
@@ -486,6 +485,7 @@ def _derived(self, derived=True):
486485
subcs = set()
487486
pars = self._get_parameters()
488487
c = self.classes()
488+
489489
def derived():
490490
for pa, part in self._.fusion_schemes.items():
491491
yield (pa, part, [], True)
@@ -563,7 +563,7 @@ def _init_prefix(self):
563563
self._.prefix = "v%x" % (hash(self) % Integer(2)**32)
564564

565565
def _init_schoenberg(self):
566-
u"""
566+
"""
567567
Initialize parameters for the computation of the limit
568568
up to which Schönberg's theorem is tested.
569569
"""
@@ -674,7 +674,7 @@ def _subconstituent_name(h):
674674

675675
def _subs(self, exp, p, seen):
676676
"""
677-
Substitute the given subexpressions in the paramaters.
677+
Substitute the given subexpressions in the parameters.
678678
"""
679679
if id(self) in seen:
680680
return (seen[id(self)], False)
@@ -793,7 +793,7 @@ def check_feasible(self, checked=None, skip=None, derived=None, levels=3,
793793
return
794794
if skip is None:
795795
skip = set()
796-
elif isinstance(skip, six.string_types):
796+
elif isinstance(skip, str):
797797
skip = {skip}
798798
else:
799799
skip = set(skip)
@@ -997,12 +997,12 @@ def polynomialOrders(self):
997997
if self.is_pPolynomial():
998998
for order in self._.pPolynomial_ordering:
999999
pa = self.add_subscheme(DRGParameters(self, order=order),
1000-
"P-polynomial ordering %s" % (order, ))
1000+
f"P-polynomial ordering {order}")
10011001
out["P", order] = pa
10021002
if self.is_qPolynomial():
10031003
for order in self._.qPolynomial_ordering:
10041004
pa = self.add_subscheme(QPolyParameters(self, order=order),
1005-
"Q-polynomial ordering %s" % (order, ))
1005+
f"Q-polynomial ordering {order}")
10061006
out["Q", order] = pa
10071007
return out
10081008

@@ -1583,12 +1583,12 @@ def tripleSolution_generator(self, u, v, w, S=None, solver=None):
15831583
if S is None:
15841584
S = self.tripleEquations(u, v, w)
15851585
return find(make_expressions((S[h, i, j], 0,
1586-
min(self._.p[u, h, i],
1587-
self._.p[v, h, j],
1588-
self._.p[w, i, j]))
1589-
for h in range(self._.d + 1)
1590-
for i in range(self._.d + 1)
1591-
for j in range(self._.d + 1)),
1586+
min(self._.p[u, h, i],
1587+
self._.p[v, h, j],
1588+
self._.p[w, i, j]))
1589+
for h in range(self._.d + 1)
1590+
for i in range(self._.d + 1)
1591+
for j in range(self._.d + 1)),
15921592
S.variables(), solver=solver)
15931593

15941594
def variables(self):
@@ -1711,7 +1711,7 @@ def check_absoluteBound(self, expand=False, factor=False,
17111711

17121712
@check(2)
17131713
def check_schoenberg(self, expand=False, factor=False, simplify=False):
1714-
u"""
1714+
"""
17151715
Check whether Schönberg's theorem holds.
17161716
"""
17171717
if len(self._.vars) > 0:
@@ -1730,8 +1730,7 @@ def check_schoenberg(self, expand=False, factor=False, simplify=False):
17301730
try:
17311731
QPolyParameters(self, order=order).check_schoenberg()
17321732
except InfeasibleError as ex:
1733-
raise InfeasibleError(ex, part="Q-polynomial ordering %s" %
1734-
(order, ))
1733+
raise InfeasibleError(ex, part=f"Q-polynomial ordering {order}")
17351734
return
17361735
rr = range(self._.d + 1)
17371736
t = SR.symbol("__t")
@@ -1955,9 +1954,9 @@ def __eq__(self, other):
19551954
"""
19561955
if isinstance(other, self._get_class()):
19571956
return self._.hash_parameters == other._.hash_parameters
1958-
else:
1959-
return not isinstance(other, ASParameters) \
1960-
and self._.hash_parameters == other
1957+
1958+
return not isinstance(other, ASParameters) \
1959+
and self._.hash_parameters == other
19611960

19621961
def __hash__(self):
19631962
"""
@@ -1969,15 +1968,13 @@ def __repr__(self):
19691968
"""
19701969
String representation.
19711970
"""
1972-
return "Parameters of a %s with %s %s" % \
1973-
(self.OBJECT, self.ARRAY, self._format_parameterArray())
1971+
return "Parameters of a {} with {} {}".format(self.OBJECT, self.ARRAY, self._format_parameterArray())
19741972

19751973
def _ascii_art_(self):
19761974
"""
19771975
ASCII art representation.
19781976
"""
1979-
return ascii_art("Parameters of a %s with %s " %
1980-
(self.OBJECT, self.ARRAY),
1977+
return ascii_art(f"Parameters of a {self.OBJECT} with {self.ARRAY} ",
19811978
self._format_parameterArray_ascii())
19821979

19831980
def _check_family(self):
@@ -2074,11 +2071,11 @@ def _compute_dualParameters(self, q, k, m, tr):
20742071
for i in range(self._.d + 1):
20752072
for j in range(self._.d + 1):
20762073
q[h, i, j] = full_simplify(
2077-
sum(k[t] * self._.omega[tr(h, t)]
2078-
* self._.omega[tr(i, t)]
2079-
* self._.omega[tr(j, t)]
2080-
for t in range(self._.d + 1))
2081-
* m[i] * m[j] / self._.n)
2074+
sum(k[t] * self._.omega[tr(h, t)]
2075+
* self._.omega[tr(i, t)]
2076+
* self._.omega[tr(j, t)]
2077+
for t in range(self._.d + 1))
2078+
* m[i] * m[j] / self._.n)
20822079
self._check_parameter(h, i, j, q[h, i, j],
20832080
integral=self.DUAL_INTEGRAL,
20842081
name=self.DUAL_PARAMETER,
@@ -2236,16 +2233,16 @@ def _compute_sizes(self, k, expand=False, factor=False,
22362233
else:
22372234
try:
22382235
m = tuple(integralize(_simplify(_factor(
2239-
self._.n / sum(s * om**2
2240-
for s, om in zip(k, omg)))))
2236+
self._.n / sum(s * om**2
2237+
for s, om in zip(k, omg)))))
22412238
for omg in self._.omega)
22422239
except TypeError:
22432240
raise InfeasibleError("%s not integral" % self.DUAL_SIZES)
22442241
return m
22452242

22462243
def _copy(self, p):
22472244
"""
2248-
Copy fields to the given obejct.
2245+
Copy fields to the given object.
22492246
"""
22502247
ASParameters._copy(self, p)
22512248
if isinstance(p, self._get_class()):
@@ -2278,15 +2275,14 @@ def _derived(self, derived=True):
22782275
Generate parameters sets of derived association schemes.
22792276
"""
22802277
self.partSchemes()
2281-
for par, part, refs, reorder in ASParameters._derived(self, derived):
2282-
yield (par, part, refs, reorder)
2278+
yield from ASParameters._derived(self, derived)
22832279

22842280
def _format_parameterArray(self):
22852281
"""
22862282
Return a string representation of the intersection array.
22872283
"""
2288-
return "{%s; %s}" % tuple(', '.join(str(x) for x in l)
2289-
for l in self.parameterArray())
2284+
return "{{{}; {}}}".format(*tuple(', '.join(str(x) for x in l)
2285+
for l in self.parameterArray()))
22902286

22912287
def _format_parameterArray_ascii(self):
22922288
"""
@@ -2303,9 +2299,9 @@ def _format_parameterArray_latex(self):
23032299
"""
23042300
Return a LaTeX representation of the intersection array.
23052301
"""
2306-
return r"\left\{%s; %s\right\}" % tuple(', '.join(latex(x)
2307-
for x in l) for l
2308-
in self.parameterArray())
2302+
return r"\left\{{{}; {}\right\}}".format(*tuple(', '.join(latex(x)
2303+
for x in l)
2304+
for l in self.parameterArray()))
23092305

23102306
def _format_parameterArray_unicode(self):
23112307
"""
@@ -2355,9 +2351,8 @@ def _latex_(self):
23552351
"""
23562352
LaTeX representation.
23572353
"""
2358-
return LatexExpr(r"\text{Parameters of a %s with %s } %s" %
2359-
(self.OBJECT_LATEX, self.ARRAY,
2360-
self._format_parameterArray_latex()))
2354+
return LatexExpr(r"\text{{Parameters of a {} with {} }} {}".format(self.OBJECT_LATEX, self.ARRAY,
2355+
self._format_parameterArray_latex()))
23612356

23622357
def _match(self, b, c):
23632358
"""
@@ -2384,8 +2379,7 @@ def _unicode_art_(self):
23842379
"""
23852380
Unicode art representation.
23862381
"""
2387-
return unicode_art("Parameters of a %s with %s " %
2388-
(self.OBJECT, self.ARRAY),
2382+
return unicode_art(f"Parameters of a {self.OBJECT} with {self.ARRAY} ",
23892383
self._format_parameterArray_unicode())
23902384

23912385
def antipodalSubscheme(self):
@@ -2535,9 +2529,8 @@ def merge(self, k, p, *args, **kargs):
25352529
eqs.append(c0 == cc)
25362530
else:
25372531
if len(bi) > 1 or len(ci) > 1:
2538-
raise IndexError("merging %s %s does not yield "
2539-
"a %s-polynomial scheme" %
2540-
(self.PARTS, sorted(adj), self.MATRIX))
2532+
raise IndexError("merging {} {} does not yield "
2533+
"a {}-polynomial scheme".format(self.PARTS, sorted(adj), self.MATRIX))
25412534
b.append(next(iter(bi)))
25422535
c.append(next(iter(ci)))
25432536
cur = nxt
@@ -2640,7 +2633,7 @@ def terwilligerPolynomial(self, var='x', i=2, p_order=None, q_order=None):
26402633
self.pTable()
26412634
if not self._has("Q"):
26422635
self.dualEigenmatrix()
2643-
x = SR.symbol(var) if isinstance(var, six.string_types) else var
2636+
x = SR.symbol(var) if isinstance(var, str) else var
26442637
ths = next(iter(zip(*self._.Q[p_order, q_order[1]]))) \
26452638
+ (Integer(0), )
26462639
o = p_order[1]

drg/aux.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from .references import refs as references
2-
from .util import utf8
32

43

54
class InfeasibleError(Exception):
@@ -16,7 +15,7 @@ def __init__(self, reason=None, refs=None, part=None):
1615
elif not isinstance(part, tuple):
1716
part = (part, )
1817
if refs is None:
19-
refs = []
18+
refs = []
2019
elif not isinstance(refs, list):
2120
refs = [refs]
2221
refs = [(references[pap], thm)
@@ -42,7 +41,7 @@ def __init__(self, reason=None, refs=None, part=None):
4241
if len(self.refs) > 0:
4342
msg.append("nonexistence by %s" %
4443
"; ".join(self.formatRef(ref) for ref in self.refs))
45-
self.args = (utf8(": ".join(msg)), )
44+
self.args = (": ".join(msg), )
4645

4746
@staticmethod
4847
def formatRef(ref):
@@ -53,10 +52,10 @@ def formatRef(ref):
5352
if thm is None:
5453
return pap.name
5554
else:
56-
return "%s, %s" % (pap.name, thm)
55+
return f"{pap.name}, {thm}"
5756

5857

59-
class Parameters(object):
58+
class Parameters:
6059
"""
6160
An auxiliary class for storing the computed parameters.
6261
"""

0 commit comments

Comments
 (0)