def testSplit(self): a = arange(9, chunk_size=2) splits = split(a, 3) self.assertEqual(len(splits), 3) self.assertTrue(all(s.shape == (3, ) for s in splits)) splits[0].tiles() self.assertEqual(splits[0].nsplits, ((2, 1), )) self.assertEqual(splits[1].nsplits, ((1, 2), )) self.assertEqual(splits[2].nsplits, ((2, 1), )) a = arange(8, chunk_size=2) splits = split(a, [3, 5, 6, 10]) self.assertEqual(len(splits), 5) self.assertEqual(splits[0].shape, (3, )) self.assertEqual(splits[1].shape, (2, )) self.assertEqual(splits[2].shape, (1, )) self.assertEqual(splits[3].shape, (2, )) self.assertEqual(splits[4].shape, (0, )) splits[0].tiles() self.assertEqual(splits[0].nsplits, ((2, 1), )) self.assertEqual(splits[1].nsplits, ((1, 1), )) self.assertEqual(splits[2].nsplits, ((1, ), )) self.assertEqual(splits[3].nsplits, ((2, ), )) self.assertEqual(splits[4].nsplits, ((0, ), ))
def testSplitExecution(self): x = arange(48, chunk_size=3).reshape(2, 3, 8) ss = split(x, 4, axis=2) res = [self.executor.execute_tensor(i, concat=True)[0] for i in ss] expected = np.split(np.arange(48).reshape(2, 3, 8), 4, axis=2) self.assertEqual(len(res), len(expected)) [np.testing.assert_equal(r, e) for r, e in zip(res, expected)] ss = split(x, [3, 5, 6, 10], axis=2) res = [self.executor.execute_tensor(i, concat=True)[0] for i in ss] expected = np.split(np.arange(48).reshape(2, 3, 8), [3, 5, 6, 10], axis=2) self.assertEqual(len(res), len(expected)) [np.testing.assert_equal(r, e) for r, e in zip(res, expected)] # hsplit x = arange(120, chunk_size=3).reshape(2, 12, 5) ss = hsplit(x, 4) res = [self.executor.execute_tensor(i, concat=True)[0] for i in ss] expected = np.hsplit(np.arange(120).reshape(2, 12, 5), 4) self.assertEqual(len(res), len(expected)) [np.testing.assert_equal(r, e) for r, e in zip(res, expected)] # vsplit x = arange(48, chunk_size=3).reshape(8, 3, 2) ss = vsplit(x, 4) res = [self.executor.execute_tensor(i, concat=True)[0] for i in ss] expected = np.vsplit(np.arange(48).reshape(8, 3, 2), 4) self.assertEqual(len(res), len(expected)) [np.testing.assert_equal(r, e) for r, e in zip(res, expected)] # dsplit x = arange(48, chunk_size=3).reshape(2, 3, 8) ss = dsplit(x, 4) res = [self.executor.execute_tensor(i, concat=True)[0] for i in ss] expected = np.dsplit(np.arange(48).reshape(2, 3, 8), 4) self.assertEqual(len(res), len(expected)) [np.testing.assert_equal(r, e) for r, e in zip(res, expected)] x_data = sps.random(12, 8, density=.1) x = tensor(x_data, chunk_size=3) ss = split(x, 4, axis=0) res = [self.executor.execute_tensor(i, concat=True)[0] for i in ss] expected = np.split(x_data.toarray(), 4, axis=0) self.assertEqual(len(res), len(expected)) [ np.testing.assert_equal(r.toarray(), e) for r, e in zip(res, expected) ]