Skip to content

Commit

Permalink
Solution Array: fix almost_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Jan 18, 2022
1 parent 3d4dd34 commit 1ac62d2
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions gpkit/solution_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,14 @@ def __call__(self, posy):
posy_subbed = self.subinto(posy)
return getattr(posy_subbed, "c", posy_subbed)

def almost_equal(self, other, reltol=1e-3, sens_abstol=0.01):
def almost_equal(self, other, reltol=1e-3):
"Checks for almost-equality between two solutions"
svars, ovars = self["variables"], other["variables"]
svks, ovks = set(svars), set(ovars)
if svks != ovks:
return False
for key in svks:
if abs(cast(np.divide, svars[key], ovars[key]) - 1) >= reltol:
return False
if abs(self["sensitivities"]["variables"][key]
- other["sensitivities"]["variables"][key]) >= sens_abstol:
if np.max(abs(cast(np.divide, svars[key], ovars[key]) - 1)) >= reltol:
return False
return True

Expand Down

0 comments on commit 1ac62d2

Please sign in to comment.