Skip to content

Commit

Permalink
generae vertex labels if they don't exist
Browse files Browse the repository at this point in the history
Also, allow grabbing of optimal vertices
  • Loading branch information
natemacfadden committed Feb 19, 2024
1 parent df2f545 commit b3aee58
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cytools/polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ def label_origin(self):

@property
def labels_vertices(self):
if self._labels_vertices:
# generate the labels
self.vertices()
return self._labels_vertices

@property
Expand Down Expand Up @@ -990,12 +993,15 @@ def points_to_indices(self,
else:
return inds # return a list of indices

def vertices(self, as_indices: bool = False) -> np.ndarray:
def vertices(self,
optimal: bool = False,
as_indices: bool = False) -> np.ndarray:
"""
**Description:**
Returns the vertices of the polytope.
**Arguments:**
- `optimal`: Whether to return the points in their optimal coordinates.
- `as_indices`: Return the points as indices of the full list
of points of the polytope.
Expand All @@ -1017,7 +1023,9 @@ def vertices(self, as_indices: bool = False) -> np.ndarray:
"""
# return the answer if known
if self._labels_vertices is not None:
return self.pts(which=self._labels_vertices,as_indices=as_indices)
return self.pts(which=self._labels_vertices,
optimal=optimal,
as_indices=as_indices)

# calculate the answer
if self.dim() == 0:
Expand Down Expand Up @@ -1075,7 +1083,7 @@ def vertices(self, as_indices: bool = False) -> np.ndarray:
self._labels_vertices = tuple(sorted(self._labels_vertices))

# return
return self.vertices(as_indices=as_indices)
return self.vertices(optimal=optimal, as_indices=as_indices)

# faces
# =====
Expand Down

0 comments on commit b3aee58

Please sign in to comment.