Example #1
0
    def test_pack_data(self):
        f = NoneFilter(1, False)

        # Packing into an empty array should be fine because there is nothing
        # to pack
        data = bytearray(0)
        f.pack_data(0.001, data)
Example #2
0
    def test_pack_data(self):
        f = NoneFilter(1, False)

        # Packing into an empty array should be fine because there is nothing
        # to pack
        data = bytearray(0)
        f.pack_data(0.001, data)
Example #3
0
    def test_from_parameters_force_width(self, latching, width):
        # Create the mock signal and connection
        signal = SignalParameters(latching=latching)
        rps = ReceptionParameters(None, width, None)

        # Build the filter
        nf = NoneFilter.from_parameters(signal, rps, width=1)
        assert NoneFilter(1, latching) == nf
Example #4
0
    def test_standard(self, width, latching):
        nf = NoneFilter(width, latching)

        # Pack the filter into some data
        data = bytearray(nf.size)
        nf.pack_into(0.001, data)

        # Check the values are sane
        v1, v2, mask, size = struct.unpack("<4I", data)
        assert v1 == 0
        assert v2 == tp.value_to_fix(1.0)
        assert mask == (0xffffffff if latching else 0x00000000)
        assert size == width
Example #5
0
    def test_forced_filter_width(self):
        """Test construction of filter regions from signals and keyspaces."""
        # Create two keyspaces, two signals and two connections with equivalent
        # synapses.
        # Create two keyspaces, two signals and two reception parameters with
        # different synapses.
        ks_a = mock.Mock(name="Keyspace[A]")
        signal_a = SignalParameters(keyspace=ks_a, latching=False)

        ks_b = mock.Mock(name="Keyspace[B]")
        signal_b = SignalParameters(keyspace=ks_b, latching=False)

        rp_a = ReceptionParameters(nengo.Lowpass(0.01), 3, None)
        rp_b = ReceptionParameters(None, 5, None)

        # Create the type of dictionary that is expected as input
        specs = [
            ReceptionSpec(signal_a, rp_a),
            ReceptionSpec(signal_b, rp_b),
        ]

        # Create the regions, with minimisation
        filter_region, routing_region = make_filter_regions(specs,
                                                            0.001,
                                                            width=1)

        # Check that the filter region is as expected
        for f in filter_region.filters:
            assert (f == LowpassFilter(1, False, 0.01)
                    or f == NoneFilter(1, False))  # noqa: E711
Example #6
0
def test_filter_region_force_width():
    """Test creation of a filter data region."""
    # Create two filters
    fs = [LowpassFilter(5, False, 0.1), NoneFilter(3, False)]

    # Create the filter region
    fr = FilterRegion(fs, dt=0.001)

    # The size should be correct (count of words + header 1 + data 1 + header 2
    # + data 2)
    assert fr.sizeof() == 4 + 16 + 8 + 16 + 0

    # Check that the data is written out correctly
    fp = tempfile.TemporaryFile()
    fr.write_subregion_to_file(fp, filter_width=1)
    fp.seek(0)

    length, = struct.unpack("<I", fp.read(4))
    assert length == len(fs)

    expected_data = bytearray(fr.sizeof() - 4)
    fs[0].pack_into(fr.dt, expected_data, width=1)
    fs[1].pack_into(fr.dt,
                    expected_data, (fs[0].size_words() + 4) * 4,
                    width=1)
    assert fp.read() == expected_data
    def test_from_parameters_force_width(self, latching, width):
        # Create the mock signal and connection
        signal = SignalParameters(latching=latching)
        rps = ReceptionParameters(None, width)

        # Build the filter
        nf = NoneFilter.from_parameters(signal, rps, width=1)
        assert NoneFilter(1, latching) == nf
Example #8
0
    def test_from_signal_and_connection_force_width(self, latching, width):
        # Create the mock signal and connection
        signal = mock.Mock(name="signal", spec_set=["latching"])
        signal.latching = latching

        with nengo.Network():
            a = nengo.Ensemble(100, width)
            b = nengo.Ensemble(100, width)
            connection = nengo.Connection(a, b, synapse=None)

        # Build the filter
        nf = NoneFilter.from_signal_and_connection(signal, connection, width=1)
        assert NoneFilter(1, latching) == nf
Example #9
0
    def test_from_signal_and_connection_to_slice(self, latching):
        # Create the mock signal and connection
        signal = mock.Mock(name="signal", spec_set=["latching"])
        signal.latching = latching

        with nengo.Network():
            a = nengo.Ensemble(100, 2)
            b = nengo.Ensemble(100, 2)
            connection = nengo.Connection(a[1], b[0], synapse=None)

        # Build the filter
        nf = NoneFilter.from_signal_and_connection(signal, connection)
        assert NoneFilter(2, latching) == nf
Example #10
0
    def test_eq(self):
        lpfs = [
            LowpassFilter(5, True, 0.01),
            LowpassFilter(5, True, 0.02),
            LowpassFilter(3, True, 0.01),
            LowpassFilter(5, False, 0.01)
        ]

        for lpf in lpfs[1:]:
            assert lpf != lpfs[0]

        lpf = LowpassFilter(5, True, 0.01)
        assert lpf == lpfs[0]

        nf = NoneFilter(5, True)
        assert lpf != nf and nf != lpf
Example #11
0
    def test_different_filters(self):
        """Test construction of filter regions from signals and keyspaces."""
        # Create two keyspaces, two signals and two reception parameters with
        # different synapses.
        ks_a = mock.Mock(name="Keyspace[A]")
        signal_a = SignalParameters(keyspace=ks_a, latching=False)

        ks_b = mock.Mock(name="Keyspace[B]")
        signal_b = SignalParameters(keyspace=ks_b, latching=False)

        rp_a = ReceptionParameters(nengo.Lowpass(0.01), 3, None)
        rp_b = ReceptionParameters(None, 3, None)

        # Create the type of dictionary that is expected as input
        specs = [
            ReceptionSpec(signal_a, rp_a),
            ReceptionSpec(signal_b, rp_b),
        ]

        # Create the regions, with minimisation
        filter_region, routing_region = make_filter_regions(
            specs,
            0.001,
            minimise=True,  # Shouldn't achieve anything
            filter_routing_tag="spam",
            index_field="eggs")

        # Check that the filter region is as expected
        assert filter_region.dt == 0.001
        assert len(filter_region.filters) == 2

        for f in filter_region.filters:
            assert (f == LowpassFilter(3, False, 0.01)
                    or f == NoneFilter(3, False))  # noqa: E711

        # Check that the routing region is as expected
        assert routing_region.filter_routing_tag == "spam"

        assert routing_region.index_field == "eggs"
        if (signal_a, 0) in routing_region.signal_routes:
            assert (signal_b, 1) in routing_region.signal_routes
        else:
            assert (signal_b, 0) in routing_region.signal_routes
Example #12
0
 def test_size_words(self):
     f = NoneFilter(1, False)
     assert f.size_words() == 0
Example #13
0
 def test_size_words(self):
     f = NoneFilter(1, False)
     assert f.size_words() == 0