Exemplo n.º 1
0
    def testSparseDotExecution(self):
        size_executor = Executor(
            sync_provider_type=Executor.SyncProviderType.MOCK)

        a_data = sps.random(5, 9, density=.1)
        b_data = sps.random(9, 10, density=.2)
        a = tensor(a_data, chunk_size=2)
        b = tensor(b_data, chunk_size=3)

        c = dot(a, b)

        size_res = size_executor.execute_tensor(c, mock=True)
        res = self.executor.execute_tensor(c, concat=True)[0]
        self.assertEqual(sum(s[0] for s in size_res), 0)
        self.assertGreaterEqual(sum(s[1] for s in size_res), 0)
        self.assertTrue(issparse(res))
        np.testing.assert_allclose(res.toarray(), a_data.dot(b_data).toarray())

        c2 = dot(a, b, sparse=False)

        size_res = size_executor.execute_tensor(c2, mock=True)
        res = self.executor.execute_tensor(c2, concat=True)[0]
        self.assertEqual(sum(s[0] for s in size_res), c2.nbytes)
        self.assertFalse(issparse(res))
        np.testing.assert_allclose(res, a_data.dot(b_data).toarray())

        c3 = tensordot(a, b.T, (-1, -1), sparse=False)

        res = self.executor.execute_tensor(c3, concat=True)[0]
        self.assertFalse(issparse(res))
        np.testing.assert_allclose(res, a_data.dot(b_data).toarray())

        c = inner(a, b.T)

        res = self.executor.execute_tensor(c, concat=True)[0]
        self.assertTrue(issparse(res))
        np.testing.assert_allclose(res.toarray(), a_data.dot(b_data).toarray())

        c = inner(a, b.T, sparse=False)

        res = self.executor.execute_tensor(c, concat=True)[0]
        self.assertFalse(issparse(res))
        np.testing.assert_allclose(res, a_data.dot(b_data).toarray())

        # test vector inner
        a_data = np.random.rand(5)
        b_data = np.random.rand(5)
        a = tensor(a_data, chunk_size=2).tosparse()
        b = tensor(b_data, chunk_size=2).tosparse()

        c = inner(a, b)

        res = self.executor.execute_tensor(c, concat=True)[0]
        self.assertTrue(np.isscalar(res))
        np.testing.assert_allclose(res, np.inner(a_data, b_data))
Exemplo n.º 2
0
def test_sparse_dot_execution(setup):
    rs = np.random.RandomState(0)

    a_data = sps.random(5, 9, density=.1)
    b_data = sps.random(9, 10, density=.2)
    a = tensor(a_data, chunk_size=2)
    b = tensor(b_data, chunk_size=3)

    c = dot(a, b)

    res = c.execute().fetch()
    assert issparse(res) is True
    np.testing.assert_allclose(res.toarray(), a_data.dot(b_data).toarray())

    c2 = dot(a, b, sparse=False)

    res = c2.execute().fetch()
    assert issparse(res) is False
    np.testing.assert_allclose(res, a_data.dot(b_data).toarray())

    c3 = tensordot(a, b.T, (-1, -1), sparse=False)

    res = c3.execute().fetch()
    assert issparse(res) is False
    np.testing.assert_allclose(res, a_data.dot(b_data).toarray())

    c = inner(a, b.T)

    res = c.execute().fetch()
    assert issparse(res) is True
    np.testing.assert_allclose(res.toarray(), a_data.dot(b_data).toarray())

    c = inner(a, b.T, sparse=False)

    res = c.execute().fetch()
    assert issparse(res) is False
    np.testing.assert_allclose(res, a_data.dot(b_data).toarray())

    # test vector inner
    a_data = rs.rand(5)
    b_data = rs.rand(5)
    a = tensor(a_data, chunk_size=2).tosparse()
    b = tensor(b_data, chunk_size=2).tosparse()

    c = inner(a, b)

    res = c.execute().fetch()
    assert np.isscalar(res) is True
    np.testing.assert_allclose(res, np.inner(a_data, b_data))
Exemplo n.º 3
0
    def testSparseDotExecution(self):
        a_data = sps.random(5, 9, density=.1)
        b_data = sps.random(9, 10, density=.2)
        a = tensor(a_data, chunk_size=2)
        b = tensor(b_data, chunk_size=3)

        c = dot(a, b)

        res = self.executor.execute_tensor(c, concat=True)[0]
        self.assertTrue(issparse(res))
        np.testing.assert_allclose(res.toarray(), a_data.dot(b_data).toarray())

        c2 = dot(a, b, sparse=False)

        res = self.executor.execute_tensor(c2, concat=True)[0]
        self.assertFalse(issparse(res))
        np.testing.assert_allclose(res, a_data.dot(b_data).toarray())

        c3 = tensordot(a, b.T, (-1, -1), sparse=False)

        res = self.executor.execute_tensor(c3, concat=True)[0]
        self.assertFalse(issparse(res))
        np.testing.assert_allclose(res, a_data.dot(b_data).toarray())

        c = inner(a, b.T)

        res = self.executor.execute_tensor(c, concat=True)[0]
        self.assertTrue(issparse(res))
        np.testing.assert_allclose(res.toarray(), a_data.dot(b_data).toarray())

        c = inner(a, b.T, sparse=False)

        res = self.executor.execute_tensor(c, concat=True)[0]
        self.assertFalse(issparse(res))
        np.testing.assert_allclose(res, a_data.dot(b_data).toarray())

        # test vector inner
        a_data = np.random.rand(5)
        b_data = np.random.rand(5)
        a = tensor(a_data, chunk_size=2).tosparse()
        b = tensor(b_data, chunk_size=2).tosparse()

        c = inner(a, b)

        res = self.executor.execute_tensor(c, concat=True)[0]
        self.assertTrue(np.isscalar(res))
        np.testing.assert_allclose(res, np.inner(a_data, b_data))
Exemplo n.º 4
0
 def testCooCreation(self):
     # self.assert(mls.issparse(self.c1))
     # type assertion only. REQUIRE: parameter assertion as well
     s = mls.COONDArray(self.c1)
     assert (isinstance(s, mls.COONDArray))
     assert (isinstance(s, mls.SparseNDArray))
     assert (mls.issparse(s))
     assert (s.issparse())