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 e6cda25 commit 6b32ce9
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions wecopttool/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,8 @@ def subset_close(
:py:func:`numpy.isclose`.
equal_nan
Whether to compare NaNs as equal. Passed to
:py:func:`numpy.isclose`.
:py:func:`numpy.isclose` and
:py:func:`numpy.array_equal`.
Returns
-------
Expand All @@ -2401,18 +2402,16 @@ def subset_close(
raise ValueError("Elements in set_b not unique")

ind = []
tmp_result = [False for _ in range(len(set_a))]
for subset_element in set_a:
for set_element in set_b:
if np.isclose(subset_element, set_element, rtol, atol, equal_nan):
tmp_set_ind = np.where(
np.isclose(set_element, set_b , rtol, atol, equal_nan))
tmp_subset_ind = np.where(
np.isclose(subset_element, set_a , rtol, atol,
equal_nan))
ind.append( int(tmp_set_ind[0]) )
tmp_result[ int(tmp_subset_ind[0]) ] = True
subset = all(tmp_result)
for el in set_a:
a_in_b = np.isclose(set_b, el,
rtol=rtol, atol=atol, equal_nan=equal_nan)
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 6b32ce9

Please sign in to comment.