extmath_test.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:mpnum 作者: dseuss 项目源码 文件源码
def test_randomized_svd(rows, cols, rank, dtype, transpose, n_iter, target_gen,
                        rgen):
    rank = min(rows, cols) - 2 if rank is 'fullrank' else rank
    A = target_gen(rows, cols, rank=rank, randstate=rgen, dtype=dtype)

    U_ref, s_ref, V_ref = utils.truncated_svd(A, k=rank)
    U, s, V = em.randomized_svd(A, rank, transpose=transpose, randstate=rgen,
                                n_iter=n_iter)

    error_U = np.abs(U.conj().T.dot(U_ref)) - np.eye(rank)
    assert_allclose(np.linalg.norm(error_U), 0, atol=1e-3)
    error_V = np.abs(V.dot(V_ref.conj().T)) - np.eye(rank)
    assert_allclose(np.linalg.norm(error_V), 0, atol=1e-3)
    assert_allclose(s.ravel() - s_ref, 0, atol=1e-3)
    # Check that singular values are returned in descending order
    assert_array_equal(s, np.sort(s)[::-1])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号