Exemple #1
0
    def testRepeat(self):
        a = arange(10, chunk_size=2).reshape(2, 5)

        t = repeat(a, 3)
        self.assertEqual(t.shape, (30, ))
        self.assertEqual(calc_shape(t), t.shape)

        t = repeat(a, 3, axis=0)
        self.assertEqual(t.shape, (6, 5))
        self.assertEqual(calc_shape(t), t.shape)

        t = repeat(a, 3, axis=1)
        self.assertEqual(t.shape, (2, 15))
        self.assertEqual(calc_shape(t), t.shape)

        t = repeat(a, [3], axis=1)
        self.assertEqual(t.shape, (2, 15))
        self.assertEqual(calc_shape(t), t.shape)

        t = repeat(a, [3, 4], axis=0)
        self.assertEqual(t.shape, (7, 5))
        self.assertEqual(calc_shape(t), t.shape)

        with self.assertRaises(ValueError):
            repeat(a, [3, 4], axis=1)

        a = tensor(np.random.randn(10), chunk_size=5)

        t = repeat(a, 3)
        t.tiles()
        self.assertEqual(sum(t.nsplits[0]), 30)
        self.assertEqual(calc_shape(t.chunks[0]), t.chunks[0].shape)

        a = tensor(np.random.randn(100), chunk_size=10)

        t = repeat(a, 3)
        t.tiles()
        self.assertEqual(sum(t.nsplits[0]), 300)
        self.assertEqual(calc_shape(t.chunks[0]), t.chunks[0].shape)

        a = tensor(np.random.randn(4))
        b = tensor((4, ))

        t = repeat(a, b)
        self.assertEqual(calc_shape(t), t.shape)
        self.assertEqual(t.rough_shape, (4, ))

        t.tiles()
        self.assertTrue(np.isnan(t.nsplits[0]))
        self.assertEqual(calc_shape(t.chunks[0]), t.chunks[0].shape)
        self.assertEqual(t.chunks[0].rough_shape, (4, ))
Exemple #2
0
    def testRepeat(self):
        a = arange(10, chunks=2).reshape(2, 5)

        t = repeat(a, 3)
        self.assertEqual(t.shape, (30, ))

        t = repeat(a, 3, axis=0)
        self.assertEqual(t.shape, (6, 5))

        t = repeat(a, 3, axis=1)
        self.assertEqual(t.shape, (2, 15))

        t = repeat(a, [3, 4], axis=0)
        self.assertEqual(t.shape, (7, 5))

        with self.assertRaises(ValueError):
            repeat(a, [3, 4], axis=1)

        a = tensor(np.random.randn(10), chunks=5)

        t = repeat(a, 3)
        t.tiles()
        self.assertEqual(sum(t.nsplits[0]), 30)

        a = tensor(np.random.randn(100), chunks=10)

        t = repeat(a, 3)
        t.tiles()
        self.assertEqual(sum(t.nsplits[0]), 300)
Exemple #3
0
    def testRepeatExecution(self):
        a = repeat(3, 4)

        res = self.executor.execute_tensor(a)[0]
        expected = np.repeat(3, 4)
        np.testing.assert_equal(res, expected)

        x_data = np.random.randn(20, 30)
        x = tensor(x_data, chunk_size=(3, 4))

        t = repeat(x, 2)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.repeat(x_data, 2)
        np.testing.assert_equal(res, expected)

        t = repeat(x, 3, axis=1)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.repeat(x_data, 3, axis=1)
        np.testing.assert_equal(res, expected)

        t = repeat(x, np.arange(20), axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.repeat(x_data, np.arange(20), axis=0)
        np.testing.assert_equal(res, expected)

        t = repeat(x, arange(20, chunk_size=5), axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.repeat(x_data, np.arange(20), axis=0)
        np.testing.assert_equal(res, expected)

        x_data = sps.random(20, 30, density=.1)
        x = tensor(x_data, chunk_size=(3, 4))

        t = repeat(x, 2, axis=1)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.repeat(x_data.toarray(), 2, axis=1)
        np.testing.assert_equal(res.toarray(), expected)