Skip to content

Commit 31c67b0

Browse files
committed
src/sage/geometry/cone.py: reviewer suggestions in Hilbert_basis()
Tighten the whitespace around list/generator comprehensions, and simplify the control flow in two instances by eliminating an if/else branch. (Only one of these was suggested by the reviewer, but the other is in a similar spirit.) Thanks to Martin Rubey for the suggestions.
1 parent 3542b29 commit 31c67b0

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/sage/geometry/cone.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4451,37 +4451,38 @@ def Hilbert_basis(self):
44514451
The primal Normaliz algorithm, see [Normaliz]_.
44524452
"""
44534453

4454-
if self.is_strictly_convex():
4455-
# Used in lieu of our linear_subspace() for containment
4456-
# testing. None of the points we test can be zero, so
4457-
# checking the empty tuple is equivalent to checking a
4458-
# trivial subspace, and the empty tuple is faster.
4459-
L = ()
4460-
else:
4454+
# Used in lieu of our linear_subspace() for containment
4455+
# testing when this cone is strictly convex. None of the
4456+
# points we test can be zero, so checking the empty tuple is
4457+
# equivalent to checking a trivial subspace, and the empty
4458+
# tuple is faster.
4459+
L = ()
4460+
4461+
if not self.is_strictly_convex():
44614462
# Our linear_subspace(), but as a cone, so that
44624463
# containment testing using "in" works properly.
4463-
L = Cone( (c*r for c in (1,-1) for r in self.lines()),
4464-
self.lattice() )
4464+
L = Cone((c*r for c in (1, -1) for r in self.lines()),
4465+
self.lattice())
44654466

44664467
irreducible = list(self.rays()) # these are irreducible for sure
44674468
irr_modified = False # have we appended to "irreducible"?
4468-
gens = [ x for x in self.semigroup_generators()
4469-
if x not in irreducible ]
4469+
gens = [x for x in self.semigroup_generators()
4470+
if x not in irreducible]
44704471

44714472
from itertools import chain
44724473
while gens:
44734474
x = gens.pop()
4474-
if all( (y in L) or (x-y not in self)
4475-
for y in chain(irreducible,gens) ):
4475+
if all((y in L) or (x-y not in self)
4476+
for y in chain(irreducible, gens)):
44764477
irreducible.append(x)
44774478
irr_modified = True
44784479

44794480
if irr_modified:
44804481
return PointCollection(irreducible, self.lattice())
4481-
else:
4482-
# Avoid the PointCollection overhead if nothing was
4483-
# added to the irreducible list beyond self.rays().
4484-
return self.rays()
4482+
4483+
# Avoid the PointCollection overhead if nothing was
4484+
# added to the irreducible list beyond self.rays().
4485+
return self.rays()
44854486

44864487

44874488
def Hilbert_coefficients(self, point, solver=None, verbose=0,

0 commit comments

Comments
 (0)