Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
LatticePolytopeClass, NefPartition, PointCollection, ToricLattice_amb…
Browse files Browse the repository at this point in the history
…ient: Add _sage_input_ methods
  • Loading branch information
Matthias Koeppe authored and dimpase committed Mar 6, 2022
1 parent a1bb676 commit 477b84c
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
47 changes: 47 additions & 0 deletions src/sage/geometry/lattice_polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,28 @@ def __init__(self, points=None, compute_vertices=None,
self._ambient_facet_indices = tuple(ambient_facet_indices)
self._vertices = ambient.vertices(self._ambient_vertex_indices)

def _sage_input_(self, sib, coerced):
"""
Return Sage command to reconstruct ``self``.
See :mod:`sage.misc.sage_input` for details.
EXAMPLES::
sage: p = lattice_polytope.cross_polytope(2)
sage: sage_input(p, verify=True)
# Verified
LatticePolytope(sage.geometry.point_collection.PointCollection((vector(ZZ, [1, 0]),
vector(ZZ, [0, 1]),
vector(ZZ, [-1, 0]),
vector(ZZ, [0, -1]))),
compute_vertices=False)
"""
if self._ambient is not self:
raise NotImplementedError
data = self._vertices
return sib.name('LatticePolytope')(sib(self._vertices), compute_vertices=False)

def __contains__(self, point):
r"""
Check if ``point`` is contained in ``self``.
Expand Down Expand Up @@ -4495,6 +4517,31 @@ def _repr_(self):
pass
return result

def _sage_input_(self, sib, coerced):
"""
Return Sage command to reconstruct ``self``.
See :mod:`sage.misc.sage_input` for details.
EXAMPLES::
sage: o = lattice_polytope.cross_polytope(3)
sage: np = o.nef_partitions()[0]; np
Nef-partition {0, 1, 3} U {2, 4, 5}
sage: sage_input(np, verify=True)
# Verified
NefPartition([0, 0, 1, 0, 1, 1],
LatticePolytope(sage.geometry.point_collection.PointCollection((vector(ZZ, [1, 0, 0]),
vector(ZZ, [0, 1, 0]),
vector(ZZ, [0, 0, 1]),
vector(ZZ, [-1, 0, 0]),
vector(ZZ, [0, -1, 0]),
vector(ZZ, [0, 0, -1]))),
compute_vertices=False))
"""
vertex_to_part = [ZZ(i) for i in self._vertex_to_part]
return sib.name('NefPartition')(vertex_to_part, sib(self.Delta_polar()))

def Delta(self, i=None):
r"""
Return the polytope $\Delta$ or $\Delta_i$ corresponding to ``self``.
Expand Down
33 changes: 27 additions & 6 deletions src/sage/geometry/point_collection.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,10 @@ cdef class PointCollection(SageObject):
if ``points`` are already accessible to you as a :class:`tuple`, it is
preferable to use it for speed and memory consumption reasons;
- ``module`` -- an ambient module for ``points``. If ``None``, it will be
determined as :func:`parent` of the first point. Of course, this cannot
be done if there are no points, so in this case you must give an
appropriate ``module`` directly. Note that ``None`` is *not* the default
value - you always *must* give this argument explicitly, even if it is
``None``.
- ``module`` -- an ambient module for ``points``. If ``None`` (the default),
it will be determined as :func:`parent` of the first point. Of course, this
cannot be done if there are no points, so in this case you must give an
appropriate ``module`` directly.
OUTPUT:
Expand Down Expand Up @@ -172,6 +170,29 @@ cdef class PointCollection(SageObject):
self._points = tuple(points)
self._module = self._points[0].parent() if module is None else module

def _sage_input_(self, sib, coerced):
r"""
Return Sage command to reconstruct ``self``.
See :mod:`sage.misc.sage_input` for details.
EXAMPLES::
sage: c = Cone([(0,0,1), (1,0,1), (0,1,1), (1,1,1)]).rays()
sage: sage_input(c, verify=True)
# Verified
sage.geometry.point_collection.PointCollection((vector(ZZ, [0, 0, 1]), vector(ZZ, [1, 0, 1]), vector(ZZ, [0, 1, 1]), vector(ZZ, [1, 1, 1])))
sage: c = sage.geometry.point_collection.PointCollection([], ToricLattice(2, 'U'))
sage: sage_input(c, verify=True)
# Verified
sage.geometry.point_collection.PointCollection((), ToricLattice(2, 'U', 'U*', 'U', 'U^*'))
"""
args = [sib(self._points)]
if not self._points or self._module is not self._points[0].parent():
args.append(sib(self._module))
return sib.name('sage.geometry.point_collection.PointCollection')(*args)

def __add__(left, right):
r"""
Return the joint point collection.
Expand Down
23 changes: 23 additions & 0 deletions src/sage/geometry/toric_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,29 @@ def __init__(self, rank, name, dual_name, latex_name, latex_dual_name):
self._latex_name = latex_name
self._latex_dual_name = latex_dual_name

def _sage_input_(self, sib, coerced):
r"""
Return Sage command to reconstruct ``self``.
See :mod:`sage.misc.sage_input` for details.
EXAMPLES::
sage: N = ToricLattice(3, "N", "M", "N", "M")
sage: sage_input(N, verify=True)
# Verified
ToricLattice(3, 'N', 'M')
sage: N = ToricLattice(3, "N")
sage: sage_input(N, verify=True)
# Verified
ToricLattice(3, 'N', 'N*', 'N', 'N^*')
"""
args = [self.rank(), self._name, self._dual_name]
if self._latex_name != self._name or self._latex_dual_name != self._dual_name:
args.extend([self._latex_name, self._latex_dual_name])
return sib.name('ToricLattice')(*args)

def __richcmp__(self, right, op):
r"""
Compare ``self`` and ``right``.
Expand Down

0 comments on commit 477b84c

Please sign in to comment.