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

Commit 74fdacf

Browse files
author
Matthias Koeppe
committed
LatticePolytopeClass, NefPartition, PointCollection, ToricLattice_ambient: Add _sage_input_ methods
1 parent 6be27b7 commit 74fdacf

File tree

3 files changed

+98
-6
lines changed

3 files changed

+98
-6
lines changed

src/sage/geometry/lattice_polytope.py

+48
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,27 @@ def __init__(self, points=None, compute_vertices=None,
548548
self._ambient_facet_indices = tuple(ambient_facet_indices)
549549
self._vertices = ambient.vertices(self._ambient_vertex_indices)
550550

551+
def _sage_input_(self, sib, coerced):
552+
"""
553+
Return Sage command to reconstruct ``self``.
554+
555+
See :mod:`sage.misc.sage_input` for details.
556+
557+
EXAMPLES::
558+
559+
sage: p = lattice_polytope.cross_polytope(2)
560+
sage: sage_input(p, verify=True)
561+
# Verified
562+
LatticePolytope(sage.geometry.point_collection.PointCollection(
563+
(vector(ZZ, [1, 0]), vector(ZZ, [0, 1]),
564+
vector(ZZ, [-1, 0]), vector(ZZ, [0, -1]))),
565+
compute_vertices=False)
566+
"""
567+
if self._ambient is not self:
568+
raise NotImplementedError
569+
data = self._vertices
570+
return sib.name('LatticePolytope')(sib(self._vertices), compute_vertices=False)
571+
551572
def __contains__(self, point):
552573
r"""
553574
Check if ``point`` is contained in ``self``.
@@ -4495,6 +4516,33 @@ def _repr_(self):
44954516
pass
44964517
return result
44974518

4519+
def _sage_input_(self, sib, coerced):
4520+
"""
4521+
Return Sage command to reconstruct ``self``.
4522+
4523+
See :mod:`sage.misc.sage_input` for details.
4524+
4525+
EXAMPLES::
4526+
4527+
sage: o = lattice_polytope.cross_polytope(3)
4528+
sage: np = o.nef_partitions()[0]; np
4529+
Nef-partition {0, 1, 3} U {2, 4, 5}
4530+
sage: sage_input(np, verify=True)
4531+
# Verified
4532+
NefPartition([0, 0, 1, 0, 1, 1],
4533+
LatticePolytope(sage.geometry.point_collection.PointCollection(
4534+
(vector(ZZ, [1, 0, 0]),
4535+
vector(ZZ, [0, 1, 0]),
4536+
vector(ZZ, [0, 0, 1]),
4537+
vector(ZZ, [-1, 0, 0]),
4538+
vector(ZZ, [0, -1, 0]),
4539+
vector(ZZ, [0, 0, -1]))),
4540+
compute_vertices=False))
4541+
"""
4542+
parts_list = [ZZ(self.part_of_point(i))
4543+
for i in range(self.Delta_polar().nvertices())]
4544+
return sib.name('NefPartition')(parts_list, sib(self.Delta_polar()))
4545+
44984546
def Delta(self, i=None):
44994547
r"""
45004548
Return the polytope $\Delta$ or $\Delta_i$ corresponding to ``self``.

src/sage/geometry/point_collection.pyx

+27-6
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ cdef class PointCollection(SageObject):
129129
if ``points`` are already accessible to you as a :class:`tuple`, it is
130130
preferable to use it for speed and memory consumption reasons;
131131
132-
- ``module`` -- an ambient module for ``points``. If ``None``, it will be
133-
determined as :func:`parent` of the first point. Of course, this cannot
134-
be done if there are no points, so in this case you must give an
135-
appropriate ``module`` directly. Note that ``None`` is *not* the default
136-
value - you always *must* give this argument explicitly, even if it is
137-
``None``.
132+
- ``module`` -- an ambient module for ``points``. If ``None`` (the default),
133+
it will be determined as :func:`parent` of the first point. Of course, this
134+
cannot be done if there are no points, so in this case you must give an
135+
appropriate ``module`` directly.
138136
139137
OUTPUT:
140138
@@ -172,6 +170,29 @@ cdef class PointCollection(SageObject):
172170
self._points = tuple(points)
173171
self._module = self._points[0].parent() if module is None else module
174172

173+
def _sage_input_(self, sib, coerced):
174+
r"""
175+
Return Sage command to reconstruct ``self``.
176+
177+
See :mod:`sage.misc.sage_input` for details.
178+
179+
EXAMPLES::
180+
181+
sage: c = Cone([(0,0,1), (1,0,1), (0,1,1), (1,1,1)]).rays()
182+
sage: sage_input(c, verify=True)
183+
# Verified
184+
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])))
185+
186+
sage: c = sage.geometry.point_collection.PointCollection([], ToricLattice(2, 'U'))
187+
sage: sage_input(c, verify=True)
188+
# Verified
189+
sage.geometry.point_collection.PointCollection((), ToricLattice(2, 'U', 'U*', 'U', 'U^*'))
190+
"""
191+
args = [sib(self._points)]
192+
if not self._points or self._module is not self._points[0].parent():
193+
args.append(sib(self._module))
194+
return sib.name('sage.geometry.point_collection.PointCollection')(*args)
195+
175196
def __add__(left, right):
176197
r"""
177198
Return the joint point collection.

src/sage/geometry/toric_lattice.py

+23
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,29 @@ def __init__(self, rank, name, dual_name, latex_name, latex_dual_name):
901901
self._latex_name = latex_name
902902
self._latex_dual_name = latex_dual_name
903903

904+
def _sage_input_(self, sib, coerced):
905+
r"""
906+
Return Sage command to reconstruct ``self``.
907+
908+
See :mod:`sage.misc.sage_input` for details.
909+
910+
EXAMPLES::
911+
912+
sage: N = ToricLattice(3, "N", "M", "N", "M")
913+
sage: sage_input(N, verify=True)
914+
# Verified
915+
ToricLattice(3, 'N', 'M')
916+
917+
sage: N = ToricLattice(3, "N")
918+
sage: sage_input(N, verify=True)
919+
# Verified
920+
ToricLattice(3, 'N', 'N*', 'N', 'N^*')
921+
"""
922+
args = [self.rank(), self._name, self._dual_name]
923+
if self._latex_name != self._name or self._latex_dual_name != self._dual_name:
924+
args.extend([self._latex_name, self._latex_dual_name])
925+
return sib.name('ToricLattice')(*args)
926+
904927
def __richcmp__(self, right, op):
905928
r"""
906929
Compare ``self`` and ``right``.

0 commit comments

Comments
 (0)