diff --git a/matfree/matfun.py b/matfree/matfun.py index bec7343..6f5bb12 100644 --- a/matfree/matfun.py +++ b/matfree/matfun.py @@ -84,7 +84,12 @@ def _chebyshev_nodes(n, /): def matrix_poly_chebyshev(matfun, order, matvec, /): - """Construct an implementation of matrix-Chebyshev-polynomial interpolation.""" + """Construct an implementation of matrix-Chebyshev-polynomial interpolation. + + This function assumes that the spectrum of the matrix-vector product + is contained in the interval (-1, 1), and that the matrix-function + is analytic on this interval. + """ # Construct nodes nodes = _chebyshev_nodes(order) fx_nodes = matfun(nodes) diff --git a/tests/test_matfun/test_matrix_poly_chebyshev.py b/tests/test_matfun/test_matrix_poly_chebyshev.py index 0430a3f..0918348 100644 --- a/tests/test_matfun/test_matrix_poly_chebyshev.py +++ b/tests/test_matfun/test_matrix_poly_chebyshev.py @@ -1,10 +1,9 @@ """Test matrix-polynomial-vector algorithms via Chebyshev's recursion.""" from matfree import matfun, test_util -from matfree.backend import linalg, np, prng, testing +from matfree.backend import linalg, np, prng -@testing.parametrize("eigvals_range", [(-1, 1), (3, 4)]) -def test_matrix_poly_chebyshev(eigvals_range, n=4): +def test_matrix_poly_chebyshev(n=12): """Test matrix-polynomial-vector algorithms via Chebyshev's recursion.""" # Create a test-problem: matvec, matrix function, # vector, and parameters (a matrix). @@ -19,8 +18,7 @@ def fun(x): v = prng.normal(prng.prng_key(2), shape=(n,)) - eigvals = np.linspace(0, 1, num=n) - eigvals = eigvals_range[0] + eigvals * (eigvals_range[1] - eigvals_range[0]) + eigvals = np.linspace(-1 + 0.01, 1 - 0.01, num=n) matrix = test_util.symmetric_matrix_from_eigenvalues(eigvals) # Compute the solution @@ -35,4 +33,4 @@ def fun(x): # Compute the matrix-function vector product matfun_vec = matfun.matrix_poly_vector_product(algorithm) received = matfun_vec(v, matrix) - assert np.allclose(expected, received) + assert np.allclose(expected, received, rtol=1e-4)