def testLogisticExecution(self): arr = tensor.random.logistic(.5, 1.0, 100, chunk_size=10) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, )) arr = tensor.random.logistic(.5, 1.0, 100, chunk_size=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): np.testing.assert_equal( res, np.random.RandomState(0).logistic(.5, 1.0, 10))
def testZipfExecute(self): arr = tensor.random.zipf(1.1, 100, chunk_size=10) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, )) arr = tensor.random.zipf(1.1, 100, chunk_size=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal(res, np.random.RandomState(0).zipf(1.1, 10)))
def testStandardNormalExecute(self): arr = tensor.random.standard_normal(100, chunks=10) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, )) arr = tensor.random.standard_normal(100, chunks=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal(res, np.random.RandomState(0).standard_normal(10)))
def testRandnExecution(self): arr = tensor.random.randn(10, 20, chunk_size=3) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (10, 20)) arr = tensor.random.randn(10, 20, chunk_size=5).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal(res, np.random.RandomState(0).randn(5, 5)))
def testBetaExecute(self): arr = tensor.random.beta(1, 2, chunk_size=2).tiles() arr.chunks[0].op._state = State(np.random.RandomState(0)) self.assertEqual( self.executor.execute_tensor(arr)[0], np.random.RandomState(0).beta(1, 2)) arr = tensor.random.beta([1, 2], [3, 4], chunk_size=2).tiles() arr.chunks[0].op._state = State(np.random.RandomState(0)) self.assertTrue( np.array_equal( self.executor.execute_tensor(arr)[0], np.random.RandomState(0).beta([1, 2], [3, 4]))) arr = tensor.random.beta([[2, 3]], from_ndarray([[4, 6], [5, 2]], chunk_size=2), chunk_size=1, size=(3, 2, 2)).tiles() for c in arr.chunks: c.op._state = State(np.random.RandomState(0)) res = self.executor.execute_tensor(arr, concat=True)[0] self.assertEqual(res[0, 0, 0], np.random.RandomState(0).beta(2, 4)) self.assertEqual(res[0, 0, 1], np.random.RandomState(0).beta(3, 6)) self.assertEqual(res[0, 1, 0], np.random.RandomState(0).beta(2, 5)) self.assertEqual(res[0, 1, 1], np.random.RandomState(0).beta(3, 2)) arr = tensor.random.RandomState(0).beta([[3, 4]], [[1], [2]], chunk_size=1) tensor.random.seed(0) arr2 = tensor.random.beta([[3, 4]], [[1], [2]], chunk_size=1) self.assertTrue( np.array_equal( self.executor.execute_tensor(arr, concat=True)[0], self.executor.execute_tensor(arr2, concat=True)[0]))
def testLogseriesExecution(self): arr = tensor.random.logseries(.5, 100, chunks=10) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, )) arr = tensor.random.logseries(.5, 100, chunks=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal(res, np.random.RandomState(0).logseries(.5, 10)))
def testRandomIntegersExecution(self): arr = tensor.random.random_integers(0, 10, size=(10, 20), chunk_size=3) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (10, 20)) arr = tensor.random.random_integers(0, 10, size=(10, 20), chunk_size=5).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): np.testing.assert_equal( res, np.random.RandomState(0).random_integers(0, 10, size=(5, 5)))
def testTriangularExecute(self): arr = tensor.random.triangular(.1, .2, .3, 100, chunks=10) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, )) arr = tensor.random.triangular(.1, .2, .3, 100, chunks=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal( res, np.random.RandomState(0).triangular(.1, .2, .3, 10)))
def testNegativeBinomialExecution(self): arr = tensor.random.negative_binomial(5, 1.0, 100, chunks=10) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, )) arr = tensor.random.negative_binomial(5, 1.0, 100, chunks=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal( res, np.random.RandomState(0).negative_binomial(5, 1.0, 10)))
def testDirichletExecute(self): arr = tensor.random.dirichlet((10, 5, 3), 100, chunks=10) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, 3)) arr = tensor.random.dirichlet((10, 5, 3), 100, chunks=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal( res, np.random.RandomState(0).dirichlet((10, 5, 3), 10)))
def testHypergeometricExecution(self): arr = tensor.random.hypergeometric(10, 20, 15, 100, chunk_size=10) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, )) arr = tensor.random.hypergeometric(10, 20, 15, 100, chunk_size=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal( res, np.random.RandomState(0).hypergeometric(10, 20, 15, 10)))
def testNoncentralChisquareExecution(self): arr = tensor.random.noncentral_chisquare(.5, 1.0, 100, chunk_size=10) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, )) arr = tensor.random.noncentral_chisquare(.5, 1.0, 100, chunk_size=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal( res, np.random.RandomState(0).noncentral_chisquare(.5, 1.0, 10)))
def testMultinomialExecution(self): arr = tensor.random.multinomial(10, [.2, .5, .3], 100, chunk_size=10) self.assertEqual(arr.shape, (100, 3)) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, 3)) arr = tensor.random.multinomial(10, [.2, .5, .3], 100, chunk_size=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal( res, np.random.RandomState(0).multinomial(10, [.2, .5, .3], 10)))
def testMultivariateNormalExecution(self): arr = tensor.random.multivariate_normal([1, 2], [[1, 0], [0, 1]], 100, chunk_size=10) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (100, 2)) arr = tensor.random.multivariate_normal([1, 2], [[1, 0], [0, 1]], 100, chunk_size=10).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal( res, np.random.RandomState(0).multivariate_normal( [1, 2], [[1, 0], [0, 1]], 10)))
def testChoiceExecution(self): arr = tensor.random.choice(5, size=3, chunk_size=1) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (3, )) arr = tensor.random.choice(5, size=(15, ), chunk_size=5).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal(res, np.random.RandomState(0).choice(5, size=(5, )))) arr = tensor.random.choice([1, 4, 9], size=3, chunk_size=1) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (3, )) arr = tensor.random.choice([1, 4, 9], size=(15, ), chunk_size=5).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal( res, np.random.RandomState(0).choice([1, 4, 9], size=(5, )))) with self.assertRaises(ValueError): tensor.random.choice([1, 3, 4], size=5, replace=False, chunk_size=2) arr = tensor.random.choice([1, 4, 9], size=3, replace=False, chunk_size=1) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (3, )) arr = tensor.random.choice([1, 4, 9], size=(3, ), replace=False, chunk_size=1).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal( res, np.random.RandomState(0).choice([1, 4, 9], size=(1, ), replace=False))) arr = tensor.random.choice([1, 4, 9], size=3, p=[.2, .5, .3], chunk_size=1) self.assertEqual( self.executor.execute_tensor(arr, concat=True)[0].shape, (3, )) arr = tensor.random.choice([1, 4, 9], size=(15, ), chunk_size=5, p=[.2, .5, .3]).tiles() for chunk in arr.chunks: chunk.op._state = State(np.random.RandomState(0)) for res in self.executor.execute_tensor(arr): self.assertTrue( np.array_equal( res, np.random.RandomState(0).choice([1, 4, 9], size=(5, ), p=[.2, .5, .3])))