Commit 80de2b00 authored by Vincent Delecroix's avatar Vincent Delecroix

refactor interaction with flipper

parent bf86301e
This diff is collapsed.
......@@ -2,10 +2,62 @@ r"""
Utility functions.
"""
from __future__ import print_function, absolute_import
def det2(u, v):
return u[0]*v[1] - u[1]*v[0]
def flipper_edge(T, e):
r"""
EXAMPLES::
sage: import flipper
sage: from veerer.layout import flipper_edge
sage: T = flipper.create_triangulation([(0r,1r,2r),(-1r,-2r,-3r)])
sage: sorted([flipper_edge(T, e) for e in T.edges])
[0, 1, 2, 3, 4, 5]
"""
n = (3 * T.num_triangles)
e = e.label
return n * (e < 0) + e
def flipper_edge_perm(n):
from array import array
return array('l', range(n-1,-1,-1))
def flipper_face_edge_perms(T):
r"""
Return a pair ``(face permutation, edge permutation)`` from a flipper triangulation.
"""
from .permutation import perm_init
n = 3 * T.num_triangles # number of half edges
# extract triangulation
triangles = [(flipper_edge(T, e), flipper_edge(T, f), flipper_edge(T, g)) for e,f,g in T]
return perm_init(triangles), flipper_edge_perm(n)
def flipper_isometry_to_perm(isom, ep, inv=False):
r"""
Question: how do we create an isometry in flipper?
"""
from array import array
n = isom.zeta
p = array('l', [-1]*(2*n))
if inv:
dic = isom.inverse_label_map
else:
dic = isom.label_map
for i,j in dic.items():
if i < 0:
i = ep[~i]
if j < 0:
j = ep[~j]
p[i] = j
return p
def flipper_nf_to_sage(K, name='a'):
r"""
Convert a flipper number field to Sage.
......
r"""
Partial permutation on `\{0, 1, ..., n-1\}`.
TODO:
- We want much faster datastructure (ie C array)
- In many situations, we need a bitarray of the size of
the permutation (conjugation, composition, etc). But
such array should not be allocated each time the function
is called.
"""
from __future__ import absolute_import, print_function
from six.moves import range, map, zip
......@@ -162,6 +171,12 @@ def perm_init(data, n=None, involution=None):
c = str_to_cycles(data)
return perm_from_cycles(c, n=n, involution=involution)
if data.__module__.startswith('flipper'):
if involution is None:
raise ValueError("involution must be provided")
from .misc import flipper_isometry_to_perm
return flipper_isometry_to_perm(data, involution)
raise TypeError("The input must be list, tuple or string")
def perm_from_cycles(t, n=None, involution=None):
......@@ -329,6 +344,7 @@ def perm_random_conjugacy_class(c):
#####################################################################
# Serialization
#####################################################################
# TODO: this is called often and would better be cythonized
CHARS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-'
CHARS_INV = {j:i for i,j in enumerate(CHARS)}
......@@ -486,6 +502,9 @@ def perm_cycles(p, singletons=True, n=None):
"""
if n is None:
n = len(p)
elif n < 0 or n > len(p):
raise ValueError
seen = [False] * n
res = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment