minor tuning
This commit is contained in:
parent
a0d79e729d
commit
5daf67ec7d
1 changed files with 47 additions and 20 deletions
62
chop/util.py
62
chop/util.py
|
|
@ -135,21 +135,59 @@ def find_faces(neighbors: numpy.ndarray) -> List[numpy.ndarray]:
|
|||
return cleaned_faces(remove, k)
|
||||
|
||||
|
||||
@profile
|
||||
def _get_map(a, b):
|
||||
'''
|
||||
Returns m, n such that a[m] == b, b[n] == a
|
||||
Returns m such that a[m] == b
|
||||
Assumes that all elements appear exactly once in each array
|
||||
'''
|
||||
assert(a.size == b.size)
|
||||
if a.size == 0:
|
||||
return numpy.array(()), numpy.array(())
|
||||
sa = a.argsort()
|
||||
sb = b.argsort()
|
||||
ra = numpy.empty_like(sa)
|
||||
rb = numpy.empty_like(sa)
|
||||
ra[sa] = numpy.arange(sa.size)
|
||||
rb[sb] = numpy.arange(sa.size)
|
||||
return sa[rb], sb[ra]
|
||||
r = numpy.empty_like(sa)
|
||||
r[sb] = numpy.arange(sa.size)
|
||||
return sa[r]
|
||||
|
||||
|
||||
@profile
|
||||
def _get_map_rows(a, b):
|
||||
'''
|
||||
Row-wise _get_map
|
||||
'''
|
||||
dims = numpy.maximum(a.max(0), b.max(0)) + 1
|
||||
a1d = numpy.ravel_multi_index(a.T, dims)
|
||||
b1d = numpy.ravel_multi_index(b.T, dims)
|
||||
return _get_map(a1d, b1d)
|
||||
|
||||
|
||||
@profile
|
||||
def _get_maps(a, b):
|
||||
'''
|
||||
Returns m, n such that a[m] == b, b[n] == a
|
||||
Assumes that all elements appear exactly once in each array
|
||||
'''
|
||||
if a.size == 0:
|
||||
return numpy.array(()), numpy.array(())
|
||||
sa = a.argsort()
|
||||
sb = b.argsort()
|
||||
r = numpy.empty_like(sa)
|
||||
r[sb] = numpy.arange(sa.size)
|
||||
m = sa[r]
|
||||
r[sa] = numpy.arange(sa.size)
|
||||
n = sb[r]
|
||||
return m, n
|
||||
|
||||
|
||||
@profile
|
||||
def _get_maps_rows(a, b):
|
||||
'''
|
||||
Row-wise _get_map_2way
|
||||
'''
|
||||
dims = numpy.maximum(a.max(0), b.max(0)) + 1
|
||||
a1d = numpy.ravel_multi_index(a.T, dims)
|
||||
b1d = numpy.ravel_multi_index(b.T, dims)
|
||||
return _get_map(a1d, b1d)
|
||||
|
||||
|
||||
def _argsort_rows(a):
|
||||
|
|
@ -161,16 +199,6 @@ def _argsort_rows(a):
|
|||
return numpy.argsort(a1d)
|
||||
|
||||
|
||||
def _get_map_rows(a, b):
|
||||
'''
|
||||
Row-wise _get_map
|
||||
'''
|
||||
dims = numpy.maximum(a.max(0), b.max(0)) + 1
|
||||
a1d = numpy.ravel_multi_index(a.T, dims)
|
||||
b1d = numpy.ravel_multi_index(b.T, dims)
|
||||
return _get_map(a1d, b1d)
|
||||
|
||||
|
||||
def _searchsorted_rows(a, b):
|
||||
'''
|
||||
Row-wise searchsorted
|
||||
|
|
|
|||
Loading…
Reference in a new issue