|
26 | 26 | import logging |
27 | 27 | import sys |
28 | 28 | from functools import partial |
| 29 | +from typing import TYPE_CHECKING |
29 | 30 |
|
30 | 31 | import numpy as np |
31 | 32 | import numpy.linalg as la |
|
36 | 37 | PyOpenCLArrayContext, |
37 | 38 | pytest_generate_tests_for_array_contexts, |
38 | 39 | ) |
39 | | -from pytools import obj_array |
| 40 | +from pytools import memoize_on_first_arg, obj_array |
40 | 41 | from pytools.convergence import PConvergenceVerifier |
41 | 42 |
|
42 | 43 | import sumpy.symbolic as sym |
|
62 | 63 | AxisTargetDerivative, |
63 | 64 | BiharmonicKernel, |
64 | 65 | DirectionalSourceDerivative, |
| 66 | + ElasticityKernel, |
65 | 67 | HelmholtzKernel, |
66 | 68 | Kernel, |
67 | 69 | LaplaceKernel, |
| 70 | + LineOfCompressionKernel, |
| 71 | + OneKernel, |
68 | 72 | StokesletKernel, |
| 73 | + StressletKernel, |
69 | 74 | YukawaKernel, |
70 | 75 | ) |
71 | 76 | from sumpy.test.geometries import make_ellipsoid, make_torus |
72 | 77 |
|
73 | 78 |
|
| 79 | +if TYPE_CHECKING: |
| 80 | + from collections.abc import Callable |
| 81 | + |
74 | 82 | logger = logging.getLogger(__name__) |
75 | 83 |
|
76 | 84 | pytest_generate_tests = pytest_generate_tests_for_array_contexts([ |
@@ -857,6 +865,8 @@ def test_m2m_compressed_error_helmholtz(actx_factory: ArrayContextFactory, dim, |
857 | 865 | # }}} |
858 | 866 |
|
859 | 867 |
|
| 868 | +# {{{ test_jump |
| 869 | + |
860 | 870 | @pytest.mark.parametrize(("kernel_cls", "kernel_kwargs"), [ |
861 | 871 | (LaplaceKernel, {}), |
862 | 872 | (HelmholtzKernel, {"k": 1}), |
@@ -922,6 +932,39 @@ def test_jump( |
922 | 932 | err = abs((inside-outside) - -1) |
923 | 933 | assert err < tol, err |
924 | 934 |
|
| 935 | +# }}} |
| 936 | + |
| 937 | + |
| 938 | +# {{{ test_pickle |
| 939 | + |
| 940 | +@memoize_on_first_arg |
| 941 | +def get_kernel_name_for_test(knl: Kernel) -> Callable[[str], str]: |
| 942 | + return lambda prefix: f"{prefix}: {type(knl).__name__}" |
| 943 | + |
| 944 | + |
| 945 | +@pytest.mark.parametrize("knl", [ |
| 946 | + BiharmonicKernel(2), |
| 947 | + ElasticityKernel(2, 0, 0), |
| 948 | + HelmholtzKernel(3, helmholtz_k_name="kay"), |
| 949 | + LaplaceKernel(3), |
| 950 | + LineOfCompressionKernel(), |
| 951 | + OneKernel(2), |
| 952 | + StokesletKernel(2, 0, 0), |
| 953 | + StressletKernel(2, 0, 0, 0), |
| 954 | + YukawaKernel(2, yukawa_lambda_name="lambda"), |
| 955 | +]) |
| 956 | +def test_pickle(knl: Kernel) -> None: |
| 957 | + import pickle |
| 958 | + |
| 959 | + result = pickle.dumps(knl) |
| 960 | + assert pickle.loads(result) == knl |
| 961 | + |
| 962 | + _ = get_kernel_name_for_test(knl) |
| 963 | + result = pickle.dumps(knl) |
| 964 | + assert pickle.loads(result) == knl |
| 965 | + |
| 966 | +# }}} |
| 967 | + |
925 | 968 |
|
926 | 969 | # You can test individual routines by typing |
927 | 970 | # $ python test_kernels.py 'test_p2p(_acf, True)' |
|
0 commit comments