diff --git a/sumpy/p2p.py b/sumpy/p2p.py index 96ae097c8a41d02abd3ddeb81d68f9751520ec03..6899e79512db378cd844d46f55180728a0ef995a 100644 --- a/sumpy/p2p.py +++ b/sumpy/p2p.py @@ -212,7 +212,7 @@ class P2P(P2PBase): def __call__(self, queue, targets, sources, strength, **kwargs): from pytools.obj_array import is_obj_array - knl = self.get_optimized_kernel( + knl = self.get_cached_optimized_kernel( targets_is_obj_array=( is_obj_array(targets) or isinstance(targets, (tuple, list))), sources_is_obj_array=( @@ -225,6 +225,7 @@ class P2P(P2PBase): # {{{ P2P Matrix Writer + class P2PMatrixGenerator(P2PBase): default_name = "p2p_matrix" @@ -248,7 +249,7 @@ class P2PMatrixGenerator(P2PBase): def __call__(self, queue, targets, sources, **kwargs): from pytools.obj_array import is_obj_array - knl = self.get_optimized_kernel( + knl = self.get_cached_optimized_kernel( targets_is_obj_array=( is_obj_array(targets) or isinstance(targets, (tuple, list))), sources_is_obj_array=( @@ -260,6 +261,7 @@ class P2PMatrixGenerator(P2PBase): # {{{ P2P from CSR-like interaction list + class P2PFromCSR(P2PComputationBase): default_name = "p2p_from_csr" diff --git a/test/test_matrixgen.py b/test/test_matrixgen.py index 161ec6f14620ed2c386ae4650d785cf6c5e7b801..592cc0cda7cf8f9a97fd8fa35945e99bb7a753f5 100644 --- a/test/test_matrixgen.py +++ b/test/test_matrixgen.py @@ -22,8 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -import numpy as np import sys +import numpy as np +import numpy.linalg as la import pytest import pyopencl as cl @@ -41,7 +42,7 @@ else: faulthandler.enable() -def create_arguments(n, mode): +def create_arguments(n, mode, target_radius=1.0): # parametrize circle t = np.linspace(0.0, 2.0 * np.pi, n, endpoint=False) unit_circle = np.exp(1j * t) @@ -52,7 +53,7 @@ def create_arguments(n, mode): # create sources and targets h = 2.0 * np.pi / n - targets = unit_circle + targets = target_radius * unit_circle sources = unit_circle radius = 7.0 * h @@ -82,33 +83,22 @@ def test_qbx_direct(ctx_getter): [LineTaylorLocalExpansion(lknl, order)]) lpot = LayerPotential(ctx, [LineTaylorLocalExpansion(lknl, order)]) - from pytools.convergence import EOCRecorder - eocrec = EOCRecorder() - for n in [200, 300, 400]: targets, sources, centers, sigma, expansion_radii = \ create_arguments(n, mode_nr) - eigval = 1.0 / (2.0 * mode_nr) - result_ref = eigval * sigma - h = 2 * np.pi / n strengths = (sigma * h,) _, (mat,) = mat_gen(queue, targets, sources, centers, expansion_radii=expansion_radii) - result_mat = mat @ strengths[0] + result_mat = mat.dot(strengths[0]) _, (result_lpot,) = lpot(queue, targets, sources, centers, strengths, expansion_radii=expansion_radii) - assert np.max(np.abs(result_mat - result_lpot)) < 1.0e-14 - eocrec.add_data_point(h, np.max(np.abs(result_ref - result_lpot))) - - print(eocrec) - - slack = 1.5 - assert eocrec.order_estimate() > order - slack + eps = 1.0e-10 * la.norm(result_lpot) + assert la.norm(result_mat - result_lpot) < eps @pytest.mark.parametrize("exclude_self", [True, False]) @@ -129,14 +119,9 @@ def test_p2p_direct(ctx_getter, exclude_self): mat_gen = P2PMatrixGenerator(ctx, [lknl], exclude_self=exclude_self) lpot = P2P(ctx, [lknl], exclude_self=exclude_self) - from pytools.convergence import EOCRecorder - eocrec = EOCRecorder() - for n in [200, 300, 400]: - targets, sources, _, sigma, _ = create_arguments(n, mode_nr) - - eigval = 1.0 / (2.0 * mode_nr) - result_ref = eigval * sigma + targets, sources, _, sigma, _ = \ + create_arguments(n, mode_nr, target_radius=1.2) h = 2 * np.pi / n strengths = (sigma * h,) @@ -146,17 +131,14 @@ def test_p2p_direct(ctx_getter, exclude_self): extra_kwargs["target_to_source"] = np.arange(n, dtype=np.int32) _, (mat,) = mat_gen(queue, targets, sources, **extra_kwargs) - result_mat = mat @ strengths[0] + result_mat = mat.dot(strengths[0]) _, (result_lpot,) = lpot(queue, targets, sources, strengths, **extra_kwargs) - assert np.max(np.abs(result_mat - result_lpot)) < 1.0e-14 - eocrec.add_data_point(h, np.max(np.abs(result_ref - result_lpot))) - - print(eocrec) + eps = 1.0e-10 * la.norm(result_lpot) + assert la.norm(result_mat - result_lpot) < eps - assert eocrec.order_estimate() > 0.8 # You can test individual routines by typing # $ python test_kernels.py 'test_p2p(cl.create_some_context)'