예제 #1
0
    def test_pickle_0(self):
        a = histogram(category(0, 1, 2),
                      integer(0, 20, label='ia'),
                      regular(20, 0.0, 20.0, uoflow=False),
                      variable(0.0, 1.0, 2.0),
                      circular(4, label='pa'))
        for i in range(len(a.axis(0))):
            a.fill(i, 0, 0, 0, 0)
            for j in range(len(a.axis(1))):
                a.fill(i, j, 0, 0, 0)
                for k in range(len(a.axis(2))):
                    a.fill(i, j, k, 0, 0)
                    for l in range(len(a.axis(3))):
                        a.fill(i, j, k, l, 0)
                        for m in range(len(a.axis(4))):
                            a.fill(i, j, k, l, m * 0.5 * pi)

        io = BytesIO()
        pickle.dump(a, io)
        io.seek(0)
        b = pickle.load(io)
        self.assertNotEqual(id(a), id(b))
        self.assertEqual(a.dim, b.dim)
        self.assertEqual(a.axis(0), b.axis(0))
        self.assertEqual(a.axis(1), b.axis(1))
        self.assertEqual(a.axis(2), b.axis(2))
        self.assertEqual(a.axis(3), b.axis(3))
        self.assertEqual(a.axis(4), b.axis(4))
        self.assertEqual(a.sum, b.sum)
        self.assertEqual(a, b)
예제 #2
0
    def test_pickle_1(self):
        a = histogram(category(0, 1, 2),
                       integer(0, 3, label='ia'),
                       regular(4, 0.0, 4.0, uoflow=False),
                       variable(0.0, 1.0, 2.0))
        for i in range(len(a.axis(0))):
            a.fill(i, 0, 0, 0, weight=3)
            for j in range(len(a.axis(1))):
                a.fill(i, j, 0, 0, weight=10)
                for k in range(len(a.axis(2))):
                    a.fill(i, j, k, 0, weight=2)
                    for l in range(len(a.axis(3))):
                        a.fill(i, j, k, l, weight=5)

        io = BytesIO()
        pickle.dump(a, io)
        io.seek(0)
        b = pickle.load(io)
        self.assertNotEqual(id(a), id(b))
        self.assertEqual(a.dim, b.dim)
        self.assertEqual(a.axis(0), b.axis(0))
        self.assertEqual(a.axis(1), b.axis(1))
        self.assertEqual(a.axis(2), b.axis(2))
        self.assertEqual(a.axis(3), b.axis(3))
        self.assertEqual(a.sum, b.sum)
        self.assertEqual(a, b)
예제 #3
0
 def test_getitem(self):
     v = [-0.1, 0.2, 0.3]
     a = variable(*v)
     for i in range(2):
         self.assertEqual(a[i][0], v[i])
         self.assertEqual(a[i][1], v[i+1])
     self.assertEqual(a[-1][0], -float("infinity"))
     self.assertEqual(a[2][1], float("infinity"))
예제 #4
0
 def test_index(self):
     a = variable(-0.1, 0.2, 0.3)
     self.assertEqual(a.index(-10.0), -1)
     self.assertEqual(a.index(-0.11), -1)
     self.assertEqual(a.index(-0.1), 0)
     self.assertEqual(a.index(0.0), 0)
     self.assertEqual(a.index(0.19), 0)
     self.assertEqual(a.index(0.2), 1)
     self.assertEqual(a.index(0.21), 1)
     self.assertEqual(a.index(0.29), 1)
     self.assertEqual(a.index(0.3), 2)
     self.assertEqual(a.index(0.31), 2)
     self.assertEqual(a.index(10), 2)
예제 #5
0
 def test_numpy_conversion_6(self):
     a = integer(0, 2)
     b = regular(2, 0, 2)
     c = variable(0, 1, 2)
     ref = numpy.array((0., 1., 2.))
     self.assertTrue(numpy.all(numpy.array(a) == ref))
     self.assertTrue(numpy.all(numpy.array(b) == ref))
     self.assertTrue(numpy.all(numpy.array(c) == ref))
     d = circular(4)
     ref = numpy.array((0., 0.5*pi, pi, 1.5*pi, 2.0*pi))
     self.assertTrue(numpy.all(numpy.array(d) == ref))
     e = category(1, 2)
     ref = numpy.array((1, 2))
     self.assertTrue(numpy.all(numpy.array(e) == ref))
예제 #6
0
 def test_iter(self):
     v = [-0.1, 0.2, 0.3]
     a = variable(*v)
     self.assertEqual([x[0] for x in a], v[:-1])
     self.assertEqual([x[1] for x in a], v[1:])
예제 #7
0
 def test_len(self):
     self.assertEqual(len(variable(-0.1, 0.2, 0.3)), 2)
예제 #8
0
 def test_init(self):
     variable(0, 1)
     variable(1, -1)
     variable(0, 1, 2, 3, 4)
     variable(0, 1, label="va")
     variable(0, 1, uoflow=True)
     variable(0, 1, label="va", uoflow=True)
     with self.assertRaises(TypeError):
         variable()
     with self.assertRaises(RuntimeError):
         variable(1.0)
     with self.assertRaises(TypeError):
         variable("1", 2)
     with self.assertRaises(KeyError):
         variable(0.0, 1.0, 2.0, bad_keyword="ra")
     a = variable(-0.1, 0.2, 0.3)
     self.assertEqual(a, variable(-0.1, 0.2, 0.3))
     self.assertNotEqual(a, variable(0, 0.2, 0.3))
     self.assertNotEqual(a, variable(-0.1, 0.1, 0.3))
     self.assertNotEqual(a, variable(-0.1, 0.1))