当前位置: 首页>>代码示例>>Python>>正文


Python bisect.bisect_right方法代码示例

本文整理汇总了Python中bisect.bisect_right方法的典型用法代码示例。如果您正苦于以下问题:Python bisect.bisect_right方法的具体用法?Python bisect.bisect_right怎么用?Python bisect.bisect_right使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bisect的用法示例。


在下文中一共展示了bisect.bisect_right方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_cat_ids

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def get_cat_ids(self, idx):
        """Get category ids of concatenated dataset by index.

        Args:
            idx (int): Index of data.

        Returns:
            list[int]: All categories in the image of specified index.
        """

        if idx < 0:
            if -idx > len(self):
                raise ValueError(
                    'absolute value of index should not exceed dataset length')
            idx = len(self) + idx
        dataset_idx = bisect.bisect_right(self.cumulative_sizes, idx)
        if dataset_idx == 0:
            sample_idx = idx
        else:
            sample_idx = idx - self.cumulative_sizes[dataset_idx - 1]
        return self.datasets[dataset_idx].get_cat_ids(sample_idx) 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:23,代码来源:dataset_wrappers.py

示例2: iterate_from

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def iterate_from(self, start_tok):
        piecenum = bisect.bisect_right(self._offsets, start_tok)-1

        while piecenum < len(self._pieces):
            offset = self._offsets[piecenum]
            piece = self._pieces[piecenum]

            # If we've got another piece open, close it first.
            if self._open_piece is not piece:
                if self._open_piece is not None:
                    self._open_piece.close()
                self._open_piece = piece

            # Get everything we can from this piece.
            for tok in piece.iterate_from(max(0, start_tok-offset)):
                yield tok

            # Update the offset table.
            if piecenum+1 == len(self._offsets):
                self._offsets.append(self._offsets[-1] + len(piece))

            # Move on to the next piece.
            piecenum += 1 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:25,代码来源:util.py

示例3: bisect_right

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def bisect_right(self, value):
        """Return an index to insert `value` in the sorted-key list.

        Similar to `bisect_left`, but if `value` is already present, the
        insertion point with be after (to the right of) any existing values.

        Similar to the `bisect` module in the standard library.

        Runtime complexity: `O(log(n))` -- approximate.

        >>> from operator import neg
        >>> skl = SortedList([5, 4, 3, 2, 1], key=neg)
        >>> skl.bisect_right(1)
        5

        :param value: insertion index of value in sorted-key list
        :return: index

        """
        return self._bisect_key_right(self._key(value)) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:22,代码来源:sortedlist.py

示例4: get_statement_startend2

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def get_statement_startend2(lineno, node):
    import ast
    # flatten all statements and except handlers into one lineno-list
    # AST's line numbers start indexing at 1
    l = []
    for x in ast.walk(node):
        if isinstance(x, _ast.stmt) or isinstance(x, _ast.ExceptHandler):
            l.append(x.lineno - 1)
            for name in "finalbody", "orelse":
                val = getattr(x, name, None)
                if val:
                    # treat the finally/orelse part as its own statement
                    l.append(val[0].lineno - 1 - 1)
    l.sort()
    insert_index = bisect_right(l, lineno)
    start = l[insert_index - 1]
    if insert_index >= len(l):
        end = None
    else:
        end = l[insert_index]
    return start, end 
开发者ID:pytest-dev,项目名称:py,代码行数:23,代码来源:source.py

示例5: get_last_full_moon

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def get_last_full_moon(d):
    """
    Returns the last full moon for d

    Raises ValueError if the d value is not between 2000 - 2099
    """

    now = d.timestamp
    idx = bisect.bisect_right(fullmoons, now)
    if idx in [0, len(fullmoons)]:
        raise ValueError(
            u'watson has only full moon dates from year 2000 to 2099, not {}'
            .format(d.year))

    last = fullmoons[idx - 1]
    return arrow.get(last) 
开发者ID:TailorDev,项目名称:Watson,代码行数:18,代码来源:fullmoon.py

示例6: Add

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def Add(self, score):
    """Add a score into the last N scores.

    If needed, drops the score that is furthest away from the given score.
    """
    num_sampled_scores = len(self.scores)
    if num_sampled_scores < self.MAX_NUM_SAMPLED_SCORES:
      bisect.insort(self.scores, score)
    else:
      index_left = bisect.bisect_left(self.scores, score)
      index_right = bisect.bisect_right(self.scores, score)
      index_center = index_left + (index_right - index_left) / 2
      self.scores.insert(index_left, score)
      if index_center < num_sampled_scores / 2:
        self.scores.pop()
      else:
        self.scores.pop(0)
    self.num_scores += 1 
开发者ID:elsigh,项目名称:browserscope,代码行数:20,代码来源:local_scores.py

示例7: Add

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def Add(self, score):
    """Add a score into the last N scores.

    If needed, drops the score that is furthest away from the given score.
    """
    num_sampled_scores = len(self.scores)
    if num_sampled_scores < self.MAX_NUM_SAMPLED_SCORES:
      bisect.insort(self.scores, score)
    else:
      index_left = bisect.bisect_left(self.scores, score)
      index_right = bisect.bisect_right(self.scores, score)
      index_center = index_left + (index_right - index_left) / 2
      self.scores.insert(index_left, score)
      if index_center < num_sampled_scores / 2:
        self.scores.pop()
      else:
        self.scores.pop(0)
    self.num_scores += 1
    RankerCacher.CachePut(self) 
开发者ID:elsigh,项目名称:browserscope,代码行数:21,代码来源:result_ranker.py

示例8: get_ancestral_haplotypes

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def get_ancestral_haplotypes(ts):
    """
    Returns a numpy array of the haplotypes of the ancestors in the
    specified tree sequence.
    """
    tables = ts.dump_tables()
    nodes = tables.nodes
    flags = nodes.flags[:]
    flags[:] = 1
    nodes.set_columns(time=nodes.time, flags=flags)

    sites = tables.sites.position
    tsp = tables.tree_sequence()
    B = tsp.genotype_matrix().T

    A = np.full((ts.num_nodes, ts.num_sites), tskit.MISSING_DATA, dtype=np.int8)
    for edge in ts.edges():
        start = bisect.bisect_left(sites, edge.left)
        end = bisect.bisect_right(sites, edge.right)
        if sites[end - 1] == edge.right:
            end -= 1
        A[edge.parent, start:end] = B[edge.parent, start:end]
    A[: ts.num_samples] = B[: ts.num_samples]
    return A 
开发者ID:tskit-dev,项目名称:tsinfer,代码行数:26,代码来源:eval_util.py

示例9: query_by_time

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def query_by_time(self, category, time_start=None, time_end=None):
        self._purge_old_events(category)

        class ItemWrapper(object):
            def __init__(self, tl):
                self._l = tl

            def __getitem__(self, item):
                return self._l[item][0]

            def __len__(self):
                return len(self._l)

        timeline = self._event_timelines[category]
        left_pos = 0 if time_start is None \
            else bisect.bisect_left(ItemWrapper(timeline), time_start)
        right_pos = len(timeline) if time_end is None \
            else bisect.bisect_right(ItemWrapper(timeline), time_end)
        return [it[1] for it in itertools.islice(timeline, left_pos, right_pos)] 
开发者ID:mars-project,项目名称:mars,代码行数:21,代码来源:events.py

示例10: _find_nearest_size

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def _find_nearest_size(self, size_candidate):
        index = bisect.bisect_right(self._possible_sizes, size_candidate)

        if index == 0:
            return self._possible_sizes[0]

        if index >= len(self._possible_sizes):
            return self._possible_sizes[-1]

        right_size = self._possible_sizes[index]
        left_size = self._possible_sizes[index - 1]

        if abs(size_candidate - right_size) < abs(size_candidate - left_size):
            return right_size
        else:
            return left_size 
开发者ID:nemanja-m,项目名称:gaps,代码行数:18,代码来源:size_detector.py

示例11: get_statement_startend2

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def get_statement_startend2(lineno, node):
    import ast

    # flatten all statements and except handlers into one lineno-list
    # AST's line numbers start indexing at 1
    values = []
    for x in ast.walk(node):
        if isinstance(x, (ast.stmt, ast.ExceptHandler)):
            values.append(x.lineno - 1)
            for name in ("finalbody", "orelse"):
                val = getattr(x, name, None)
                if val:
                    # treat the finally/orelse part as its own statement
                    values.append(val[0].lineno - 1 - 1)
    values.sort()
    insert_index = bisect_right(values, lineno)
    start = values[insert_index - 1]
    if insert_index >= len(values):
        end = None
    else:
        end = values[insert_index]
    return start, end 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:24,代码来源:source.py

示例12: find_module

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def find_module(modlist, mod_addrs, addr):
    """Uses binary search to find what module a given address resides in.

    This is much faster than a series of linear checks if you have
    to do it many times. Note that modlist and mod_addrs must be sorted
    in order of the module base address.
    
    NOTE: the mod_addrs and addr parameters must already be masked for 
    the address space"""

    pos = bisect_right(mod_addrs, addr) - 1
    if pos == -1:
        return None
    mod = modlist[mod_addrs[pos]]

    if (mod.obj_vm.address_compare(addr, mod.DllBase) != -1 and
            mod.obj_vm.address_compare(addr, mod.DllBase + mod.SizeOfImage) == -1):
        return mod
    else:
        return None 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:22,代码来源:tasks.py

示例13: find_module

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def find_module(cls, modlist, mod_addrs, addr_space, vpage):
        """Determine which module owns a virtual page. 

        :param      modlist     | <list>
                    mod_addrs   | <list>
                    addr_space  | <addrspace.AbstractVirtualAddressSpace>
                    vpage       | <int> 
        
        :returns    <module> || None
        """

        pos = bisect_right(mod_addrs, vpage) - 1
        if pos == -1:
            return None
        mod = modlist[mod_addrs[pos]]

        compare = mod.obj_vm.address_compare
        if (compare(vpage, mod.module_core) != -1 and
                compare(vpage, mod.module_core + mod.core_size) == -1):
            return mod
        else:
            return None 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:24,代码来源:linux_strings.py

示例14: find_module

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def find_module(cls, modlist, mod_addrs, addr_space, vpage):
        """Determine which module owns a virtual page. 

        :param      modlist     | <list>
                    mod_addrs   | <list>
                    addr_space  | <addrspace.AbstractVirtualAddressSpace>
                    vpage       | <int> 
        
        :returns    <module> || None
        """

        pos = bisect_right(mod_addrs, vpage) - 1
        if pos == -1:
            return None
        mod = modlist[mod_addrs[pos]]

        compare = mod.obj_vm.address_compare
        if (compare(vpage, mod.address) != -1 and
                compare(vpage, mod.address + mod.m('size')) == -1):
            return mod
        else:
            return None 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:24,代码来源:mac_strings.py

示例15: getMxCompatibility

# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import bisect_right [as 别名]
def getMxCompatibility(version):
    """:rtype: MxCompatibility500"""
    if version < minVersion():  # ensures compat loaded
        return None
    keys = list(_versionsMap.keys())
    return _versionsMap[keys[bisect.bisect_right(keys, version)-1]] 
开发者ID:graalvm,项目名称:mx,代码行数:8,代码来源:mx_compat.py


注:本文中的bisect.bisect_right方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。