diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8173bd209ee80755e4fc0d3f47ad6b605b1fdcea..e1579ae818bfedb952d960b231627eeadf413695 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -50,7 +50,7 @@ Python 3 Titan X: reports: junit: test/pytest.xml -Python 3.6 Conda: +Python 3 Conda: script: # Disable caching to ensure SymEngine code generation is exercised. - export SUMPY_NO_CACHE=1 diff --git a/sumpy/fmm.py b/sumpy/fmm.py index a233175686f2c395fe7783235ddeb5e351b09ff0..668734fdc8a433a65b3b80b722f825b2aa2f743b 100644 --- a/sumpy/fmm.py +++ b/sumpy/fmm.py @@ -320,13 +320,16 @@ class SumpyExpansionWrangler(object): return source_array.with_queue(self.queue)[self.tree.user_source_ids] def reorder_potentials(self, potentials): - from pytools.obj_array import is_obj_array, with_object_array_or_scalar - assert is_obj_array(potentials) + from pytools.obj_array import obj_array_vectorize + import numpy as np + assert ( + isinstance(potentials, np.ndarray) + and potentials.dtype.char == "O") def reorder(x): return x.with_queue(self.queue)[self.tree.sorted_target_ids] - return with_object_array_or_scalar(reorder, potentials) + return obj_array_vectorize(reorder, potentials) # }}} diff --git a/sumpy/tools.py b/sumpy/tools.py index 353ca9dac95673863fa735bd685267257443acb1..959e2d45634c204045830859bb44490e24eb571c 100644 --- a/sumpy/tools.py +++ b/sumpy/tools.py @@ -181,18 +181,18 @@ def build_matrix(op, dtype=None, shape=None): def vector_to_device(queue, vec): - from pytools.obj_array import with_object_array_or_scalar + from pytools.obj_array import obj_array_vectorize from pyopencl.array import to_device def to_dev(ary): return to_device(queue, ary) - return with_object_array_or_scalar(to_dev, vec) + return obj_array_vectorize(to_dev, vec) def vector_from_device(queue, vec): - from pytools.obj_array import with_object_array_or_scalar + from pytools.obj_array import obj_array_vectorize def from_dev(ary): from numbers import Number @@ -202,7 +202,7 @@ def vector_from_device(queue, vec): return ary.get(queue=queue) - return with_object_array_or_scalar(from_dev, vec) + return obj_array_vectorize(from_dev, vec) def _merge_kernel_arguments(dictionary, arg): diff --git a/sumpy/visualization.py b/sumpy/visualization.py index bf5f016b4c089be7723a2ff92c91530c998603c2..d1eee517a9d99b1544f8e30c566e91debe9a72d8 100644 --- a/sumpy/visualization.py +++ b/sumpy/visualization.py @@ -33,34 +33,22 @@ from six.moves import range def separate_by_real_and_imag(data, real_only): + from pytools.obj_array import obj_array_real_copy, obj_array_imag_copy + for name, field in data: - from pytools.obj_array import log_shape - ls = log_shape(field) - - if ls != () and ls[0] > 1: - assert len(ls) == 1 - from pytools.obj_array import ( - oarray_real_copy, oarray_imag_copy, - with_object_array_or_scalar) - - if field[0].dtype.kind == "c": - if real_only: - yield (name, - with_object_array_or_scalar(oarray_real_copy, field)) - else: - yield (name+"_r", - with_object_array_or_scalar(oarray_real_copy, field)) - yield (name+"_i", - with_object_array_or_scalar(oarray_imag_copy, field)) - else: - yield (name, field) + try: + # Look inside object arrays to get the entry dtype. + entry_dtype = field[0].dtype + except AttributeError: + entry_dtype = field.dtype + + assert entry_dtype.kind != "O" + + if real_only or entry_dtype.kind != "c": + yield (name, obj_array_real_copy(field)) else: - # ls == () - if field.dtype.kind == "c": - yield (name+"_r", field.real.copy()) - yield (name+"_i", field.imag.copy()) - else: - yield (name, field) + yield (name + "_r", obj_array_real_copy(field)) + yield (name + "_i", obj_array_imag_copy(field)) def make_field_plotter_from_bbox(bbox, h, extend_factor=0): diff --git a/test/test_fmm.py b/test/test_fmm.py index 2bc6d69d6bcafedf338cc78aea0591d6d5ac3845..b429456628e35d997cb0cbe8f4eec4588e1b66fd 100644 --- a/test/test_fmm.py +++ b/test/test_fmm.py @@ -72,10 +72,10 @@ else: HelmholtzConformingVolumeTaylorMultipoleExpansion), (YukawaKernel(2), Y2DLocalExpansion, Y2DMultipoleExpansion), ]) -def test_sumpy_fmm(ctx_getter, knl, local_expn_class, mpole_expn_class): +def test_sumpy_fmm(ctx_factory, knl, local_expn_class, mpole_expn_class): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nsources = 1000 @@ -201,10 +201,10 @@ def test_sumpy_fmm(ctx_getter, knl, local_expn_class, mpole_expn_class): pconv_verifier() -def test_sumpy_fmm_timing_data_collection(ctx_getter): +def test_sumpy_fmm_timing_data_collection(ctx_factory): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue( ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) @@ -257,10 +257,10 @@ def test_sumpy_fmm_timing_data_collection(ctx_getter): assert timing_data -def test_sumpy_fmm_exclude_self(ctx_getter): +def test_sumpy_fmm_exclude_self(ctx_factory): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nsources = 500 diff --git a/test/test_kernels.py b/test/test_kernels.py index 834d823321bec0c05b3253e4c8718ff9145b343f..caff694dd1eddc9639f7be072dee669db1c897c2 100644 --- a/test/test_kernels.py +++ b/test/test_kernels.py @@ -58,8 +58,8 @@ else: @pytest.mark.parametrize("exclude_self", (True, False)) -def test_p2p(ctx_getter, exclude_self): - ctx = ctx_getter() +def test_p2p(ctx_factory, exclude_self): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) dimensions = 3 @@ -140,13 +140,13 @@ def test_p2p(ctx_getter, exclude_self): True ]) # Sample: test_p2e2p(cl._csc, LaplaceKernel(2), VolumeTaylorLocalExpansion, 4, False) -def test_p2e2p(ctx_getter, base_knl, expn_class, order, with_source_derivative): +def test_p2e2p(ctx_factory, base_knl, expn_class, order, with_source_derivative): #logging.basicConfig(level=logging.INFO) from sympy.core.cache import clear_cache clear_cache() - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) np.random.seed(17) @@ -353,13 +353,13 @@ def test_p2e2p(ctx_getter, base_knl, expn_class, order, with_source_derivative): HelmholtzConformingVolumeTaylorMultipoleExpansion), (HelmholtzKernel(2), H2DLocalExpansion, H2DMultipoleExpansion) ]) -def test_translations(ctx_getter, knl, local_expn_class, mpole_expn_class): +def test_translations(ctx_factory, knl, local_expn_class, mpole_expn_class): logging.basicConfig(level=logging.INFO) from sympy.core.cache import clear_cache clear_cache() - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) np.random.seed(17) diff --git a/test/test_matrixgen.py b/test/test_matrixgen.py index 2c07b40a5c753e6c362be61263f0bf388784fc4a..463e7be6221a603ba3684b1c764d8905f35ca7e7 100644 --- a/test/test_matrixgen.py +++ b/test/test_matrixgen.py @@ -98,10 +98,10 @@ def _build_block_index(queue, nnodes, nblks, factor): @pytest.mark.parametrize('factor', [1.0, 0.6]) @pytest.mark.parametrize('lpot_id', [1, 2]) -def test_qbx_direct(ctx_getter, factor, lpot_id): +def test_qbx_direct(ctx_factory, factor, lpot_id): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) ndim = 2 @@ -143,8 +143,9 @@ def test_qbx_direct(ctx_getter, factor, lpot_id): extra_kwargs = {} if lpot_id == 2: + from pytools.obj_array import make_obj_array extra_kwargs["dsource_vec"] = \ - vector_to_device(queue, np.ones((ndim, n))) + vector_to_device(queue, make_obj_array(np.ones((ndim, n)))) _, (result_lpot,) = lpot(queue, targets=targets, @@ -181,10 +182,10 @@ def test_qbx_direct(ctx_getter, factor, lpot_id): @pytest.mark.parametrize("exclude_self", [True, False]) @pytest.mark.parametrize("factor", [1.0, 0.6]) @pytest.mark.parametrize('lpot_id', [1, 2]) -def test_p2p_direct(ctx_getter, exclude_self, factor, lpot_id): +def test_p2p_direct(ctx_factory, exclude_self, factor, lpot_id): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) ndim = 2 @@ -225,8 +226,9 @@ def test_p2p_direct(ctx_getter, exclude_self, factor, lpot_id): extra_kwargs["target_to_source"] = \ cl.array.arange(queue, 0, n, dtype=np.int) if lpot_id == 2: + from pytools.obj_array import make_obj_array extra_kwargs["dsource_vec"] = \ - vector_to_device(queue, np.ones((ndim, n))) + vector_to_device(queue, make_obj_array(np.ones((ndim, n)))) _, (result_lpot,) = lpot(queue, targets=targets, diff --git a/test/test_misc.py b/test/test_misc.py index 77f887c1896c3c0db8fc6a69209defa2e1a50591..d8aff52f0e7918b65ef5572eae577e4a77983a5c 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -243,7 +243,7 @@ RTOL_P2E2E2P = 1e-2 @pytest.mark.parametrize("case", P2E2E2P_TEST_CASES) -def test_toy_p2e2e2p(ctx_getter, case): +def test_toy_p2e2e2p(ctx_factory, case): dim = case.dim src = case.source.reshape(dim, -1) @@ -256,7 +256,7 @@ def test_toy_p2e2e2p(ctx_getter, case): from sumpy.expansion.local import VolumeTaylorLocalExpansion from sumpy.expansion.multipole import VolumeTaylorMultipoleExpansion - cl_ctx = ctx_getter() + cl_ctx = ctx_factory() ctx = t.ToyContext(cl_ctx, LaplaceKernel(dim), VolumeTaylorMultipoleExpansion, diff --git a/test/test_qbx.py b/test/test_qbx.py index d408c4a4b82b907a6af801227f2c0e3ffbbb2f5a..8b73224c0ec23dc8f9249e2baad5fd92afb2d638 100644 --- a/test/test_qbx.py +++ b/test/test_qbx.py @@ -41,11 +41,11 @@ else: faulthandler.enable() -def test_direct(ctx_getter): +def test_direct(ctx_factory): # This evaluates a single layer potential on a circle. logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from sumpy.kernel import LaplaceKernel