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

Commit

Permalink
Use element_class instead of zero_vector
Browse files Browse the repository at this point in the history
  • Loading branch information
novoselt committed Nov 14, 2017
1 parent dd6a616 commit e37e8f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
34 changes: 17 additions & 17 deletions src/sage/geometry/lattice_polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,7 @@ def _compute_facets(self):
constants = []
for c in self._PPL().minimized_constraints():
if c.is_inequality():
n = N.zero_vector()
for i, coef in enumerate(c.coefficients()):
n[i] = coef
n = N.element_class(N, c.coefficients())
n.set_immutable()
normals.append(n)
constants.append(c.inhomogeneous_term())
Expand Down Expand Up @@ -3678,6 +3676,7 @@ def points(self, *args, **kwds):
"""
if not hasattr(self, "_points"):
M = self.lattice()
nv = self.nvertices()
self._points = points = self._vertices
if self.dim() == 1:
v = points[1] - points[0]
Expand All @@ -3691,17 +3690,19 @@ def points(self, *args, **kwds):
current.set_immutable()
points.append(current)
if self.dim() > 1:
m = self._embed(read_palp_matrix(
self.poly_x("p", reduce_dimension=True)))
if m.ncols() > self.nvertices():
points = list(points)
for j in range(self.nvertices(), m.ncols()):
current = M.zero_vector()
for i in range(M.rank()):
current[i] = m[i, j]
current.set_immutable()
points.append(current)
if len(points) > self.nvertices():
result = self.poly_x("p", reduce_dimension=True)
if self.dim() == self.lattice_dim():
points = read_palp_point_collection(StringIO(result), M)
else:
m = self._embed(read_palp_matrix(result))
if m.ncols() > nv:
points = list(points)
for j in range(nv, m.ncols()):
current = M.element_class(
M, [m[i, j] for i in range(M.rank())])
current.set_immutable()
points.append(current)
if len(points) > nv:
self._points = PointCollection(points, M)
if args or kwds:
return self._points(*args, **kwds)
Expand Down Expand Up @@ -5321,9 +5322,8 @@ def all_points(polytopes):
else:
points = list(p.vertices())
for j in range(nv, m.ncols()):
current = M.zero_vector()
for i in range(M.rank()):
current[i] = m[i, j]
current = M.element_class(
M, [m[i, j] for i in range(M.rank())])
current.set_immutable()
points.append(current)
p._points = PointCollection(points, M)
Expand Down
23 changes: 8 additions & 15 deletions src/sage/geometry/point_collection.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1000,24 +1000,17 @@ def read_palp_point_collection(f, lattice=None, permutation=False):
first_line = first_line.split()
m = int(first_line[0])
n = int(first_line[1])
points = []
if m >= n:
# Typical situation: a point on each line
if lattice is None:
lattice = ToricLattice(n).dual()
for i in range(m):
p = lattice.zero_vector()
for j, e in enumerate(f.readline().split()):
p[j] = int(e)
points.append(p)
lattice = lattice or ToricLattice(n).dual()
points = [lattice.element_class(lattice, f.readline().split())
for i in range(m)]
else:
if lattice is None:
lattice = ToricLattice(m).dual()
for i in range(n):
points.append(lattice.zero_vector())
for j in range(m):
for i, e in enumerate(f.readline().split()):
points[i][j] = int(e)
# Also may appear as PALP output, e.g. points of 3-d polytopes
lattice = lattice or ToricLattice(m).dual()
data = [f.readline().split() for j in range(m)]
points = [lattice.element_class(lattice, [data[j][i] for j in range(m)])
for i in range(n)]
for p in points:
p.set_immutable()
pc = PointCollection(points, lattice)
Expand Down

0 comments on commit e37e8f7

Please sign in to comment.