Exemplo n.º 1
0
    def test_rsvd_adaptive(self, dtype, shape, q, p):
        X = rand_rank(*shape, 10, dtype=dtype)
        U, s, V = qu.rsvd(X, 1e-5, q=q, p=p, k_start=10)

        k = s.size
        assert 10 <= k <= 20

        assert U.dtype == dtype
        assert V.dtype == dtype

        assert_allclose(U.conj().T @ U, np.eye(k), rtol=1e-6, atol=1e-6)
        assert_allclose(V @ V.conj().T, np.eye(k), rtol=1e-6, atol=1e-6)

        Ue, se, Ve = qu.svds(X, k)
        act_err = qu.norm(X - usv2dense(U, s, V), 'fro')

        assert act_err < 1e-4

        assert_allclose(s[:k // 2], se[:k // 2], rtol=0.1)
Exemplo n.º 2
0
    def test_rsvd(self, dtype, shape, sparse, q, p):
        X = rand_rect(*shape, dtype=dtype, sparse=sparse)

        k = 15
        U, s, V = qu.rsvd(X, k, q=q, p=p)

        assert U.shape == (shape[0], k)
        assert s.shape == (k, )
        assert V.shape == (k, shape[1])

        assert U.dtype == dtype
        assert V.dtype == dtype

        assert_allclose(U.conj().T @ U, np.eye(k), rtol=1e-5, atol=1e-5)
        assert_allclose(V @ V.conj().T, np.eye(k), rtol=1e-5, atol=1e-5)

        Ue, se, Ve = qu.svds(X, k)
        opt_err = qu.norm(X.A - usv2dense(Ue, se, Ve), 'fro')
        act_err = qu.norm(X.A - usv2dense(U, s, V), 'fro')

        assert act_err < 1.2 * opt_err

        assert_allclose(s[:k // 2], se[:k // 2], rtol=0.05)