Exemplo n.º 1
0
 def testSeededRNG(self):
     N = 100
     seed = 8675309
     numericdtypes = [ak.int64, ak.float64, ak.bool]
     for dt in numericdtypes:
         # Make sure unseeded runs differ
         a = ak.randint(0, 2**32, N, dtype=dt)
         b = ak.randint(0, 2**32, N, dtype=dt)
         self.assertFalse((a == b).all())
         # Make sure seeded results are same
         a = ak.randint(0, 2**32, N, dtype=dt, seed=seed)
         b = ak.randint(0, 2**32, N, dtype=dt, seed=seed)
         self.assertTrue((a == b).all())
     # Uniform
     self.assertFalse((ak.uniform(N) == ak.uniform(N)).all())
     self.assertTrue((ak.uniform(N, seed=seed) == ak.uniform(N, seed=seed)).all())
     # Standard Normal
     self.assertFalse((ak.standard_normal(N) == ak.standard_normal(N)).all())
     self.assertTrue((ak.standard_normal(N, seed=seed) == ak.standard_normal(N, seed=seed)).all())
     # Strings (uniformly distributed length)
     self.assertFalse((ak.random_strings_uniform(1, 10, N) == ak.random_strings_uniform(1, 10, N)).all())
     self.assertTrue((ak.random_strings_uniform(1, 10, N, seed=seed) == ak.random_strings_uniform(1, 10, N, seed=seed)).all())
     # Strings (log-normally distributed length)
     self.assertFalse((ak.random_strings_lognormal(2, 1, N) == ak.random_strings_lognormal(2, 1, N)).all())
     self.assertTrue((ak.random_strings_lognormal(2, 1, N, seed=seed) == ak.random_strings_lognormal(2, 1, N, seed=seed)).all())
Exemplo n.º 2
0
    def test_standard_normal(self):
        pda = ak.standard_normal(100)
        self.assertIsInstance(pda, ak.pdarray)
        self.assertEqual(100, len(pda))
        self.assertEqual(float, pda.dtype)

        pda = ak.standard_normal(np.int64(100))
        self.assertIsInstance(pda, ak.pdarray)
        self.assertEqual(100, len(pda))
        self.assertEqual(float, pda.dtype)

        pda = ak.standard_normal(np.int64(100), np.int64(1))
        self.assertIsInstance(pda, ak.pdarray)
        self.assertEqual(100, len(pda))
        self.assertEqual(float, pda.dtype)

        npda = pda.to_ndarray()
        pda = ak.standard_normal(np.int64(100), np.int64(1))

        self.assertTrue((npda == pda.to_ndarray()).all())

        with self.assertRaises(TypeError) as cm:
            ak.standard_normal('100')
        self.assertEqual(
            'type of argument "size" must be one of (int, int64); got str instead',
            cm.exception.args[0])

        with self.assertRaises(TypeError) as cm:
            ak.standard_normal(100.0)
        self.assertEqual(
            'type of argument "size" must be one of (int, int64); got float instead',
            cm.exception.args[0])

        with self.assertRaises(ValueError) as cm:
            ak.standard_normal(-1)
        self.assertEqual("The size parameter must be > 0",
                         cm.exception.args[0])
Exemplo n.º 3
0
    def test_standard_normal(self):
        pda = ak.standard_normal(100)
        self.assertIsInstance(pda, ak.pdarray)
        self.assertEqual(100,len(pda))
        self.assertEqual(float,pda.dtype)

        with self.assertRaises(TypeError) as cm:          
            ak.standard_normal('100')          
        self.assertEqual('type of argument "size" must be int; got str instead', 
                         cm.exception.args[0]) 
   
        with self.assertRaises(TypeError) as cm:          
            ak.standard_normal(100.0)          
        self.assertEqual('type of argument "size" must be int; got float instead', 
                         cm.exception.args[0])   
    
        with self.assertRaises(ValueError) as cm:          
            ak.standard_normal(-1)          
        self.assertEqual("The size parameter must be > 0", 
                         cm.exception.args[0])