def testStackExecution(self): raw = [np.random.randn(3, 4) for _ in range(10)] arrs = [tensor(a, chunk_size=3) for a in raw] arr2 = stack(arrs) res = self.executor.execute_tensor(arr2, concat=True) self.assertTrue(np.array_equal(res[0], np.stack(raw))) arr3 = stack(arrs, axis=1) res = self.executor.execute_tensor(arr3, concat=True) self.assertTrue(np.array_equal(res[0], np.stack(raw, axis=1))) arr4 = stack(arrs, axis=2) res = self.executor.execute_tensor(arr4, concat=True) self.assertTrue(np.array_equal(res[0], np.stack(raw, axis=2)))
def testCovExecution(self): data = np.array([[0, 2], [1, 1], [2, 0]]).T x = tensor(data, chunk_size=1) t = cov(x) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.cov(data) np.testing.assert_equal(res, expected) data_x = [-2.1, -1, 4.3] data_y = [3, 1.1, 0.12] x = tensor(data_x, chunk_size=1) y = tensor(data_y, chunk_size=1) X = stack((x, y), axis=0) t = cov(x, y) r = tall(t == cov(X)) self.assertTrue(self.executor.execute_tensor(r)[0])
def testStack(self): raw_arrs = [ones((3, 4), chunk_size=2) for _ in range(10)] arr2 = stack(raw_arrs, axis=0) self.assertEqual(arr2.shape, (10, 3, 4)) self.assertEqual(calc_shape(arr2), arr2.shape) arr2.tiles() self.assertEqual(arr2.nsplits, ((1, ) * 10, (2, 1), (2, 2))) self.assertEqual(calc_shape(arr2.chunks[0]), arr2.chunks[0].shape) arr3 = stack(raw_arrs, axis=1) self.assertEqual(arr3.shape, (3, 10, 4)) self.assertEqual(calc_shape(arr3), arr3.shape) arr3.tiles() self.assertEqual(arr3.nsplits, ((2, 1), (1, ) * 10, (2, 2))) self.assertEqual(calc_shape(arr3.chunks[0]), arr3.chunks[0].shape) arr4 = stack(raw_arrs, axis=2) self.assertEqual(calc_shape(arr4), arr4.shape) self.assertEqual(arr4.shape, (3, 4, 10)) arr4.tiles() self.assertEqual(arr4.nsplits, ((2, 1), (2, 2), (1, ) * 10)) self.assertEqual(calc_shape(arr4.chunks[0]), arr4.chunks[0].shape) with self.assertRaises(ValueError): raw_arrs2 = [ ones((3, 4), chunk_size=2), ones((4, 3), chunk_size=2) ] stack(raw_arrs2) with self.assertRaises(np.AxisError): stack(raw_arrs, axis=3) arr5 = stack(raw_arrs, -1).tiles() self.assertEqual(arr5.nsplits, ((2, 1), (2, 2), (1, ) * 10)) arr6 = stack(raw_arrs, -3).tiles() self.assertEqual(arr6.nsplits, ((1, ) * 10, (2, 1), (2, 2))) with self.assertRaises(np.AxisError): stack(raw_arrs, axis=-4)