示例#1
0
文件: test_base.py 项目: qinxuye/mars
def test_repeat():
    a = arange(10, chunk_size=2).reshape(2, 5)

    t = repeat(a, 3)
    assert t.shape == (30, )

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

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

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

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

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

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

    t = repeat(a, 3)
    t = tile(t)
    assert sum(t.nsplits[0]) == 30

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

    t = repeat(a, 3)
    t = tile(t)
    assert sum(t.nsplits[0]) == 300

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

    t = repeat(a, b)

    t = tile(t)
    assert np.isnan(t.nsplits[0])
示例#2
0
    def testRepeat(self):
        a = arange(10, chunk_size=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], 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), chunk_size=5)

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

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

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

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

        t = repeat(a, b)

        t = t.tiles()
        self.assertTrue(np.isnan(t.nsplits[0]))
示例#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)