Example #1
0
def test_count_nonzero_execution(setup):
    raw = [[0, 1, 7, 0, 0], [3, 0, 0, 2, 19]]

    arr = tensor(raw, chunk_size=5)
    t = count_nonzero(arr)

    res = t.execute().fetch()
    expected = np.count_nonzero(raw)
    np.testing.assert_equal(res, expected)

    arr = tensor(raw, chunk_size=2)
    t = count_nonzero(arr)

    res = t.execute().fetch()
    expected = np.count_nonzero(raw)
    np.testing.assert_equal(res, expected)

    t = count_nonzero(arr, axis=0)

    res = t.execute().fetch()
    expected = np.count_nonzero(raw, axis=0)
    np.testing.assert_equal(res, expected)

    t = count_nonzero(arr, axis=1)

    res = t.execute().fetch()
    expected = np.count_nonzero(raw, axis=1)
    np.testing.assert_equal(res, expected)

    raw = sps.csr_matrix(raw)

    arr = tensor(raw, chunk_size=2)
    t = count_nonzero(arr)

    res = t.execute().fetch()
    expected = np.count_nonzero(raw.A)
    np.testing.assert_equal(res, expected)

    t = count_nonzero(arr, axis=0)

    res = t.execute().fetch()
    expected = np.count_nonzero(raw.A, axis=0)
    np.testing.assert_equal(res, expected)

    t = count_nonzero(arr, axis=1)

    res = t.execute().fetch()
    expected = np.count_nonzero(raw.A, axis=1)
    np.testing.assert_equal(res, expected)

    # test string dtype
    a = tensor(list('abcdefghi'), dtype=object)
    assert count_nonzero(a).execute().fetch() == 9
    a = tensor(list('abcdefghi'), dtype=object, chunk_size=2)
    assert count_nonzero(a).execute().fetch() == 9
Example #2
0
    def testCountNonzeroExecution(self):
        raw = [[0, 1, 7, 0, 0], [3, 0, 0, 2, 19]]

        arr = tensor(raw, chunk_size=5)
        t = count_nonzero(arr)

        res = self.executor.execute_tensor(t)[0]
        expected = np.count_nonzero(raw)
        np.testing.assert_equal(res, expected)

        arr = tensor(raw, chunk_size=2)
        t = count_nonzero(arr)

        res = self.executor.execute_tensor(t)[0]
        expected = np.count_nonzero(raw)
        np.testing.assert_equal(res, expected)

        t = count_nonzero(arr, axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.count_nonzero(raw, axis=0)
        np.testing.assert_equal(res, expected)

        t = count_nonzero(arr, axis=1)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.count_nonzero(raw, axis=1)
        np.testing.assert_equal(res, expected)

        raw = sps.csr_matrix(raw)

        arr = tensor(raw, chunk_size=2)
        t = count_nonzero(arr)

        res = self.executor.execute_tensor(t)[0]
        expected = np.count_nonzero(raw.A)
        np.testing.assert_equal(res, expected)

        t = count_nonzero(arr, axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.count_nonzero(raw.A, axis=0)
        np.testing.assert_equal(res, expected)

        t = count_nonzero(arr, axis=1)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.count_nonzero(raw.A, axis=1)
        np.testing.assert_equal(res, expected)

        # test string dtype
        a = tensor(list('abcdefghi'), dtype=object)
        self.assertEqual(self.executor.execute_tensor(count_nonzero(a), concat=True)[0], 9)
        a = tensor(list('abcdefghi'), dtype=object, chunk_size=2)
        self.assertEqual(self.executor.execute_tensor(count_nonzero(a), concat=True)[0], 9)
Example #3
0
    def testCountNonzeroExecution(self):
        raw = [[0, 1, 7, 0, 0], [3, 0, 0, 2, 19]]

        arr = tensor(raw, chunk_size=5)
        t = count_nonzero(arr)

        res = self.executor.execute_tensor(t)[0]
        expected = np.count_nonzero(raw)
        np.testing.assert_equal(res, expected)

        arr = tensor(raw, chunk_size=2)
        t = count_nonzero(arr)

        res = self.executor.execute_tensor(t)[0]
        expected = np.count_nonzero(raw)
        np.testing.assert_equal(res, expected)

        t = count_nonzero(arr, axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.count_nonzero(raw, axis=0)
        np.testing.assert_equal(res, expected)

        t = count_nonzero(arr, axis=1)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.count_nonzero(raw, axis=1)
        np.testing.assert_equal(res, expected)

        raw = sps.csr_matrix(raw)

        arr = tensor(raw, chunk_size=2)
        t = count_nonzero(arr)

        res = self.executor.execute_tensor(t)[0]
        expected = np.count_nonzero(raw.A)
        np.testing.assert_equal(res, expected)

        t = count_nonzero(arr, axis=0)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.count_nonzero(raw.A, axis=0)
        np.testing.assert_equal(res, expected)

        t = count_nonzero(arr, axis=1)

        res = self.executor.execute_tensor(t, concat=True)[0]
        expected = np.count_nonzero(raw.A, axis=1)
        np.testing.assert_equal(res, expected)