diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 607b8696237460a03566c49463a3042cd2de7fe1..c4a452ed2d159b63d2925fb29dfaee71229696d6 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -41,13 +41,16 @@ def _add_functionality(): ], } - def to_string(cls, value): + def to_string(cls, value, default_format=None): for name in dir(cls): if (not name.startswith("_") and getattr(cls, name) == value): return name - raise ValueError("a name for value %d was not found in %s" - % (value, cls.__name__)) + if default_format is None: + raise ValueError("a name for value %d was not found in %s" + % (value, cls.__name__)) + else: + return default_format % value for cls in CONSTANT_CLASSES: cls.to_string = classmethod(to_string) @@ -243,8 +246,10 @@ def _add_functionality(): # {{{ ImageFormat def image_format_repr(self): return "ImageFormat(%s, %s)" % ( - channel_order.to_string(self.channel_order), - channel_type.to_string(self.channel_data_type)) + channel_order.to_string(self.channel_order, + ""), + channel_type.to_string(self.channel_data_type, + "")) ImageFormat.__repr__ = image_format_repr # }}} diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp index 233ea32aebc237b837cdee7fb3e5c986e364059f..6acdccbe791df7ea415d56400e69ae99f1b688a2 100644 --- a/src/wrapper/wrap_cl.hpp +++ b/src/wrapper/wrap_cl.hpp @@ -1565,17 +1565,15 @@ namespace pyopencl cl_mem_flags flags, cl_mem_object_type image_type) { - cl_uint num_image_formats = 1024; - std::vector formats(num_image_formats); - do - { - if (formats.size() < num_image_formats) - formats.resize(num_image_formats); + cl_uint num_image_formats; + PYOPENCL_CALL_GUARDED(clGetSupportedImageFormats, ( + ctx.data(), flags, image_type, + 0, NULL, &num_image_formats)); - PYOPENCL_CALL_GUARDED(clGetSupportedImageFormats, ( - ctx.data(), flags, image_type, - formats.size(), formats.empty( ) ? NULL : &formats.front(), &num_image_formats)); - } while (formats.size() < num_image_formats); + std::vector formats(num_image_formats); + PYOPENCL_CALL_GUARDED(clGetSupportedImageFormats, ( + ctx.data(), flags, image_type, + formats.size(), formats.empty( ) ? NULL : &formats.front(), NULL)); PYOPENCL_RETURN_VECTOR(cl_image_format, formats); }