From ec6b253b48f3fd774db61771b2506b9f90c38205 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Wed, 17 Jul 2013 18:55:14 -0400 Subject: [PATCH] Make ImageFormat comparable, hashable --- doc/misc.rst | 1 + doc/runtime.rst | 12 ++++++++++-- pyopencl/__init__.py | 13 +++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/doc/misc.rst b/doc/misc.rst index 9ac75437..4c57d8c3 100644 --- a/doc/misc.rst +++ b/doc/misc.rst @@ -82,6 +82,7 @@ Version 2013.2 * Add :meth:`pyopencl.array.Array.map_to_host`. * Support *strides* on :func:`pyopencl.enqueue_map_buffer` and :func:`pyopencl.enqueue_map_image`. +* :class:`pyopencl.ImageFormat` was made comparable and hashable. Version 2013.1 -------------- diff --git a/doc/runtime.rst b/doc/runtime.rst index 20fceb24..5eff4034 100644 --- a/doc/runtime.rst +++ b/doc/runtime.rst @@ -398,8 +398,6 @@ Image Formats .. class:: ImageFormat([channel_order, channel_type]) - .. versionchanged:: 0.91 - Constructor arguments added. .. attribute:: channel_order @@ -427,6 +425,16 @@ Image Formats .. versionadded:: 0.91 + |comparable| + + .. versionchanged:: 0.91 + + Constructor arguments added. + + .. versionchanged:: 2013.2 + + :class:`ImageFormat` was made comparable and hashable + .. function:: get_supported_image_formats(context, flags, image_type) See :class:`mem_flags` for possible values of *flags* diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index a7e3830e..57566ca7 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -637,7 +637,20 @@ def _add_functionality(): channel_type.to_string(self.channel_data_type, "<unknown channel data type 0x%x>")) + def image_format_eq(self, other): + return (self.channel_order == other.channel_order + and self.channel_data_type == other.channel_data_type) + + def image_format_ne(self, other): + return not image_format_eq(self, other) + + def image_format_hash(self): + return hash((type(self), self.channel_order, self.channel_data_type)) + ImageFormat.__repr__ = image_format_repr + ImageFormat.__eq__ = image_format_eq + ImageFormat.__ne__ = image_format_ne + ImageFormat.__hash__ = image_format_hash # }}} -- GitLab