diff --git a/.gitignore b/.gitignore index 5c3e32eb..92fcfa51 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,6 @@ mpmath.egg-info/ # Coverage-related files .coverage htmlcov/ + +# Visual Studio files +.vs/ \ No newline at end of file diff --git a/README.rst b/README.rst index 725ed018..4db5f933 100644 --- a/README.rst +++ b/README.rst @@ -138,7 +138,7 @@ See the main documentation for more detailed instructions. The unit tests in mpmath/tests/ can be run via the script runtests.py, but it is recommended to run them with py.test -(http://codespeak.net/py/dist/index.html), especially +(https://pytest.org/), especially to generate more useful reports in case there are failures. You may also want to check out the demo scripts in the demo diff --git a/doc/source/setup.txt b/doc/source/setup.txt index 3e1a7e17..516f1a41 100644 --- a/doc/source/setup.txt +++ b/doc/source/setup.txt @@ -36,6 +36,7 @@ or If you have an old version of mpmath installed already, you may have to pass ``easy_install`` the ``-U`` flag to force an upgrade. +If installation fails, try deleting the following folders: .eggs, mpmath.egg-info, dist, build Debian/Ubuntu ............. diff --git a/mpmath/calculus/quadrature.py b/mpmath/calculus/quadrature.py index 4751b407..3cdd76e3 100644 --- a/mpmath/calculus/quadrature.py +++ b/mpmath/calculus/quadrature.py @@ -211,7 +211,7 @@ class QuadratureRule(object): the standard interval and then calls :func:`~mpmath.sum_next`. """ ctx = self.ctx - I = err = ctx.zero + I = total_err = ctx.zero for i in xrange(len(points)-1): a, b = points[i], points[i+1] if a == b: @@ -224,23 +224,26 @@ class QuadratureRule(object): f = lambda x: _f(-x) + _f(x) a, b = (ctx.zero, ctx.inf) results = [] + err = ctx.zero for degree in xrange(1, max_degree+1): nodes = self.get_nodes(a, b, degree, prec, verbose) if verbose: print("Integrating from %s to %s (degree %s of %s)" % \ (ctx.nstr(a), ctx.nstr(b), degree, max_degree)) - results.append(self.sum_next(f, nodes, degree, prec, results, verbose)) + result = self.sum_next(f, nodes, degree, prec, results, verbose) + results.append(result) if degree > 1: err = self.estimate_error(results, prec, epsilon) + if verbose: + print("Estimated error:", ctx.nstr(err), " epsilon:", ctx.nstr(epsilon), " result: ", ctx.nstr(result)) if err <= epsilon: break - if verbose: - print("Estimated error:", ctx.nstr(err)) I += results[-1] - if err > epsilon: + total_err += err + if total_err > epsilon: if verbose: - print("Failed to reach full accuracy. Estimated error:", ctx.nstr(err)) - return I, err + print("Failed to reach full accuracy. Estimated error:", ctx.nstr(total_err)) + return I, total_err def sum_next(self, f, nodes, degree, prec, previous, verbose=False): r""" diff --git a/mpmath/tests/test_quad.py b/mpmath/tests/test_quad.py index 3efd254b..fc71c5f5 100644 --- a/mpmath/tests/test_quad.py +++ b/mpmath/tests/test_quad.py @@ -19,6 +19,10 @@ def test_basic_integrals(): assert ae(quadts(lambda x: 2*sqrt(1-x*x), [-1, 1]), pi) mp.dps = 15 +def test_multiple_intervals(): + y,err = quad(lambda x: sign(x), [-0.5, 0.9, 1], maxdegree=2, error=True) + assert abs(y-0.5) < 2*err + def test_quad_symmetry(): assert quadts(sin, [-1, 1]) == 0 assert quadgl(sin, [-1, 1]) == 0 diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..95697f21 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +markers = + slow: marks tests as slow (deselect with '-m "not slow"') \ No newline at end of file