Example #1
0
    def testNanCumReduction(self):
        raw = np.random.randint(5, size=(8, 8, 8))
        raw[:2, 2:4, 4:6] = np.nan

        arr = tensor(raw, chunk_size=3)

        res1 = self.executor.execute_tensor(nancumsum(arr, axis=1),
                                            concat=True)
        res2 = self.executor.execute_tensor(nancumprod(arr, axis=1),
                                            concat=True)
        expected1 = np.nancumsum(raw, axis=1)
        expected2 = np.nancumprod(raw, axis=1)
        np.testing.assert_array_equal(res1[0], expected1)
        np.testing.assert_array_equal(res2[0], expected2)

        raw = sps.random(8, 8, density=.1, format='lil')
        raw[:2, 2:4] = np.nan

        arr = tensor(raw, chunk_size=3)

        res1 = self.executor.execute_tensor(nancumsum(arr, axis=1),
                                            concat=True)[0]
        res2 = self.executor.execute_tensor(nancumprod(arr, axis=1),
                                            concat=True)[0]
        expected1 = np.nancumsum(raw.A, axis=1)
        expected2 = np.nancumprod(raw.A, axis=1)
        self.assertTrue(np.allclose(res1, expected1))
        self.assertTrue(np.allclose(res2, expected2))
Example #2
0
def test_nan_cum_reduction(setup):
    raw = np.random.randint(5, size=(8, 8, 8)).astype(float)
    raw[:2, 2:4, 4:6] = np.nan

    arr = tensor(raw, chunk_size=6)

    res1 = nancumsum(arr, axis=1).execute().fetch()
    res2 = nancumprod(arr, axis=1).execute().fetch()
    expected1 = np.nancumsum(raw, axis=1)
    expected2 = np.nancumprod(raw, axis=1)
    np.testing.assert_array_equal(res1, expected1)
    np.testing.assert_array_equal(res2, expected2)

    raw = sps.random(8, 8, density=.1, format='lil')
    raw[:2, 2:4] = np.nan

    arr = tensor(raw, chunk_size=6)

    res1 = nancumsum(arr, axis=1).execute().fetch()
    res2 = nancumprod(arr, axis=1).execute().fetch()
    expected1 = np.nancumsum(raw.A, axis=1)
    expected2 = np.nancumprod(raw.A, axis=1)
    assert np.allclose(res1, expected1) is True
    assert np.allclose(res2, expected2) is True