def testAverageExecution(self): data = arange(1, 5, chunk_size=1) t = average(data) res = self.executor.execute_tensor(t)[0] expected = np.average(np.arange(1, 5)) self.assertEqual(res, expected) t = average(arange(1, 11, chunk_size=2), weights=arange(10, 0, -1, chunk_size=2)) res = self.executor.execute_tensor(t)[0] expected = np.average(range(1, 11), weights=range(10, 0, -1)) self.assertEqual(res, expected) data = arange(6, chunk_size=2).reshape((3, 2)) t = average(data, axis=1, weights=tensor([1. / 4, 3. / 4], chunk_size=2)) res = self.executor.execute_tensor(t, concat=True)[0] expected = np.average(np.arange(6).reshape(3, 2), axis=1, weights=(1. / 4, 3. / 4)) np.testing.assert_equal(res, expected) with self.assertRaises(TypeError): average(data, weights=tensor([1. / 4, 3. / 4], chunk_size=2))
def test_average_execution(setup): data = arange(1, 5, chunk_size=1) t = average(data) res = t.execute().fetch() expected = np.average(np.arange(1, 5)) assert res == expected t = average(arange(1, 11, chunk_size=2), weights=arange(10, 0, -1, chunk_size=2)) res = t.execute().fetch() expected = np.average(range(1, 11), weights=range(10, 0, -1)) assert res == expected data = arange(6, chunk_size=2).reshape((3, 2)) t = average(data, axis=1, weights=tensor([1. / 4, 3. / 4], chunk_size=2)) res = t.execute().fetch() expected = np.average(np.arange(6).reshape(3, 2), axis=1, weights=(1. / 4, 3. / 4)) np.testing.assert_equal(res, expected) with pytest.raises(TypeError): average(data, weights=tensor([1. / 4, 3. / 4], chunk_size=2))