Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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)))
Exemplo n.º 3
0
    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)))
Exemplo n.º 4
0
    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]))
Exemplo n.º 5
0
    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)))
Exemplo n.º 6
0
    def testNegativeBinomialExecution(self):
        arr = tensor.random.negative_binomial(5, 1.0, 100, chunk_size=10)
        self.assertEqual(
            self.executor.execute_tensor(arr, concat=True)[0].shape, (100, ))

        arr = tensor.random.negative_binomial(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).negative_binomial(5, 1.0, 10)))
Exemplo n.º 7
0
    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)))
Exemplo n.º 8
0
    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)))
Exemplo n.º 9
0
    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)))
Exemplo n.º 10
0
    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)))
Exemplo n.º 11
0
    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])))