Example #1
0
    def testMeanExecution(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.mean())
        expected1 = raw1.mean()
        self.assertTrue(np.allclose(res1[0], expected1))

        res2 = self.executor.execute_tensor(arr1.mean(axis=0))
        expected2 = raw1.mean(axis=0)
        self.assertTrue(np.allclose(np.concatenate(res2), expected2))

        res3 = self.executor.execute_tensor(arr1.mean(axis=1, keepdims=True))
        expected3 = raw1.mean(axis=1, keepdims=True)
        self.assertTrue(np.allclose(np.concatenate(res3), expected3))

        arr2 = tensor(raw2, chunk_size=3)

        res1 = self.executor.execute_tensor(arr2.mean())
        expected1 = raw2.mean()
        self.assertEqual(res1[0], expected1)

        res2 = self.executor.execute_tensor(arr2.mean(axis=0))
        expected2 = raw2.mean(axis=0)
        self.assertTrue(np.allclose(np.concatenate(res2), expected2))

        res3 = self.executor.execute_tensor(arr2.mean(axis=1, keepdims=True))
        expected3 = raw2.mean(axis=1, keepdims=True)
        self.assertTrue(np.allclose(np.concatenate(res3), expected3))

        raw1 = sps.random(20, 25, density=.1)

        arr1 = tensor(raw1, chunk_size=3)

        res1 = self.executor.execute_tensor(arr1.mean())
        expected1 = raw1.mean()
        self.assertTrue(np.allclose(res1[0], expected1))

        arr2 = tensor(raw1, chunk_size=30)

        res1 = self.executor.execute_tensor(arr2.mean())
        expected1 = raw1.mean()
        self.assertTrue(np.allclose(res1[0], expected1))

        arr = mean(1)
        self.assertEqual(self.executor.execute_tensor(arr)[0], 1)

        with self.assertRaises(TypeError):
            self.executor.execute_tensor(tensor(list('abcdefghi'), dtype=object).mean())
Example #2
0
def test_mean_execution(setup):
    raw1 = np.random.random((20, 25))
    raw2 = np.random.randint(10, size=(20, 25))

    arr1 = tensor(raw1, chunk_size=6)

    res1 = arr1.mean().execute().fetch()
    expected1 = raw1.mean()
    np.testing.assert_allclose(res1, expected1)

    res2 = arr1.mean(axis=0).execute().fetch()
    expected2 = raw1.mean(axis=0)
    assert np.allclose(res2, expected2) is True

    res3 = arr1.mean(axis=1, keepdims=True).execute().fetch()
    expected3 = raw1.mean(axis=1, keepdims=True)
    np.testing.assert_allclose(res3, expected3)

    arr2 = tensor(raw2, chunk_size=6)

    res1 = arr2.mean().execute().fetch()
    expected1 = raw2.mean()
    assert res1 == expected1

    res2 = arr2.mean(axis=0).execute().fetch()
    expected2 = raw2.mean(axis=0)
    np.testing.assert_allclose(res2, expected2)

    res3 = arr2.mean(axis=1, keepdims=True).execute().fetch()
    expected3 = raw2.mean(axis=1, keepdims=True)
    np.testing.assert_allclose(res3, expected3)

    raw1 = sps.random(20, 25, density=.1)

    arr1 = tensor(raw1, chunk_size=6)

    res1 = arr1.mean().execute().fetch()
    expected1 = raw1.mean()
    np.testing.assert_allclose(res1, expected1)

    arr2 = tensor(raw1, chunk_size=30)

    res1 = arr2.mean().execute().fetch()
    expected1 = raw1.mean()
    np.testing.assert_allclose(res1, expected1)

    arr = mean(1)
    assert arr.execute().fetch() == 1

    with pytest.raises(TypeError):
        tensor(list('abcdefghi'), dtype=object).mean().execute()