def testStdExecution(self): raw1 = np.random.random((20, 25)) raw2 = np.random.randint(10, size=(20, 25)) arr1 = tensor(raw1, chunk_size=3) res1 = self.executor.execute_tensor(arr1.std()) expected1 = raw1.std() self.assertTrue(np.allclose(res1[0], expected1)) res2 = self.executor.execute_tensor(arr1.std(axis=0)) expected2 = raw1.std(axis=0) self.assertTrue(np.allclose(np.concatenate(res2), expected2)) res3 = self.executor.execute_tensor(arr1.std(axis=1, keepdims=True)) expected3 = raw1.std(axis=1, keepdims=True) self.assertTrue(np.allclose(np.concatenate(res3), expected3)) arr2 = tensor(raw2, chunk_size=3) res1 = self.executor.execute_tensor(arr2.std()) expected1 = raw2.std() self.assertAlmostEqual(res1[0], expected1) res2 = self.executor.execute_tensor(arr2.std(axis=0)) expected2 = raw2.std(axis=0) self.assertTrue(np.allclose(np.concatenate(res2), expected2)) res3 = self.executor.execute_tensor(arr2.std(axis=1, keepdims=True)) expected3 = raw2.std(axis=1, keepdims=True) self.assertTrue(np.allclose(np.concatenate(res3), expected3)) res4 = self.executor.execute_tensor(arr2.std(ddof=1)) expected4 = raw2.std(ddof=1) self.assertAlmostEqual(res4[0], expected4) raw1 = sps.random(20, 25, density=.1) arr1 = tensor(raw1, chunk_size=3) res1 = self.executor.execute_tensor(arr1.std()) expected1 = raw1.toarray().std() self.assertTrue(np.allclose(res1[0], expected1)) arr2 = tensor(raw1, chunk_size=30) res1 = self.executor.execute_tensor(arr2.std()) expected1 = raw1.toarray().std() self.assertTrue(np.allclose(res1[0], expected1)) arr = std(1) self.assertEqual(self.executor.execute_tensor(arr)[0], 0)
def test_std_execution(setup): raw1 = np.random.random((20, 25)) raw2 = np.random.randint(10, size=(20, 25)) arr1 = tensor(raw1, chunk_size=6) res1 = arr1.std().execute().fetch() expected1 = raw1.std() np.testing.assert_allclose(res1, expected1) res2 = arr1.std(axis=0).execute().fetch() expected2 = raw1.std(axis=0) np.testing.assert_allclose(res2, expected2) res3 = arr1.std(axis=1, keepdims=True).execute().fetch() expected3 = raw1.std(axis=1, keepdims=True) np.testing.assert_allclose(res3, expected3) arr2 = tensor(raw2, chunk_size=6) res1 = arr2.std().execute().fetch() expected1 = raw2.std() assert pytest.approx(res1) == expected1 res2 = arr2.std(axis=0).execute().fetch() expected2 = raw2.std(axis=0) np.testing.assert_allclose(res2, expected2) res3 = arr2.std(axis=1, keepdims=True).execute().fetch() expected3 = raw2.std(axis=1, keepdims=True) np.testing.assert_allclose(res3, expected3) res4 = arr2.std(ddof=1).execute().fetch() expected4 = raw2.std(ddof=1) assert pytest.approx(res4) == expected4 raw1 = sps.random(20, 25, density=.1) arr1 = tensor(raw1, chunk_size=6) res1 = arr1.std().execute().fetch() expected1 = raw1.toarray().std() np.testing.assert_allclose(res1, expected1) arr2 = tensor(raw1, chunk_size=30) res1 = arr2.std().execute().fetch() expected1 = raw1.toarray().std() np.testing.assert_allclose(res1, expected1) arr = std(1) assert arr.execute().fetch() == 0