def test_uniform(self): testArray = ak.uniform(3) self.assertIsInstance(testArray, ak.pdarray) self.assertEqual(ak.float64, testArray.dtype) self.assertEqual([3], testArray.shape) testArray = ak.uniform(np.int64(3)) self.assertIsInstance(testArray, ak.pdarray) self.assertEqual(ak.float64, testArray.dtype) self.assertEqual([3], testArray.shape) uArray = ak.uniform(size=3, low=0, high=5, seed=0) self.assertTrue((ak.array( [0.30013431967121934, 0.47383036230759112, 1.0441791878997098]) == uArray).all()) uArray = ak.uniform(size=np.int64(3), low=np.int64(0), high=np.int64(5), seed=np.int64(0)) self.assertTrue((ak.array( [0.30013431967121934, 0.47383036230759112, 1.0441791878997098]) == uArray).all()) with self.assertRaises(TypeError): ak.uniform(low='0', high=5, size=100) with self.assertRaises(TypeError): ak.uniform(low=0, high='5', size=100) with self.assertRaises(TypeError): ak.uniform(low=0, high=5, size='100')
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())
def testUniform(self): testArray = ak.uniform(3) self.assertIsInstance(testArray, ak.pdarray) self.assertEqual(ak.float64, testArray.dtype) self.assertEqual([3], testArray.shape) with self.assertRaises(TypeError): ak.uniform(low=5) with self.assertRaises(TypeError) as cm: ak.uniform(low='0', high=5, size=100) self.assertEqual( 'type of argument "low" must be either float or int; got str instead', cm.exception.args[0]) with self.assertRaises(TypeError) as cm: ak.uniform(low=0, high='5', size=100) self.assertEqual( 'type of argument "high" must be either float or int; got str instead', cm.exception.args[0]) with self.assertRaises(TypeError) as cm: ak.uniform(low=0, high=5, size='100') self.assertEqual( 'type of argument "size" must be int; got str instead', cm.exception.args[0])
def test_uniform(self): testArray = ak.uniform(3) self.assertIsInstance(testArray, ak.pdarray) self.assertEqual(ak.float64, testArray.dtype) self.assertEqual([3], testArray.shape) uArray = ak.uniform(size=3, low=0, high=5, seed=0) self.assertTrue((ak.array( [0.30013431967121934, 0.47383036230759112, 1.0441791878997098]) == uArray).all()) with self.assertRaises(TypeError) as cm: ak.uniform(low='0', high=5, size=100) self.assertEqual( 'type of argument "low" must be either float or int; got str instead', cm.exception.args[0]) with self.assertRaises(TypeError) as cm: ak.uniform(low=0, high='5', size=100) self.assertEqual( 'type of argument "high" must be either float or int; got str instead', cm.exception.args[0]) with self.assertRaises(TypeError) as cm: ak.uniform(low=0, high=5, size='100') self.assertEqual( 'type of argument "size" must be int; got str instead', cm.exception.args[0])
def testUniform(self): testArray = ak.uniform(3) self.assertIsInstance(testArray, ak.pdarray) self.assertEqual(ak.float64, testArray.dtype) self.assertEqual([3], testArray.shape) with self.assertRaises(TypeError): ak.uniform(low=5) with self.assertRaises(TypeError) as cm: ak.randint(low='0', high=5, size=100) self.assertEqual("The low parameter must be an integer or float", cm.exception.args[0]) with self.assertRaises(TypeError) as cm: ak.randint(low=0, high='5', size=100) self.assertEqual("The high parameter must be an integer or float", cm.exception.args[0]) with self.assertRaises(TypeError) as cm: ak.randint(low=0, high=5, size='100') self.assertEqual("The size parameter must be an integer", cm.exception.args[0])