Skip to content

Commit

Permalink
whitespace cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sbailey committed Jan 3, 2024
1 parent 5cf3f7f commit cff734e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions py/desispec/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def test_argmatch(self):
b = np.array([3,2,1,4,2,3])
ii = util.argmatch(a, b)
self.assertTrue(np.all(a[ii] == b), f'{a=}, {ii=}, {a[ii]=} != {b=}')

#- special case already matching
a = np.array([1,3,2,4])
b = a.copy()
Expand All @@ -430,7 +430,7 @@ def test_argmatch(self):
b = a.copy()
ii = util.argmatch(a, b)
self.assertTrue(np.all(a[ii] == b), f'{a=}, {ii=}, {a[ii]=} != {b=}')

#- a with extras (before, in middle, and after range of b values)
a = np.array([1,3,2,4,0,5])
b = np.array([3,1,4])
Expand All @@ -453,13 +453,13 @@ def test_argmatch(self):
b = np.array([3,1,1,2,4])
ii = util.argmatch(a, b)
self.assertTrue(np.all(a[ii] == b), f'{a=}, {ii=}, {a[ii]=} != {b=}')

#- a can have extras, but not b
a = np.array([1,3,2,4])
b = np.array([3,2,5,4])
with self.assertRaises(ValueError):
ii = util.argmatch(a, b)

#- Brute force random testing with shuffles
a = np.arange(10)
b = a.copy()
Expand All @@ -478,7 +478,7 @@ def test_argmatch(self):
#- Note: extras in a is ok, just not in b
keep = np.isin(b, a)
b = b[keep]

ii = util.argmatch(a,b)
self.assertTrue(np.all(a[ii] == b), f'test number {test}\n{a=}\n{ii=}\n{a[ii]=} !=\n{b=}')

14 changes: 7 additions & 7 deletions py/desispec/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,17 +687,17 @@ def itemindices(a):
def argmatch(a, b):
"""
Returns indices ii such that a[ii] == b
Args:
a: array-like
b: array-like
Returns indices ii such that a[ii] == b
Both `a` and `b` are allowed to have repeats, and `a` values can be a
superset of `b`, but `b` cannot contain values that are not in `a`
because then no indices `ii` could result in `a[ii] == b`.
Related: desitarget.geomask.match_to which is similar, but doesn't allow
duplicates in `b`.
"""
Expand All @@ -711,15 +711,15 @@ def argmatch(a, b):
except IndexError:
#- if b has elements not in a, that can fail;
#- only do expensive check if needed
bad_b = np.isin(b, a, invert=True)
bad_b = np.isin(b, a, invert=True)
if np.any(bad_b):
raise ValueError(f'b contains values not in a; impossible to match {set(b[bad_b])} to {a=}')
else:
#- this should not occur
raise RuntimeError(f'argmatch failure for unknown reason {a=}, {b=}')

if not np.all(a[match_indices] == b):
#- this should not occur
raise RuntimeError(f'argmatch failure for unknown reason {a=} {match_indices=} {a[match_indices]=} != {b}')

return match_indices

0 comments on commit cff734e

Please sign in to comment.