def test_unknown_to_x(self):
        # Create the ingoing connection parameters
        in_transmission_params = mock.Mock()
        in_transmission_params.transform = 1.0

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.array([[0.0, 0.0], [0.0, 1.0]]))

        # Combine the parameter sets
        with pytest.raises(NotImplementedError):
            model_utils._combine_transmission_params(in_transmission_params,
                                                     out_transmission_params,
                                                     None)
    def test_x_to_x_optimize_out(self, from_type, final_port):
        # Create the ingoing connection parameters
        in_transmission_params = {
            "ensemble": EnsembleTransmissionParameters(
                            np.random.uniform(size=(100, 1)),
                            np.array([[1.0], [0.0]])
                        ),
            "node": NodeTransmissionParameters(
                        slice(10, 20),
                        mock.Mock(),
                        np.array([[1.0], [0.0]])
                    ),
            "ptn": PassthroughNodeTransmissionParameters(
                       np.array([[1.0], [0.0]])
                   ),
        }[from_type]

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.array([[0.0, 0.0], [0.0, 1.0]])
        )

        # Combine the parameter sets
        new_tps, new_in_port = model_utils._combine_transmission_params(
                in_transmission_params,
                out_transmission_params,
                final_port
            )

        # Check that the connection is optimised out
        assert new_tps is None
        assert new_in_port is None
    def test_node_to_gi(self, passthrough):
        # Create the ingoing connection parameters
        if not passthrough:
            in_transmission_params = NodeTransmissionParameters(
                slice(10, 20),
                mock.Mock(),
                np.ones((100, 1))
            )
        else:
            in_transmission_params = PassthroughNodeTransmissionParameters(
                np.ones((100, 1))
            )

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.eye(100)
        )

        # Combine the parameter sets
        new_tps, new_in_port = model_utils._combine_transmission_params(
                in_transmission_params, out_transmission_params,
                EnsembleInputPort.neurons
            )

        # Check that all the parameters are correct
        if not passthrough:
            assert new_tps.pre_slice == in_transmission_params.pre_slice
            assert new_tps.function is in_transmission_params.function

        assert np.all(new_tps.transform == np.dot(
            out_transmission_params.transform,
            in_transmission_params.transform
        )[0])
        assert new_tps.transform.shape[0] == 1
        assert new_in_port is EnsembleInputPort.global_inhibition
    def test_ens_to_x(self, final_port):
        # Create the ingoing connection parameters
        in_transmission_params = EnsembleTransmissionParameters(
            np.random.uniform(size=(100, 10)), 1.0
        )

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.hstack([np.eye(5), np.zeros((5, 5))])
        )

        # Combine the parameter sets
        new_tps, new_in_port = model_utils._combine_transmission_params(
                in_transmission_params,
                out_transmission_params,
                final_port
            )

        # Check that all the parameters are correct
        assert np.all(new_tps.untransformed_decoders ==
                      in_transmission_params.untransformed_decoders)
        assert np.all(new_tps.transform ==
                      out_transmission_params.transform)
        assert new_tps.decoders.shape == (5, 100)
        assert new_in_port is final_port
    def test_node_to_gi(self, passthrough):
        # Create the ingoing connection parameters
        if not passthrough:
            in_transmission_params = NodeTransmissionParameters(
                slice(10, 20), mock.Mock(), np.ones((100, 1)))
        else:
            in_transmission_params = PassthroughNodeTransmissionParameters(
                np.ones((100, 1)))

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.eye(100))

        # Combine the parameter sets
        new_tps, new_in_port = model_utils._combine_transmission_params(
            in_transmission_params, out_transmission_params,
            EnsembleInputPort.neurons)

        # Check that all the parameters are correct
        if not passthrough:
            assert new_tps.pre_slice == in_transmission_params.pre_slice
            assert new_tps.function is in_transmission_params.function

        assert np.all(
            new_tps.transform == np.dot(out_transmission_params.transform,
                                        in_transmission_params.transform)[0])
        assert new_tps.transform.shape[0] == 1
        assert new_in_port is EnsembleInputPort.global_inhibition
    def test_node_to_x(self, passthrough, final_port):
        # Create the ingoing connection parameters
        if not passthrough:
            in_transmission_params = NodeTransmissionParameters(
                slice(10, 15),
                mock.Mock(),
                np.random.uniform(size=(10, 5)),
            )
        else:
            in_transmission_params = PassthroughNodeTransmissionParameters(
                np.random.uniform(size=(10, 5)), )

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.hstack((np.zeros((5, 5)), np.eye(5))))

        # Combine the parameter sets
        new_tps, new_in_port = model_utils._combine_transmission_params(
            in_transmission_params, out_transmission_params, final_port)

        # Check that all the parameters are correct
        if not passthrough:
            assert new_tps.pre_slice == in_transmission_params.pre_slice
            assert new_tps.function is in_transmission_params.function

        assert np.all(
            new_tps.transform == np.dot(out_transmission_params.transform,
                                        in_transmission_params.transform))
        assert new_tps.transform.shape == (5, 5)
        assert new_in_port is final_port
    def test_x_to_x_optimize_out(self, from_type, final_port):
        # Create the ingoing connection parameters
        in_transmission_params = {
            "ensemble": EnsembleTransmissionParameters(np.dot([[1.0], [0.0]], np.random.uniform(size=(100, 1)).T), None),
            "node": NodeTransmissionParameters(
                        slice(10, 20),
                        mock.Mock(),
                        np.array([[1.0], [0.0]])
                    ),
            "ptn": PassthroughNodeTransmissionParameters(
                       np.array([[1.0], [0.0]])
                   ),
        }[from_type]

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.array([[0.0, 0.0], [0.0, 1.0]])
        )

        # Combine the parameter sets
        new_tps, new_in_port = model_utils._combine_transmission_params(
                in_transmission_params,
                out_transmission_params,
                final_port
            )

        # Check that the connection is optimised out
        assert new_tps is None
        assert new_in_port is None
    def test_unknown_to_x(self):
        # Create the ingoing connection parameters
        in_transmission_params = mock.Mock()
        in_transmission_params.transform = 1.0

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.array([[0.0, 0.0], [0.0, 1.0]])
        )

        # Combine the parameter sets
        with pytest.raises(NotImplementedError):
             model_utils._combine_transmission_params(
                    in_transmission_params,
                    out_transmission_params,
                    None
                )
    def test_ens_to_gi(self):
        # Create the ingoing connection parameters
        in_transmission_params = EnsembleTransmissionParameters(
            np.random.uniform(size=(100, 7)), 1.0)

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.ones((200, 7)))

        # Combine the parameter sets
        new_tps, new_in_port = model_utils._combine_transmission_params(
            in_transmission_params, out_transmission_params,
            EnsembleInputPort.neurons)

        # Check that all the parameters are correct
        assert np.all(new_tps.transform == 1.0)
        assert new_tps.transform.shape == (1, 7)
        assert new_tps.decoders.shape == (1, 100)
        assert new_in_port is EnsembleInputPort.global_inhibition
    def test_ens_to_x(self, final_port):
        # Create the ingoing connection parameters
        in_transmission_params = EnsembleTransmissionParameters(
            np.random.uniform(size=(100, 10)), 1.0)

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.hstack([np.eye(5), np.zeros((5, 5))]))

        # Combine the parameter sets
        new_tps, new_in_port = model_utils._combine_transmission_params(
            in_transmission_params, out_transmission_params, final_port)

        # Check that all the parameters are correct
        assert np.all(new_tps.untransformed_decoders ==
                      in_transmission_params.untransformed_decoders)
        assert np.all(new_tps.transform == out_transmission_params.transform)
        assert new_tps.decoders.shape == (5, 100)
        assert new_in_port is final_port
    def test_ens_to_gi(self):
        # Create the ingoing connection parameters
        in_transmission_params = EnsembleTransmissionParameters(
            np.random.uniform(size=(100, 7)), 1.0
        )

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.ones((200, 7))
        )

        # Combine the parameter sets
        new_tps, new_in_port = model_utils._combine_transmission_params(
                in_transmission_params,
                out_transmission_params,
                EnsembleInputPort.neurons
            )

        # Check that all the parameters are correct
        assert np.all(new_tps.transform == 1.0)
        assert new_tps.transform.shape == (1, 7)
        assert new_tps.decoders.shape == (1, 100)
        assert new_in_port is EnsembleInputPort.global_inhibition
    def test_node_to_x(self, passthrough, final_port):
        # Create the ingoing connection parameters
        if not passthrough:
            in_transmission_params = NodeTransmissionParameters(
                slice(10, 15),
                mock.Mock(),
                np.random.uniform(size=(10, 5)),
            )
        else:
            in_transmission_params = PassthroughNodeTransmissionParameters(
                np.random.uniform(size=(10, 5)),
            )

        # Create the outgoing connection parameters
        out_transmission_params = PassthroughNodeTransmissionParameters(
            np.hstack((np.zeros((5, 5)), np.eye(5)))
        )

        # Combine the parameter sets
        new_tps, new_in_port = model_utils._combine_transmission_params(
                in_transmission_params,
                out_transmission_params,
                final_port
            )

        # Check that all the parameters are correct
        if not passthrough:
            assert new_tps.pre_slice == in_transmission_params.pre_slice
            assert new_tps.function is in_transmission_params.function

        assert np.all(new_tps.transform == np.dot(
            out_transmission_params.transform,
            in_transmission_params.transform
        ))
        assert new_tps.transform.shape == (5, 5)
        assert new_in_port is final_port