Example #1
0
def test_cholesky_execution(setup):
    rs = np.random.RandomState(0)
    data = rs.randint(1, 10, (10, 10))
    symmetric_data = data.dot(data.T)

    a = tensor(symmetric_data, chunk_size=5)

    U = cholesky(a)
    t = U.T.dot(U)

    res_u = U.execute().fetch()
    np.testing.assert_allclose(np.triu(res_u), res_u)

    res = t.execute().fetch()
    np.testing.assert_allclose(res, symmetric_data)

    L = cholesky(a, lower=True)
    U = cholesky(a)
    t = L.dot(U)

    res = t.execute().fetch()
    np.testing.assert_allclose(res, symmetric_data)

    a = tensor(symmetric_data, chunk_size=5)

    L = cholesky(a, lower=True)
    U = cholesky(a)
    t = L.dot(U)

    res_u = U.execute().fetch()
    np.testing.assert_allclose(np.triu(res_u), res_u)

    res = t.execute().fetch()
    np.testing.assert_allclose(res, symmetric_data)

    a = tensor(symmetric_data, chunk_size=(2, 3))

    L = cholesky(a, lower=True)
    U = cholesky(a)
    t = L.dot(U)

    res = t.execute().fetch()
    np.testing.assert_allclose(res, symmetric_data)
Example #2
0
    def testCholeskyExecution(self):
        data = np.random.randint(1, 10, (10, 10))
        symmetric_data = data.dot(data.T)

        a = tensor(symmetric_data, chunk_size=5)

        U = cholesky(a)
        t = U.T.dot(U)

        res_u = self.executor.execute_tensor(U, concat=True)[0]
        np.testing.assert_allclose(np.triu(res_u), res_u)

        res = self.executor.execute_tensor(t, concat=True)[0]
        self.assertTrue(np.allclose(res, symmetric_data))

        L = cholesky(a, lower=True)
        U = cholesky(a)
        t = L.dot(U)

        res = self.executor.execute_tensor(t, concat=True)[0]
        self.assertTrue(np.allclose(res, symmetric_data))

        a = tensor(symmetric_data, chunk_size=2)

        L = cholesky(a, lower=True)
        U = cholesky(a)
        t = L.dot(U)

        res = self.executor.execute_tensor(t, concat=True)[0]
        np.testing.assert_allclose(res, symmetric_data)

        a = tensor(symmetric_data, chunk_size=(1, 2))

        L = cholesky(a, lower=True)
        U = cholesky(a)
        t = L.dot(U)

        res = self.executor.execute_tensor(t, concat=True)[0]
        np.testing.assert_allclose(res, symmetric_data)

        a = tensor(symmetric_data, chunk_size=4)

        L = cholesky(a, lower=True)
        U = cholesky(a)
        t = L.dot(U)

        res_u = self.executor.execute_tensor(U, concat=True)[0]
        np.testing.assert_allclose(np.triu(res_u), res_u)

        res = self.executor.execute_tensor(t, concat=True)[0]
        np.testing.assert_allclose(res, symmetric_data)

        a = tensor(symmetric_data, chunk_size=3)

        L = cholesky(a, lower=True)
        U = cholesky(a)
        t = L.dot(U)

        res_u = self.executor.execute_tensor(U, concat=True)[0]
        np.testing.assert_allclose(np.triu(res_u), res_u)

        res = self.executor.execute_tensor(t, concat=True)[0]
        np.testing.assert_allclose(res, symmetric_data)