示例#1
0
    def test_xbuffer_copy_from(self):
        a = np.array([1., 1.5], dtype=np.float32)
        xb = XBuffer(a)
        b = xb.to_numpy()

        xb.copy_from(xb * np.array([2, -1]))
        assert isinstance(xb, XBuffer)
        np.testing.assert_equal(xb.to_numpy(),
                                np.array([2., -1.5], dtype=np.float32))
        np.testing.assert_equal(a, np.array([1., 1.5], dtype=np.float32))
        np.testing.assert_equal(b, np.array([2., -1.5], dtype=np.float32))
示例#2
0
    def test_xbuffer_operators(self):
        a = np.array([1., 1.5], dtype=np.float32)
        xb = XBuffer(a)

        xb1 = xb + [1, -1]
        assert isinstance(xb1, XBuffer)
        np.testing.assert_equal(xb.to_numpy(), a)
        np.testing.assert_equal(xb1.to_numpy(),
                                np.array([2., .5], dtype=np.float32))
示例#3
0
    def test_xbuffer_arg_name(self):
        def py_func(xb):
            np.testing.assert_equal(xb.to_numpy(),
                                    np.array([1., 2.], dtype=np.float32))
            xb.copy_from(xb * 2)

        xb = XBuffer(np.array([1., 2.], dtype=np.float32))
        of = OpaqueFunc(py_func, [TypeCode.XBuffer])
        of(xb)
        np.testing.assert_equal(xb.to_numpy(),
                                np.array([2., 4.], dtype=np.float32))
示例#4
0
    def test_vector_xbuffer_arg_name(self):
        def py_func(xbuffers):
            assert len(xbuffers) == 2

            np.testing.assert_equal(xbuffers[0].to_numpy(),
                                    np.array([1., 2.], dtype=np.float32))
            xbuffers[0].copy_from(xbuffers[0] * 2)

            np.testing.assert_equal(xbuffers[1].to_numpy(),
                                    np.array([-1., 0.], dtype=np.float32))
            xbuffers[1].copy_from(xbuffers[1] * 2)

        xb1 = XBuffer(np.array([1., 2.], dtype=np.float32))
        xb2 = XBuffer(np.array([-1., 0.], dtype=np.float32))
        of = OpaqueFunc(py_func, [TypeCode.vXBuffer])
        of([xb1, xb2])

        np.testing.assert_equal(xb1.to_numpy(),
                                np.array([2., 4.], dtype=np.float32))
        np.testing.assert_equal(xb2.to_numpy(),
                                np.array([-2., 0.], dtype=np.float32))
示例#5
0
    def test_xbuffer_construction(self):
        a = np.array([1., 1.5], dtype=np.float32)
        xb = XBuffer(a)

        np.testing.assert_equal(xb.to_numpy(), a)