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


Python NodeIOController.get_node_sink方法代码示例

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


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

示例1: test_passthrough_nodes_with_other_nodes

# 需要导入模块: from nengo_spinnaker.builder.node import NodeIOController [as 别名]
# 或者: from nengo_spinnaker.builder.node.NodeIOController import get_node_sink [as 别名]
    def test_passthrough_nodes_with_other_nodes(self):
        """Test the handling of passthrough when other Nodes are present."""
        with nengo.Network() as net:
            a = nengo.Node(lambda t: t, size_in=0, size_out=1)
            b = nengo.Node(None, size_in=1, label="Passthrough Node")
            c = nengo.Node(lambda t, x: None, size_in=1, size_out=0)

            a_b = nengo.Connection(a, b)
            b_c = nengo.Connection(b, c)

        # Create a model and build the Nodes
        model = Model()
        model.config = net.config
        nioc = NodeIOController()
        nioc.build_node(model, a)
        nioc.build_node(model, b)
        nioc.build_node(model, c)

        # Check the passthrough Node resulted in a new operator but that the
        # others didn't
        assert a not in model.object_operators
        assert b in model.object_operators
        assert c not in model.object_operators

        # Get the source and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_source_for_node") as gssfn:
            spec = nioc.get_node_source(model, b_c)
            assert spec.target.obj is model.object_operators[b]
            assert spec.target.port is OutputPort.standard

        # Get the sink and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_sink_for_node"):
            assert nioc.get_node_sink(model, b_c) is not None
            assert c in nioc._input_nodes

        # Get the sink and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_sink_for_node") as gssfn:
            spec = nioc.get_node_sink(model, a_b)
            assert spec.target.obj is model.object_operators[b]
            assert spec.target.port is InputPort.standard

        # Get the source and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_source_for_node") as gssfn:
            assert nioc.get_node_source(model, a_b) is not None
            assert a in nioc._output_nodes
开发者ID:project-rig,项目名称:nengo_spinnaker,代码行数:47,代码来源:test_node.py

示例2: test_get_node_sink_repeated

# 需要导入模块: from nengo_spinnaker.builder.node import NodeIOController [as 别名]
# 或者: from nengo_spinnaker.builder.node.NodeIOController import get_node_sink [as 别名]
    def test_get_node_sink_repeated(self):
        """Test that calling a NodeIOController to get the sink for a
        connection which terminates at a Node calls the method
        `get_spinnaker_sink_for_node` and creates a new InputNode and adds
        it to the host network.
        """
        with nengo.Network():
            a = nengo.Ensemble(100, 1)
            c = nengo.Ensemble(100, 1)
            b = nengo.Node(lambda t, x: None, size_in=1)
            a_b = nengo.Connection(a, b)
            c_b = nengo.Connection(c, b)

        model = mock.Mock()

        # Create the IO controller
        nioc = NodeIOController()

        # Get the sinks
        with mock.patch.object(nioc, "get_spinnaker_sink_for_node"):
            nioc.get_node_sink(model, a_b)
            nioc.get_node_sink(model, c_b)

        # Check that `a` is in the host_network as is a new InputNode, and a
        # connection between them with a synapse of None.
        assert len(nioc.host_network.all_nodes) == 2
        for node in nioc.host_network.all_nodes:
            if node is not b:
                assert isinstance(node, InputNode)
                assert node.target is b
                in_node = node
            else:
                assert node is b

        # Check that there is ONLY ONE connection from a to the output node
        assert len(nioc.host_network.all_connections) == 1
        for conn in nioc.host_network.all_connections:
            assert conn.pre_obj is in_node
            assert conn.post_obj is b
            assert conn.synapse is None
开发者ID:project-rig,项目名称:nengo_spinnaker,代码行数:42,代码来源:test_node.py

示例3: test_get_source_then_sink_of_node_to_node

# 需要导入模块: from nengo_spinnaker.builder.node import NodeIOController [as 别名]
# 或者: from nengo_spinnaker.builder.node.NodeIOController import get_node_sink [as 别名]
    def test_get_source_then_sink_of_node_to_node(self):
        """Test that getting the source and then the sink of a Node->Node
        connection just adds those items to the host network.
        """
        with nengo.Network():
            a = nengo.Node(lambda t: [t, t], size_in=0, size_out=2)
            b = nengo.Node(lambda t, x: None, size_in=2, size_out=0)
            a_b = nengo.Connection(a, b)

        model = mock.Mock()

        # Create the IO controller
        nioc = NodeIOController()

        # Get the source and then the sink
        with mock.patch.object(nioc, "get_spinnaker_sink_for_node"), \
                mock.patch.object(nioc, "get_spinnaker_source_for_node"):
            nioc.get_node_source(model, a_b)
            nioc.get_node_sink(model, a_b)

        # The host network should contain a, b and a_b and nothing else
        assert nioc.host_network.all_nodes == [a, b]
        assert nioc.host_network.all_connections == [a_b]
开发者ID:project-rig,项目名称:nengo_spinnaker,代码行数:25,代码来源:test_node.py

示例4: test_get_node_sink_standard

# 需要导入模块: from nengo_spinnaker.builder.node import NodeIOController [as 别名]
# 或者: from nengo_spinnaker.builder.node.NodeIOController import get_node_sink [as 别名]
    def test_get_node_sink_standard(self):
        """Test that calling a NodeIOController to get the sink for a
        connection which terminates at a Node calls the method
        `get_spinnaker_sink_for_node` and creates a new InputNode and adds
        it to the host network.
        """
        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Node(lambda t, x: None, size_in=2)
            a_b = nengo.Connection(a, b)

        model = mock.Mock()

        # Create the IO controller
        nioc = NodeIOController()

        # Get the sink
        with mock.patch.object(nioc, "get_spinnaker_sink_for_node") as gssfn:
            spec = gssfn.return_value = mock.Mock(name="spec")
            assert nioc.get_node_sink(model, a_b) is spec

            # Assert this called `get_spinnaker_sink_for_node` correctly
            gssfn.assert_called_once_with(model, a_b)

        # Check that `a` is in the host_network as is a new InputNode, and a
        # connection between them with a synapse of None.
        for node in nioc.host_network.all_nodes:
            if node is not b:
                assert isinstance(node, InputNode)
                assert node.target is b
                in_node = node
            else:
                assert node is b

        # Check that there is a connection from a to the output node
        assert len(nioc.host_network.all_connections) == 1
        conn = nioc.host_network.all_connections[0]
        assert conn.pre_obj is in_node
        assert conn.post_obj is b
        assert conn.synapse is None

        # Check that the Node is included in the Node input dictionary
        assert np.all(nioc.node_input[b] == np.zeros(b.size_in))
开发者ID:project-rig,项目名称:nengo_spinnaker,代码行数:45,代码来源:test_node.py

示例5: test_passthrough_nodes

# 需要导入模块: from nengo_spinnaker.builder.node import NodeIOController [as 别名]
# 或者: from nengo_spinnaker.builder.node.NodeIOController import get_node_sink [as 别名]
    def test_passthrough_nodes(self, width):
        """Test the handling of passthrough Nodes."""
        with nengo.Network() as net:
            a = nengo.Ensemble(100, width)
            b = nengo.Node(None, size_in=width, label="Passthrough Node")
            c = nengo.Ensemble(100, width)

            a_b = nengo.Connection(a, b)
            b_c = nengo.Connection(b, c)

        # Create a model and build the Node
        model = Model()
        model.config = net.config
        nioc = NodeIOController()
        nioc.build_node(model, b)

        # Check the passthrough Node resulted in a new operator
        assert model.object_operators[b].size_in == b.size_in
        assert model.object_operators[b].transmission_delay == 1
        assert model.object_operators[b].interpacket_pause == 1

        # Get the source and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_source_for_node") as gssfn:
            spec = nioc.get_node_source(model, b_c)
            assert spec.target.obj is model.object_operators[b]
            assert spec.target.port is OutputPort.standard

            # Assert this _didn't_ call `get_spinnaker_source_for_node`
            assert not gssfn.called

        # Get the sink and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_sink_for_node") as gssfn:
            spec = nioc.get_node_sink(model, a_b)
            assert spec.target.obj is model.object_operators[b]
            assert spec.target.port is InputPort.standard

            # Assert this _didn't_ call `get_spinnaker_sink_for_node`
            assert not gssfn.called

        # There should be nothing in the host network
        assert nioc.host_network.all_nodes == list()
        assert nioc.host_network.all_connections == list()
开发者ID:pabogdan,项目名称:nengo_spinnaker,代码行数:44,代码来源:test_node.py

示例6: test_get_node_sink_node_to_node

# 需要导入模块: from nengo_spinnaker.builder.node import NodeIOController [as 别名]
# 或者: from nengo_spinnaker.builder.node.NodeIOController import get_node_sink [as 别名]
    def test_get_node_sink_node_to_node(self):
        """Test that calling the NodeIOController with a Node->Node connection
        doesn't ask for a SpiNNaker sink.
        """
        with nengo.Network():
            a = nengo.Node(lambda t: t)
            b = nengo.Node(lambda t, x: None, size_in=1)
            a_b = nengo.Connection(a, b)

        model = mock.Mock()

        # Create the IO controller
        nioc = NodeIOController()

        # Get the source
        with mock.patch.object(nioc, "get_spinnaker_sink_for_node") as gssfn:
            assert nioc.get_node_sink(model, a_b) is None

            # Assert this _didn't_ call `get_spinnaker_source_for_node`
            assert not gssfn.called
开发者ID:project-rig,项目名称:nengo_spinnaker,代码行数:22,代码来源:test_node.py


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