Skip to content

Commit

Permalink
added handling for subsets with multiple values
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelcdevin committed Oct 11, 2023
1 parent 4cd7724 commit 3bc805e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions wecopttool/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2354,10 +2354,14 @@ def subset_close(

ind = []
for el in set_a:
b_in_a = np.isclose(set_b, el,
a_in_b = np.isclose(set_b, el,
rtol=rtol, atol=atol, equal_nan=equal_nan)
if b_in_a.any():
ind.append(np.flatnonzero(b_in_a))
if np.sum(a_in_b) == 1:
ind.append(np.flatnonzero(a_in_b)[0])
if np.sum(a_in_b) > 1:
_log.warning('Multiple matching elements in subset, ' +
'selecting closest match.')
ind.append(np.argmin(np.abs(a_in_b - el)))
subset = len(set_a) == len(ind)
ind = ind if subset else []
return subset, ind
Expand Down

0 comments on commit 3bc805e

Please sign in to comment.