Skip to content

Commit

Permalink
fix and activate pycodestyle E225 in dev/ (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton authored Aug 5, 2023
1 parent 06a5ace commit 7fa4c14
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Run pycodestyle
shell: bash -l {0}
# We currently only check for some warnings. We should enable & fix more of them.
run: pycodestyle --select=E111,E302,E306,E401,E701,E702,E703,E704,W391,W605,E711,E713,E721 spherogram_src/
run: pycodestyle --select=E111,E225,E302,E306,E401,E701,E702,E703,E704,W391,W605,E711,E713,E721 spherogram_src/
- name: Run cython-lint
shell: bash -l {0}
run: cython-lint .
Expand Down
15 changes: 7 additions & 8 deletions dev/DTcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,20 @@ def entry_slot(self, N):
def exit_slot(self, N):
if N == self[0]:
return North
elif N == self[1]:
if N == self[1]:
return West
else:
raise ValueError('%d is not a label of %s'% (N, self))
raise ValueError('%d is not a label of %s' % (N, self))

def first_under(self):
first, second, even_over = self
if even_over:
return first-1 if first%2 == 1 else second-1
return first-1 if first % 2 == 1 else second-1
else:
return first-1 if first%2 == 0 else second-1
return first-1 if first % 2 == 0 else second-1

def upper_pair(self):
first, second, even_over = self
return (0,2) if bool(first%2) ^ even_over else (1,3)
return (0,2) if bool(first % 2) ^ even_over else (1,3)


class DTPath():
Expand Down Expand Up @@ -471,7 +470,7 @@ def sign(self, vertex):
See the documentation for Spherogram.link.
"""
flipped = self.flipped(vertex)
even_first = bool(vertex[0] %2 == 0)
even_first = bool(vertex[0] % 2 == 0)
return -1 if (flipped ^ vertex[2] ^ even_first) else 1

def KLP_strand(self, vertex, edge):
Expand All @@ -481,7 +480,7 @@ def KLP_strand(self, vertex, edge):
"""
W = edge(vertex)
slot = edge.slot(W)
return 'X' if (slot==0 or slot==2) ^ self.flipped(W) else 'Y'
return 'X' if (slot == 0 or slot == 2) ^ self.flipped(W) else 'Y'

def KLP_dict(self, vertex, indices):
"""
Expand Down
3 changes: 2 additions & 1 deletion dev/dev_jennet/spanning_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def spanning_trees(G):
else:
return []


def rec(part_G,G):
"""
Recursive function 'rec' from Read paper
Expand All @@ -31,7 +32,7 @@ def rec(part_G,G):
return []

if len(G.edges()) == len(part_G.edges()):
trees +=[part_G.copy()]
trees += [part_G.copy()]
else:

# let e be an edge not in part_G
Expand Down
26 changes: 13 additions & 13 deletions dev/dev_jennet/test_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def setUp(self):
# Hopf Link
a = spherogram.Crossing('a')
b = spherogram.Crossing('b')
a[0]=b[1]
a[1]=b[0]
a[2]=b[3]
a[3]=b[2]
a[0] = b[1]
a[1] = b[0]
a[2] = b[3]
a[3] = b[2]
self.L2a1 = spherogram.Link([a,b])

#Borromean Link (3)
Expand Down Expand Up @@ -142,7 +142,7 @@ def testConnectedSum(self):
self.assertEqual(Sum.alexander_poly(), k1.alexander_poly()*k2.alexander_poly())
self.assertEqual(Sum.signature(), k1.signature()+k2.signature())
self.assertEqual(Sum.determinant(), k1.determinant()*k2.determinant())
repeat -=1
repeat -= 1

def testSignature(self):
self.assertEqual(abs(self.Tref.signature()), 2)
Expand All @@ -165,7 +165,7 @@ def testCopy(self):
self.assertEqual(k1.writhe(), k1_prime.writhe())
self.assertEqual(k1.signature(), k1_prime.signature())
self.assertEqual(k1.alexander_poly(), k1_prime.alexander_poly())
repeat-=1
repeat -= 1

repeat = 3
while repeat > 0:
Expand All @@ -175,24 +175,24 @@ def testCopy(self):
self.assertEqual(k2.writhe(), k2_prime.writhe())
self.assertEqual(k2.signature(), k2_prime.signature())
self.assertEqual(k2.alexander_poly(), k2_prime.alexander_poly())
repeat-=1
repeat -= 1

def testMirror(self):
repeat = 3
while repeat > 0:
k1 = self.random_knot()
k1_prime = k1.mirror()
self.assert_(k1.signature() == -1*k1_prime.signature(), msg="knot signature failed for "+ repr(k1))
self.assert_(k1.writhe() == -1*k1_prime.writhe(), msg="knot writhe failed for "+repr(k1))
repeat-=1
self.assert_(k1.signature() == -1*k1_prime.signature(), msg="knot signature failed for " + repr(k1))
self.assert_(k1.writhe() == -1*k1_prime.writhe(), msg="knot writhe failed for " + repr(k1))
repeat -= 1

repeat = 3
while repeat > 0:
k2 = self.random_link()
k2_prime = k2.mirror()
self.assert_(k2.signature() == -1*k2_prime.signature(), msg="link signature failed for " + repr(k2))
self.assert_(k2.writhe() == -1*k2_prime.writhe(), msg="link writhe failed for " + repr(k2))
repeat-=1
repeat -= 1

def testDet(self):
self.assertEqual(self.K3_1.determinant(), 3)
Expand Down Expand Up @@ -240,13 +240,13 @@ def testBlackGraph(self):
while repeat > 0:
k1 = self.random_knot()
self.assert_(k1.black_graph().is_planar())
repeat-=1
repeat -= 1

repeat = 3
while repeat > 0:
k2 = self.random_link()
self.assert_(k2.black_graph().is_planar())
repeat-=1
repeat -= 1


suite = unittest.TestLoader().loadTestsFromTestCase(TestLinkFunctions)
Expand Down
3 changes: 2 additions & 1 deletion dev/dev_malik/fast_jones_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ def simplify_jones_expression(poly):
# print(poly)
return poly


def simplify_monomial(monomial):
monomial = remove_squares(monomial)
monomial = remove_loops(monomial)
A = sympy.Symbol('A')
strand_vars = monomial.free_symbols - set(sympy.symbols('A,B'))
strand_labels = all_labels(strand_vars)

while len(set(strand_labels))<len(strand_labels):
while len(set(strand_labels)) < len(strand_labels):
# collections.Counter
# print(monomial)
for l in strand_labels:
Expand Down
7 changes: 5 additions & 2 deletions dev/dev_malik/knots/random_knots.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ def random_knot(n):
connect_loose_strands(crossings, loose_cs, final_cs)
return Link(crossings)


def random_open_string(n):
crossings = [Crossing('0')]
crossings[0][2]=crossings[0][3]
crossings[0][2] = crossings[0][3]
final_cs = crossings[0].crossing_strands()[0]
loose_cs = crossings[0].crossing_strands()[1]
for i in range(n):
Expand All @@ -39,10 +40,12 @@ def random_open_string(n):

return crossings, loose_cs, final_cs


def flip_crossings(crossings, loose_cs, final_cs):
for c in crossings:
if c != loose_cs.crossing and c != final_cs.crossing:
c.rotate(randint(0,1))
c.rotate(randint(0, 1))


def cross_strand(crossings, loose_cs, strand_to_cross, new_label):
opposite = strand_to_cross.opposite()
Expand Down
6 changes: 3 additions & 3 deletions dev/dev_malik/mutation/link_planar_isotopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def isosig(self, root=None, over_or_under=False):
isosig_to_link = {}
for i in range(num_samples):
print(i)
K, root = random_rooted_link(size,edge_conn)
isosig = K.isosig(root,over_or_under=True)
isosig_to_link[isosig]=(K,root)
K, root = random_rooted_link(size, edge_conn)
isosig = K.isosig(root, over_or_under=True)
isosig_to_link[isosig] = (K, root)
isosigs.append(isosig)

C = Counter(isosigs)
Expand Down
Loading

0 comments on commit 7fa4c14

Please sign in to comment.