diff --git a/pyopencl/array.py b/pyopencl/array.py index 9ee94a15ea8b4ca3458ab5499f6ba4c6b04eef95..08f7cc8b969c60b22df0565806d3db30f9126b4b 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -69,6 +69,12 @@ class VecLookupWarner(object): warn("pyopencl.array.vec is deprecated. " "Please use pyopencl.cltypes for OpenCL vector and scalar types", DeprecationWarning, 2) + + if name == "types": + name = "vec_types" + elif name == "type_to_scalar_and_count": + name = "vec_type_to_scalar_and_count" + return getattr(cltypes, name) diff --git a/pyopencl/clrandom.py b/pyopencl/clrandom.py index 225705c2fee68fc6f1acb0a99f7344eb7565ecd1..a30ffaf9391e1955a419212d7468f25ad228ea50 100644 --- a/pyopencl/clrandom.py +++ b/pyopencl/clrandom.py @@ -63,6 +63,7 @@ for some documentation if you're planning on using Random123 directly. import pyopencl as cl import pyopencl.array as cl_array +import pyopencl.cltypes as cltypes from pyopencl.tools import first_arg_dependent_memoize from pytools import memoize_method @@ -218,13 +219,13 @@ class RanluxGenerator(object): bits = 32 c_type = "float" rng_expr = "(shift + scale * gen)" - elif dtype == cl_array.vec.float2: + elif dtype == cltypes.float2: bits = 32 c_type = "float" rng_expr = "(shift + scale * gen)" size_multiplier = 2 arg_dtype = np.float32 - elif dtype in [cl_array.vec.float3, cl_array.vec.float4]: + elif dtype in [cltypes.float3, cltypes.float4]: bits = 32 c_type = "float" rng_expr = "(shift + scale * gen)" @@ -475,9 +476,9 @@ class Random123GeneratorBase(object): for dist in ["normal", "uniform"] for cmp_dtype in [ np.float32, - cl.array.vec.float2, - cl.array.vec.float3, - cl.array.vec.float4, + cltypes.float2, + cltypes.float3, + cltypes.float4, ]]: c_type = "float" scale_const = "((float) %r)" % (1/2**32) @@ -493,7 +494,7 @@ class Random123GeneratorBase(object): counter_multiplier = 1 arg_dtype = np.float32 try: - _, size_multiplier = cl.array.vec.type_to_scalar_and_count[dtype] + _, size_multiplier = cltypes.vec_type_to_scalar_and_count[dtype] except KeyError: pass diff --git a/pyopencl/cltypes.py b/pyopencl/cltypes.py index c8ff35c378bd1eb395e54dc0efa5ce6a21ff9b85..d1ba79f3f8e3905bdee8f119dca3e57a8dda6509 100644 --- a/pyopencl/cltypes.py +++ b/pyopencl/cltypes.py @@ -46,7 +46,6 @@ double = np.float64 # {{{ vector types - def _create_vector_types(): _mapping = [(k, globals()[k]) for k in ['char', 'uchar', 'short', 'ushort', 'int', @@ -55,10 +54,10 @@ def _create_vector_types(): def set_global(key, val): globals()[key] = val - field_names = ["x", "y", "z", "w"] + vec_types = {} + vec_type_to_scalar_and_count = {} - set_global('types', {}) - set_global('type_to_scalar_and_count', {}) + field_names = ["x", "y", "z", "w"] counts = [2, 3, 4, 8, 16] @@ -119,9 +118,14 @@ def _create_vector_types(): set_global("zeros_" + name, eval("lambda: filled_%s(0)" % (name))) set_global("ones_" + name, eval("lambda: filled_%s(1)" % (name))) - globals()['types'][np.dtype(base_type), count] = dtype - globals()['type_to_scalar_and_count'][dtype] = np.dtype(base_type), count + vec_types[np.dtype(base_type), count] = dtype + vec_type_to_scalar_and_count[dtype] = np.dtype(base_type), count + return vec_types, vec_type_to_scalar_and_count + + +vec_types, vec_type_to_scalar_and_count = _create_vector_types() -_create_vector_types() # }}} + +# vim: foldmethod=marker diff --git a/pyopencl/tools.py b/pyopencl/tools.py index c7bd5ed00280840f78d751f895e6013ea2154601..5efdfdb0c6199b44aafa426f0b49f79aa4ceae39 100644 --- a/pyopencl/tools.py +++ b/pyopencl/tools.py @@ -454,8 +454,8 @@ class _CDeclList: if dtype in self.declared_dtypes: return - from pyopencl.array import vec - if dtype in vec.type_to_scalar_and_count: + import pyopencl.cltypes + if dtype in pyopencl.cltypes.vec_type_to_scalar_and_count: return for name, field_data in sorted(six.iteritems(dtype.fields)): @@ -658,8 +658,8 @@ def dtype_to_c_struct(device, dtype): if dtype.fields is None: return "" - from pyopencl.array import vec - if dtype in vec.type_to_scalar_and_count: + import pyopencl.cltypes + if dtype in pyopencl.cltypes.vec_type_to_scalar_and_count: # Vector types are built-in. Don't try to redeclare those. return "" diff --git a/test/test_array.py b/test/test_array.py index 2c27e77f521cf698449864b52f4f9a4f5cfcd608..4c41890303278dc1490528e74f1a0e147d1bbbd5 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -32,6 +32,7 @@ import pytest import pyopencl as cl import pyopencl.array as cl_array +import pyopencl.cltypes as cltypes import pyopencl.tools as cl_tools from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) @@ -194,12 +195,12 @@ def test_vector_fill(ctx_factory): context = ctx_factory() queue = cl.CommandQueue(context) - a_gpu = cl_array.Array(queue, 100, dtype=cl_array.vec.float4) - a_gpu.fill(cl_array.vec.make_float4(0.0, 0.0, 1.0, 0.0)) + a_gpu = cl_array.Array(queue, 100, dtype=cltypes.float4) + a_gpu.fill(cltypes.make_float4(0.0, 0.0, 1.0, 0.0)) a = a_gpu.get() - assert a.dtype == cl_array.vec.float4 + assert a.dtype == cltypes.float4 - a_gpu = cl_array.zeros(queue, 100, dtype=cl_array.vec.float4) + a_gpu = cl_array.zeros(queue, 100, dtype=cltypes.float4) def test_absrealimag(ctx_factory): diff --git a/test/test_wrapper.py b/test/test_wrapper.py index a281e3105c5d17941821de6c103609a298d99a86..9f0eb8641051b84c39c9e50d68f8800c9f7138d9 100644 --- a/test/test_wrapper.py +++ b/test/test_wrapper.py @@ -30,6 +30,7 @@ import pytest import pyopencl as cl import pyopencl.array as cl_array +import pyopencl.cltypes as cltypes import pyopencl.clrandom from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) @@ -561,8 +562,8 @@ def test_vector_args(ctx_factory): { dest[get_global_id(0)] = x; } """).build() - x = cl_array.vec.make_float4(1, 2, 3, 4) - dest = np.empty(50000, cl_array.vec.float4) + x = cltypes.make_float4(1, 2, 3, 4) + dest = np.empty(50000, cltypes.float4) mf = cl.mem_flags dest_buf = cl.Buffer(context, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=dest)