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

Commit 477b84c

Browse files
Matthias Koeppedimpase
Matthias Koeppe
authored andcommitted
LatticePolytopeClass, NefPartition, PointCollection, ToricLattice_ambient: Add _sage_input_ methods
1 parent a1bb676 commit 477b84c

File tree

3 files changed

+97
-6
lines changed

3 files changed

+97
-6
lines changed

src/sage/geometry/lattice_polytope.py

+47
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,28 @@ 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((vector(ZZ, [1, 0]),
563+
vector(ZZ, [0, 1]),
564+
vector(ZZ, [-1, 0]),
565+
vector(ZZ, [0, -1]))),
566+
compute_vertices=False)
567+
"""
568+
if self._ambient is not self:
569+
raise NotImplementedError
570+
data = self._vertices
571+
return sib.name('LatticePolytope')(sib(self._vertices), compute_vertices=False)
572+
551573
def __contains__(self, point):
552574
r"""
553575
Check if ``point`` is contained in ``self``.
@@ -4495,6 +4517,31 @@ def _repr_(self):
44954517
pass
44964518
return result
44974519

4520+
def _sage_input_(self, sib, coerced):
4521+
"""
4522+
Return Sage command to reconstruct ``self``.
4523+
4524+
See :mod:`sage.misc.sage_input` for details.
4525+
4526+
EXAMPLES::
4527+
4528+
sage: o = lattice_polytope.cross_polytope(3)
4529+
sage: np = o.nef_partitions()[0]; np
4530+
Nef-partition {0, 1, 3} U {2, 4, 5}
4531+
sage: sage_input(np, verify=True)
4532+
# Verified
4533+
NefPartition([0, 0, 1, 0, 1, 1],
4534+
LatticePolytope(sage.geometry.point_collection.PointCollection((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+
vertex_to_part = [ZZ(i) for i in self._vertex_to_part]
4543+
return sib.name('NefPartition')(vertex_to_part, sib(self.Delta_polar()))
4544+
44984545
def Delta(self, i=None):
44994546
r"""
45004547
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)