예제 #1
0
    def test_z4_z2_compute_flat(self):
        nblks = 30
        ndim = 5
        sign_array = np.random.randint(0, 2, ndim)
        sign_map = {0: "+", 1: "-"}
        pattern = "".join([sign_map[ix] for ix in sign_array])

        na = np.random.randint(0, 10, nblks * ndim).reshape(nblks, ndim)

        z4lsts = [[Z4(na[nb, nd]) for nd in range(ndim)]
                  for nb in range(nblks)]
        z4arrs = [[z4lsts[nb][nd].to_flat() for nd in range(ndim)]
                  for nb in range(nblks)]
        z4arrs = np.asarray(z4arrs, dtype=int)
        z4out = Z4._compute(pattern, z4arrs)
        z4neg = Z4._compute(pattern, z4arrs, offset=("+", Z4(3)), neg=True)

        z2lsts = [[Z2(na[nb, nd]) for nd in range(ndim)]
                  for nb in range(nblks)]
        z2arrs = [[z2lsts[nb][nd].to_flat() for nd in range(ndim)]
                  for nb in range(nblks)]
        z2arrs = np.asarray(z2arrs, dtype=int)
        z2out = Z2._compute(pattern, z2arrs)
        z2neg = Z2._compute(pattern, z2arrs, offset=("-", Z2(1)), neg=True)

        u1lsts = [[U1(na[nb, nd]) for nd in range(ndim)]
                  for nb in range(nblks)]
        u1arrs = [[u1lsts[nb][nd].to_flat() for nd in range(ndim)]
                  for nb in range(nblks)]
        u1arrs = np.asarray(u1arrs, dtype=int)
        u1out = U1._compute(pattern, u1arrs)
        u1neg = U1._compute(pattern, u1arrs, offset=("-", U1(1)), neg=True)

        for i in range(nblks):
            z4outa = Z4._compute(pattern, z4lsts[i])
            z4outb = Z4.from_flat(z4out[i])
            assert z4outa == z4outb
            assert -(z4outa + Z4(3)) == Z4.from_flat(z4neg[i])

            z2outa = Z2._compute(pattern, z2lsts[i])
            z2outb = Z2.from_flat(z2out[i])
            assert z2outa == z2outb
            assert -(z2outa - Z2(1)) == Z2.from_flat(z2neg[i])

            u1outa = U1._compute(pattern, u1lsts[i])
            u1outb = U1.from_flat(u1out[i])
            assert u1outa == u1outb
            assert -(u1outa - U1(1)) == U1.from_flat(u1neg[i])
예제 #2
0
 def test_z4_z2_u1_flat(self):
     for z in range(-10, 10):
         z4a = Z4(z)
         z4b = Z4.from_flat(z4a.to_flat())
         assert z4a == z4b
         z2a = Z2(z)
         z2b = Z2.from_flat(z2a.to_flat())
         assert z2a == z2b
         u1a = U1(z)
         u1b = U1.from_flat(u1a.to_flat())
         assert u1a == u1b