def test_return_stats(): A, _ = diagonal(100) evals, evecs, stats = primme.eigsh(A, 3, tol=1e-6, which='LA', return_stats=True, return_history=True) assert(stats["hist"]["numMatvecs"]) svecs_left, svals, svecs_right, stats = primme.svds(A, 3, tol=1e-6, which='SM', return_stats=True, return_history=True) assert(stats["hist"]["numMatvecs"])
eval, evec = primme.eigsh(A, 1, which='LM', convtest=convtest_lm) assert_allclose(eval, [99.], atol=.1) # Sparse singular mass matrix M = scipy.sparse.spdiags(np.asarray(range(99, -1, -1), dtype=np.float32), [0], 100, 100) evals, evecs = primme.eigsh(A, 3, M=M, tol=1e-6, which='SA') assert_allclose(evals, [0. / 99., 1. / 98., 2. / 97.], atol=1e-6 * 100) print(evals) # Sparse rectangular matrix 100x10 with non-zeros on the main diagonal A = scipy.sparse.spdiags(range(10), [0], 100, 10) # Compute the three closest to 4.1 singular values and the left and right corresponding # singular vectors svecs_left, svals, svecs_right = primme.svds(A, 3, tol=1e-6, which=4.1) assert_allclose(sorted(svals), [3., 4., 5.], atol=1e-6 * 10) print(svals) # [ 4., 5., 3.] # Sparse random rectangular matrix 10^5x100 A = scipy.sparse.rand(10000, 100, density=0.001, random_state=10) # Compute the three closest singular values to 6.0 with a tolerance of 1e-6 svecs_left, svals, svecs_right, stats = primme.svds(A, 3, which='SM', tol=1e-6, return_stats=True) A_svals = svals print(svals) print(stats["elapsedTime"], stats["numMatvecs"])