Skip to content

Commit

Permalink
TMP COMMIT
Browse files Browse the repository at this point in the history
  • Loading branch information
videlec committed Jun 13, 2024
1 parent f45f00b commit f84b93e
Show file tree
Hide file tree
Showing 6 changed files with 719 additions and 86 deletions.
7 changes: 6 additions & 1 deletion veerer/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +785,15 @@ def _plot_edge_label(self, a, tilde=None, **opts):

if tilde:
if a > ep[a]:
lab = "%s=~%s" % (a, ep[a])
#lab = "%s=~%s" % (a, ep[a])
# nicer shorter version
lab = "~" + str(ep[a])
else:
lab = str(a)
else:
if a > ep[a]:
from sage.plot.graphics import Graphics
return Graphics()
lab = str(a)

x, y = self._triangulation._holonomies[a]
Expand Down
11 changes: 11 additions & 0 deletions veerer/linear_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ def _horizontal_subspace(self):
mat[i, j] *= -1
return mat

def switch_subspace_generators_matrix(self, slope=VERTICAL):
if slope == VERTICAL:
if not self._mutable:
return self._subspace
else:
return self._subspace.__copy__()
elif slope == HORIZONTAL:
return self._horizontal_subspace
else:
raise ValueError

def as_linear_family(self):
return self

Expand Down
67 changes: 60 additions & 7 deletions veerer/permutation.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,40 @@ def str_to_cycles(s):
return r


def str_to_cycles_and_data(s):
r"""
Return a list of cycles and data from a string.
EXAMPLES::
sage: from veerer.permutation import str_to_cycles_and_data
sage: str_to_cycles_and_data('(0:1,1:2)')
([[0, 1]], {0: '1', 1: '2'})
sage: str_to_cycles_and_data('(0:1,1:2)(3:0)')
([[0, 1], [3]], {0: 1, 1: 2, 3: 0})
"""
r = []
data = {}
for c_str in s[1:-1].split(')('):
if not c_str:
continue
cycle = []
for c in c_str.replace(' ', '').split(','):
i = c.find(':')
if i == -1 or c.find(':', i + 1) != -1:
raise ValueError('invalid input string')
j = c[i+1:]
c = c[:i]
if c[0] == '~':
i = ~int(c[1:])
else:
i = int(c)
cycle.append(i)
data[i] = int(j)
r.append(cycle)
return r, data


def perm_random(int n):
r"""
Return a random permutation.
Expand Down Expand Up @@ -788,6 +822,31 @@ def perm_cycle_type(array.array p, int n=-1):
return c


def perm_cycles_to_string(list cycles, involution=None, data=None):
r"""
Return a string representing a list of cycles.
INPUT:
- ``cycles`` -- list of cycles
- ``involution`` -- optional involution (possibly with fixed points)
- ``data`` -- optional data
"""
if involution:
if data:
elt = lambda e: ('%d' % e if e <= involution[e] else '~%d' % involution[e]) + (':%d' % data[e])
else:
elt = lambda e: ('%d' % e if e <= involution[e] else '~%d' % involution[e])
elif data:
elt = lambda e: ('%d' % e) + (':%d' % data[e])
else:
elt = str

return ''.join(map(lambda x: '(' + ','.join(map(elt, x)) + ')', cycles))


def perm_cycle_string(array.array p, singletons=True, n=-1, involution=None):
r"""
Return a string representing the cycle decomposition of `p`
Expand All @@ -802,13 +861,7 @@ def perm_cycle_string(array.array p, singletons=True, n=-1, involution=None):
sage: perm_cycle_string(array('i', [0,2,1]), False)
'(1,2)'
"""
if involution:
elt = lambda e: '%d'%e if e <= involution[e] else '~%d'%involution[e]
else:
elt = str

return ''.join(map(lambda x: '('+','.join(map(elt, x))+')',
perm_cycles(p, singletons, n)))
return perm_cycles_to_string(perm_cycles(p, singletons, n), involution)


def perm_orbit(array.array p, int i):
Expand Down
3 changes: 3 additions & 0 deletions veerer/polyhedron/linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ def linear_form_normalize(base_ring, linear_form):
linear_form[k] /= c

return linear_form


vector_normalize = linear_form_normalize
Loading

0 comments on commit f84b93e

Please sign in to comment.