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


Python orderedset.OrderedSet方法代码示例

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


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

示例1: outputs

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def outputs(self):
        """
        A dictionary of all output ops as "name:op" pairs

        Notes:
            Outputs are defined as matching 1 of 2 criteria:
                1. Ops in the subgraph that aren't depended on by any other ops in the subgraph
                2. Not a variable or placeholder op
        """
        op_args = OrderedSet()
        ops = OrderedSet()
        for op in self:
            if isinstance(op, ng.AssignableTensorOp):
                continue
            ops.add(op)
            for arg_op in op.args + tuple(op.control_deps):
                op_args.add(arg_op)

        return ScopedDict(self.scope, [(op.tensor.name, op.tensor)
                                       for op in ops.difference(op_args)]) 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:22,代码来源:graph.py

示例2: comm_path_exists

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def comm_path_exists(fro, to):
    """
    Find a path from fro to to, including paths non-explicit edges from
    a Receiver to its Sender.

    Note- this is a non-standard traversal, as most traversals stop at a Receiver.
    """

    # TODO: Issue #1865 does this correctly handle traversing multiple send-recv junctions
    # from fro to to?

    visit = OrderedSet(fro.args)
    visit.add(fro)
    while visit:
        v = visit.pop()
        if v == to:
            return True
        if isinstance(v, RecvOp):
            visit |= get_iterable(v.send_node())
        else:
            visit.update(v.args)

    return False 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:25,代码来源:hetr_utils.py

示例3: do_pass

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def do_pass(self, ops, **kwargs):

        ops = OrderedSet(op.forwarded for op in ops)

        for op in reversed(Op.ordered_ops(ops)):
            if op.metadata.get('marker') == 'gather':
                # op is GatherRecvOp
                if self.parallel_axis is None:
                    a = op.metadata['parallel']
                    assert a.length % len(op.from_id) == 0, '{} can not be equally divided by {}'\
                        .format(a, len(op.from_id))
                    self.parallel_axis = make_axis(
                        name=a.name,
                        length=a.length // len(op.from_id),
                        docstring='HeTr parallel axis')
                gather_send_op = op.send_node()
                update_parallel_axis(gather_send_op, self.parallel_axis) 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:19,代码来源:hetrpasses.py

示例4: __call__

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def __call__(self, *args, **kwargs):
        """
        Executes child computations in parallel.

        :arg args: list of values to the placeholders specified in __init__ *args

        :return: tuple of return values, one per return specified in __init__ returns list.
        """
        args = self.unpack_args_or_feed_dict(args, kwargs)
        for child in itervalues(self.child_computations):
            child.feed_input([args[i] for i in child.param_idx])

        return_vals = dict()
        for child in itervalues(self.child_computations):
            return_vals.update(child.get_results())

        if isinstance(self.computation_op.returns, Op):
            return return_vals[self.computation_op.returns]
        elif isinstance(self.computation_op.returns, (collections.Sequence, OrderedSet)):
            return tuple(return_vals[op] for op in self.computation_op.returns)
        elif isinstance(self.computation_op.returns, collections.Set):
            return return_vals
        else:
            return None 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:26,代码来源:hetrtransform.py

示例5: _init_variables

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def _init_variables(self, variables_):
        """
        Maps variable names to variables
        :param variables_: list of variables
        :return: OrderedDict
        """
        # initialise
        variables = OrderedDict()
        size_to_variables = OrderedDict()
        # fill dict
        for v in variables_:
            variables[v.name] = v
            if v.size not in size_to_variables:
                size_to_variables[v.size] = OrderedSet()
            size_to_variables[v.size].add(v.name)

        return variables, size_to_variables 
开发者ID:RUB-SysSec,项目名称:syntia,代码行数:19,代码来源:game.py

示例6: test_move_templates_and_folders_to_root

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def test_move_templates_and_folders_to_root(mocker):

    mock_api_post = mocker.patch('app.notify_client.NotifyAdminAPIClient.post')

    some_service_id = uuid.uuid4()

    TemplateFolderAPIClient().move_to_folder(
        some_service_id,
        None,
        template_ids=OrderedSet(('a', 'b', 'c')),
        folder_ids=OrderedSet(('1', '2', '3')),
    )

    mock_api_post.assert_called_once_with(
        '/service/{}/template-folder/contents'.format(some_service_id),
        {
            'folders': ['1', '2', '3'],
            'templates': ['a', 'b', 'c'],
        },
    ) 
开发者ID:alphagov,项目名称:notifications-admin,代码行数:22,代码来源:test_template_folder_client.py

示例7: get_trackers_and_webseeds

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def get_trackers_and_webseeds(torrent):
    trackers = OrderedSet()
    webseeds = OrderedSet()

    # Our main one first
    main_announce_url = app.config.get('MAIN_ANNOUNCE_URL')
    if main_announce_url:
        trackers.add(main_announce_url)

    # then the user ones
    torrent_trackers = torrent.trackers  # here be webseeds too
    for torrent_tracker in torrent_trackers:
        tracker = torrent_tracker.tracker

        # separate potential webseeds
        if tracker.is_webseed:
            webseeds.add(tracker.uri)
        else:
            trackers.add(tracker.uri)

    # and finally our tracker list
    trackers.update(default_trackers())

    return list(trackers), list(webseeds) 
开发者ID:nyaadevs,项目名称:nyaa,代码行数:26,代码来源:torrents.py

示例8: register_ledger

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def register_ledger(self, ledger_id):
        # Using ordered set since after ordering each PRE-PREPARE,
        # the request key is removed, so fast lookup and removal of
        # request key is needed. Need the collection to be ordered since
        # the request key needs to be removed once its ordered
        if ledger_id not in self._ordering_service.requestQueues:
            self._ordering_service.requestQueues[ledger_id] = OrderedSet()
        if ledger_id != AUDIT_LEDGER_ID:
            self._freshness_checker.register_ledger(ledger_id=ledger_id,
                                                    initial_time=self.get_time_for_3pc_batch()) 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:12,代码来源:replica.py

示例9: __init__

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def __init__(self, metrics: MetricsCollector = NullMetricsCollector()):
        self.requests = Requests()
        self.requested_propagates_for = OrderedSet()
        self.metrics = metrics

    # noinspection PyUnresolvedReferences 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:8,代码来源:propagator.py

示例10: __init__

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def __init__(self, computation_decl=None, **kwargs):
        if computation_decl is None:
            raise ValueError("computation_decl must be specified.")
        super(ExOpBlock, self).__init__(execution_graph=computation_decl.execution_graph,
                                        **kwargs)
        self.computation_decl = computation_decl
        # Doubly linked loop, with self as termination
        self.prev_exop = self
        self.next_exop = self
        # All ops handled by the block.
        self.all_ops = set()

        self.root_set = OrderedSet() 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:15,代码来源:exop.py

示例11: initialize_allocations

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def initialize_allocations(self):
        """
        Inititializes allocation caches.

        """
        self.op_tensors = dict()
        self.op_tensor_views = dict()
        self.device_buffers = OrderedSet() 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:10,代码来源:base.py

示例12: allocate

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def allocate(self):
        """
        Allocate storage and then initializes constants.

        Will finalize if not already done.
        """
        if self.allocated:
            return

        if not self.finalized:
            logging.info("Finalizing transformer.")
            self._transform_computations()

        self.allocate_storage()

        init_states = OrderedSet()
        for op in OrderedSet(self.ops):
            op = op.forwarded
            states = op.states_read | op.states_written
            for state in states:
                state = state.forwarded
                if state.initial_value is not None:
                    init_states.add(state)
        for state in init_states:
            tensor_description = state.tensor.tensor_description()
            self.get_tensor_description_tensor_view(tensor_description)[...] = state.initial_value

        self.allocated = True 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:30,代码来源:base.py

示例13: find_recvs

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def find_recvs(fro):
    # Find all the Receivers fro depends on
    visit = OrderedSet()
    recvs = OrderedSet()
    visit.add(fro)
    while visit:
        v = visit.pop()
        if isinstance(v, RecvOp):
            recvs.add(v)
            visit |= get_iterable(v.send_node())
        else:
            if hasattr(v, 'args'):
                visit.update(v.args)

    return recvs 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:17,代码来源:hetr_utils.py

示例14: __init__

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def __init__(self, device='cpu', **kwargs):
        super(HetrTransformer, self).__init__(**kwargs)

        self.default_device = device
        self.my_pid = os.getpid()
        self.is_closed = False
        self.child_transformers = dict()
        self.send_nodes = OrderedSet()
        self.graph_passes = [DeviceAssignPass(hetr=self,
                                              default_device=device,
                                              default_device_id=0),
                             CommunicationPass(self.send_nodes),
                             AxesUpdatePass()]
        self.mpilauncher = MPILauncher() 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:16,代码来源:hetrtransform.py

示例15: all_op_references

# 需要导入模块: import orderedset [as 别名]
# 或者: from orderedset import OrderedSet [as 别名]
def all_op_references(ops):
        """
        Currently ops can have references to other ops anywhere in their __dict__, (not just args,
        but the other typical places handled in serialization's `add_edges`). This function
        iterates through an ops __dict__ attributes and tests if any of them are subclasses of
        `Op`.

        This is 'greedier' than the `ordered_ops` method which only traverses the graph using the
        `args` and `control_deps` keys of an ops `__dict__`. In addition, the order of ops
        returned by this method is not guaranteed to be in a valid linear execution ordering.
        """
        op_set = OrderedSet()
        frontier = OrderedSet(ops)

        while frontier:
            op = frontier.pop()
            op_set.add(op)

            for key in op.__dict__:
                val = getattr(op, key)
                if isinstance(val, Op) and val not in op_set:
                    frontier.add(val)
                elif isinstance(val, dict):
                    for subkey in val:
                        if isinstance(val[subkey], Op) and val[subkey] not in op_set:
                            frontier.add(val[subkey])
                elif isinstance(val, (list, tuple, set, OrderedSet)):
                    for item in val:
                        if isinstance(item, Op) and item not in op_set:
                            frontier.add(item)
        return op_set 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:33,代码来源:op_graph.py


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