Ejemplo n.º 1
0
    def test_PushPop(self):
        """Object push and pop"""

        nest.ResetKernel()

        objects = (
            (True, ) * 2,
            (False, ) * 2,

            (1, ) * 2,
            (-100, ) * 2,

            (3.14, ) * 2,
            (-1.7588e11, ) * 2,

            ('string', ) * 2,

            # Literals should be converted to SLI literals
            (nest.SLILiteral('test'), ) * 2,

            # Arrays are converted to tuples on the way out
            ((1, 2, 3, 4, 5), ) * 2,
            ([1, 2, 3, 4, 5], (1, 2, 3, 4, 5)),

            # Dictionary round trip conversion should be consistent
            ({'key': 123, 'sub_dict': {nest.SLILiteral('foo'): 'bar'}}, ) * 2,
        )

        for obj_in, obj_out in objects:
            nest.sps(obj_in)
            self.assertEqual(obj_out, nest.spp())
Ejemplo n.º 2
0
    def test_PushPop_no_NumPy(self):

        nest.ResetKernel()

        a1 = array('i', [1, 2, 3])
        a2 = array('l', [1, 2, 3])
        a3 = array('f', [1.0, 2.0, 3.0])
        a4 = array('d', [1.0, 2.0, 3.0])

        for x in (a1, a2, a3, a4):
            nest.sps(x)
            self.assertEqual(x, nest.spp())
Ejemplo n.º 3
0
    def test_PushPop_no_NumPy(self):

        nest.ResetKernel()

        a1 = array('i', [1, 2, 3])
        a2 = array('l', [1, 2, 3])
        a3 = array('f', [1.0, 2.0, 3.0])
        a4 = array('d', [1.0, 2.0, 3.0])

        for x in (a1, a2, a3, a4):
            nest.sps(x)
            self.assertEqual(x, nest.spp())
Ejemplo n.º 4
0
    def test_Count(self):
        """Object count"""

        nest.ResetKernel()
        nest.sr('clear')

        for i in range(100):
            nest.sps(i)

        nest.sr('count')
        self.assertEqual(nest.spp(), 100)

        for i in range(100):
            self.assertEqual(nest.spp(), (99 - i))

        nest.sr('count')
        self.assertEqual(nest.spp(), 0)
Ejemplo n.º 5
0
    def test_Count(self):
        """Object count"""

        nest.ResetKernel()
        nest.sr('clear')

        for i in range(100):
            nest.sps(i)

        nest.sr('count')
        self.assertEqual(nest.spp(), 100)

        for i in range(100):
            self.assertEqual(nest.spp(), (99 - i))

        nest.sr('count')
        self.assertEqual(nest.spp(), 0)
Ejemplo n.º 6
0
    def test_PushPop(self):
        """Object push and pop"""

        nest.ResetKernel()

        objects = [
            1,  # int
            3.14,  # double
            1e-4,  # double
            -100,  # negative
            'string',  # string
            {
                'key': 123
            },  # dict
            [1, 2, 3, 4, 5],  # list
        ]

        for o in objects:
            nest.sps(o)
            self.assertEqual(o, nest.spp())

        try:
            import numpy
            arr = numpy.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 0]])
            nest.sps(arr[1, :])
            self.assert_((nest.spp() == numpy.array([6, 7, 8, 9, 0])).all())
            nest.sps(arr[:, 1])
            self.assert_((nest.spp() == numpy.array([2, 7])).all())
        except ImportError:
            pass  # numpy's not required for pynest to work
Ejemplo n.º 7
0
    def test_PushPop(self):
        """Object push and pop"""

        nest.ResetKernel()
        
        objects = [ 1,           # int
                    3.14,        # double
                    1e-4,        # double
                    -100,        # negative
                    'string',    # string
                    {'key':123}, # dict
                    [1,2,3,4,5], # list
                    ]

        for o in objects:
            nest.sps(o)
            self.assertEqual(o, nest.spp())

        try:
            import numpy
            arr = numpy.array([[1,2,3,4,5],[6,7,8,9,0]])
            nest.sps(arr[1,:])
            self.assert_( (nest.spp() == numpy.array([6, 7, 8, 9, 0])).all())
            nest.sps(arr[:,1])
            self.assert_( (nest.spp() == numpy.array([2, 7])).all())
        except ImportError:
            pass # numpy's not required for pynest to work
Ejemplo n.º 8
0
    def test_PushPop(self):
        """Object push and pop"""

        nest.ResetKernel()

        objects = (
            (True, ) * 2,
            (False, ) * 2,
            (1, ) * 2,
            (-100, ) * 2,
            (3.14, ) * 2,
            (-1.7588e11, ) * 2,
            ('string', ) * 2,

            # Literals should be converted to SLI literals
            (
                nest.SLILiteral('test'), ) * 2,

            # Arrays are converted to tuples on the way out
            (
                (1, 2, 3, 4, 5), ) * 2,
            ([1, 2, 3, 4, 5], (1, 2, 3, 4, 5)),

            # Dictionary round trip conversion should be consistent
            (
                {
                    'key': 123,
                    'sub_dict': {
                        nest.SLILiteral('foo'): 'bar'
                    }
                }, ) * 2,
        )

        for obj_in, obj_out in objects:
            nest.sps(obj_in)
            self.assertEqual(obj_out, nest.spp())
Ejemplo n.º 9
0
    def test_PushPop_NumPy(self):

        nest.ResetKernel()

        # Test support for slices and strides
        arr = numpy.array(((1, 2, 3, 4, 5), (6, 7, 8, 9, 0)))

        nest.sps(arr[1, :])
        self.assertTrue((nest.spp() == numpy.array((6, 7, 8, 9, 0))).all())

        nest.sps(arr[:, 1])
        self.assertTrue((nest.spp() == numpy.array((2, 7))).all())

        # Test conversion using buffer interface
        nest.sps(array('l', [1, 2, 3]))
        self.assertTrue((nest.spp() == numpy.array((1, 2, 3))).all())

        nest.sps(array('d', [1., 2., 3.]))
        self.assertTrue((nest.spp() == numpy.array((1., 2., 3.))).all())

        # Test conversion without using buffer interface
        if hasattr(numpy, 'int16'):
            i16 = numpy.array((1, 2, 3), dtype=numpy.int16)
            nest.sps(i16)
            self.assertTrue((nest.spp() == i16).all())

        # Test support for scalars and zero-dimensional arrays
        a1 = numpy.array((1, 2, 3))[1]
        a2 = numpy.array((1., 2., 3.))[1]
        a3 = numpy.array(2)
        a4 = numpy.array(2.)

        for x in (a1, a3):
            nest.sps(x)
            self.assertEqual(nest.spp(), 2)

        for x in (a2, a4):
            nest.sps(x)
            self.assertEqual(nest.spp(), 2.)
Ejemplo n.º 10
0
    def test_PushPop_NumPy(self):

        nest.ResetKernel()

        # Test support for slices and strides
        arr = numpy.array(((1, 2, 3, 4, 5), (6, 7, 8, 9, 0)))

        nest.sps(arr[1, :])
        self.assertTrue((nest.spp() == numpy.array((6, 7, 8, 9, 0))).all())

        nest.sps(arr[:, 1])
        self.assertTrue((nest.spp() == numpy.array((2, 7))).all())

        # Test conversion using buffer interface
        nest.sps(array('l', [1, 2, 3]))
        self.assertTrue((nest.spp() == numpy.array((1, 2, 3))).all())

        nest.sps(array('d', [1., 2., 3.]))
        self.assertTrue((nest.spp() == numpy.array((1., 2., 3.))).all())

        # Test conversion without using buffer interface
        if hasattr(numpy, 'int16'):
            i16 = numpy.array((1, 2, 3), dtype=numpy.int16)
            nest.sps(i16)
            self.assertTrue((nest.spp() == i16).all())

        # Test support for scalars and zero-dimensional arrays
        a1 = numpy.array((1, 2, 3))[1]
        a2 = numpy.array((1., 2., 3.))[1]
        a3 = numpy.array(2)
        a4 = numpy.array(2.)

        for x in (a1, a3):
            nest.sps(x)
            self.assertEqual(nest.spp(), 2)

        for x in (a2, a4):
            nest.sps(x)
            self.assertEqual(nest.spp(), 2.)