Skip to content

Commit

Permalink
accept sparse hyperplanes
Browse files Browse the repository at this point in the history
  • Loading branch information
natemacfadden committed Oct 11, 2023
1 parent 4c1070b commit 71d543e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cytools/cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,12 @@ def find_interior_point(self, c=1, integral=False, backend=None, check=True):
backend = "glop"

if isinstance(self._hyperplanes, (list, np.ndarray)):
self._hyperplanes = np.asarray(self._hyperplanes)
hp_iter = enumerate
dot = lambda hp,x: hp.dot(x)
else:
hp_iter = lambda hp:hp.items()
dot = lambda hp,x: sum([val*x[ind] for ind,val in hp_iter(hp)])

if backend in ("glop", "scip"):
solver = pywraplp.Solver.CreateSolver(backend.upper())
Expand Down Expand Up @@ -1019,7 +1022,7 @@ def find_interior_point(self, c=1, integral=False, backend=None, check=True):
return None

# Make sure that the solution is valid
if check and any(sum([val*solution[ind] for ind,val in hp_iter(v)]) <= 0 for v in self._hyperplanes):
if check and any(dot(v,solution) <= 0 for v in self._hyperplanes):
warnings.warn("The solution that was found is invalid.")
return None

Expand All @@ -1028,7 +1031,7 @@ def find_interior_point(self, c=1, integral=False, backend=None, check=True):
n_tries = 1000
for i in range(1,n_tries):
int_sol = np.array([int(round(x)) for x in i*solution])
if all(int_sol.dot(v) > 0 for v in self._hyperplanes):
if all(dot(v,int_sol) > 0 for v in self._hyperplanes):
break
if i == n_tries-1:
return None
Expand Down

0 comments on commit 71d543e

Please sign in to comment.