From 2f95f2f991956abac93cf6b273b1628fbad22f09 Mon Sep 17 00:00:00 2001 From: Christoph Groth Date: Thu, 22 Feb 2018 16:51:29 +0100 Subject: implement evaluation of the interpolated integrand --- vquad/test/test_core.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'vquad/test/test_core.py') diff --git a/vquad/test/test_core.py b/vquad/test/test_core.py index 648a445..46fd823 100644 --- a/vquad/test/test_core.py +++ b/vquad/test/test_core.py @@ -1,10 +1,11 @@ -# Copyright 2017 Christoph Groth (CEA). +# Copyright 2017, 2018 Christoph Groth (CEA). # # This file is part of Vquad. It is subject to the license terms in the file # LICENSE.rst found in the top-level directory of this distribution. import numpy as np from numpy.testing import assert_allclose +from pytest import raises from .. import core @@ -46,7 +47,7 @@ def f_one_with_nan(x): return result -def test_downdate(level=3): +def test_coeffs(level=3): vals = np.abs(core.tbls.nodes[level]) vals[1::2] = np.nan c_downdated = core._calc_coeffs(vals, level) @@ -54,8 +55,10 @@ def test_downdate(level=3): level -= 1 vals = np.abs(core.tbls.nodes[level]) c = core._calc_coeffs(vals, level) + assert_allclose(c_downdated[:len(c)], c, rtol=0, atol=1e-12) - assert_allclose(c_downdated[:len(c)], c, rtol=0, atol=1e-9) + vals_from_c = core._eval_legendre(c, core.tbls.nodes[level]) + assert_allclose(vals_from_c, vals, rtol=0, atol=1e-15) def test_integration(): @@ -90,6 +93,21 @@ def test_integration(): np.seterr(**old_settings) +def test_interpolation(): + vquad = core.Vquad(f24, 0, 3) + vquad.improve_until(1e-6) + + rng = np.random.RandomState(123) + x = np.linspace(0, 3, 100) + rng.shuffle(x) + + for x in [x, 1.23, [[2, 0], [1, 2]], [], [[]]]: + assert_allclose(vquad(x), f24(x)) + + for x in [-1e-100, 3.0001, 1e100, [1, 2, -1e50]]: + raises(ValueError, vquad, x) + + def test_analytic(n=200): def f(x): return f63(x, alpha, beta) -- cgit v1.2.3-74-g4815