text stringlengths 0 828 |
|---|
4219,"def get_next_item(self): |
""""""Override the default functionality to not only try to pull things |
off the external input-queue, but to first try to pull things from a |
local input-queue that we'll primarily depend on. We'll only use the |
external input-queue to get the initial root-path (we could reuse it to |
do the recursion, but it's more costly and prone to delay). |
"""""" |
# Try to pop something off the local input-queue. |
try: |
return self.__local_input_q.get(block=False) |
except queue.Empty: |
pass |
# Try to pop something off the external input-queue. |
return self.input_q.get(block=False)" |
4220,"def index_nearest(array, value): |
"""""" |
Finds index of nearest value in array. |
Args: |
array: numpy array |
value: |
Returns: |
int |
http://stackoverflow.com/questions/2566412/find-nearest-value-in-numpy-array |
"""""" |
idx = (np.abs(array-value)).argmin() |
return idx" |
4221,"def BSearch(a, x, lo=0, hi=None): |
""""""Returns index of x in a, or -1 if x not in a. |
Arguments: |
a -- ordered numeric sequence |
x -- element to search within a |
lo -- lowest index to consider in search* |
hi -- highest index to consider in search* |
*bisect.bisect_left capability that we don't need to loose."""""" |
if len(a) == 0: return -1 |
hi = hi if hi is not None else len(a) |
pos = bisect_left(a, x, lo, hi) |
return pos if pos != hi and a[pos] == x else -1" |
4222,"def BSearchRound(a, x, lo=0, hi=None): |
""""""Returns index of a that is closest to x. |
Arguments: |
a -- ordered numeric sequence |
x -- element to search within a |
lo -- lowest index to consider in search* |
hi -- highest index to consider in search* |
*bisect.bisect_left capability that we don't need to loose."""""" |
if len(a) == 0: return -1 |
hi = hi if hi is not None else len(a) |
pos = bisect_left(a, x, lo, hi) |
if pos >= hi: |
return hi - 1 |
elif a[pos] == x or pos == lo: |
return pos |
else: |
return pos - 1 if x - a[pos - 1] <= a[pos] - x else pos" |
4223,"def BSearchCeil(a, x, lo=0, hi=None): |
""""""Returns lowest i such as a[i] >= x, or -1 if x > all elements in a |
So, if x is in between two elements in a, this function will return the |
index of the higher element, hence ""Ceil"". |
Arguments: |
a -- ordered numeric sequence |
x -- element to search within a |
lo -- lowest index to consider in search |
hi -- highest index to consider in search"""""" |
if len(a) == 0: return -1 |
hi = hi if hi is not None else len(a) |
pos = bisect_left(a, x, lo, hi) |
return pos if pos < hi else -1" |
4224,"def BSearchFloor(a, x, lo=0, hi=None): |
""""""Returns highest i such as a[i] <= x, or -1 if x < all elements in a |
So, if x is in between two elements in a, this function will return the |
index of the lower element, hence ""Floor"". |
Arguments: |
a -- ordered numeric sequence |
x -- element to search within a |
lo -- lowest index to consider in search |
hi -- highest index to consider in search"""""" |
if len(a) == 0: return -1 |
hi = hi if hi is not None else len(a) |
pos = bisect_left(a, x, lo, hi) |
return pos - 1 if pos >= hi \ |
else (pos if x == a[pos] else (pos - 1 if pos > lo else -1))" |
4225,"def FindNotNaNBackwards(x, i): |
""""""Returns last position (starting at i backwards) which is not NaN, or -1."""""" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.