diff --git a/pyopencl/_init.py b/pyopencl/_init.py index 3b110de7f7d859ad4d9412c1049a13a7faf6270a..d68c610c1dd42e738160680aa44a74756d89262c 100644 --- a/pyopencl/_init.py +++ b/pyopencl/_init.py @@ -510,32 +510,6 @@ def _add_functionality(): # }}} - # {{{ ImageFormat - - def image_format_repr(self): - return "ImageFormat(%s, %s)" % ( - channel_order.to_string(self.channel_order, - "<unknown channel order 0x%x>"), - 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 - - # }}} - # # {{{ Image # image_old_init = Image.__init__ diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index a1f74b7979f34e70d309414f42db06a6d29de9f9..463758d6851f48e3e99223734578f0011e46d3aa 100644 --- a/pyopencl/cffi_cl.py +++ b/pyopencl/cffi_cl.py @@ -540,7 +540,6 @@ class ImageFormat(object): cls = type(cls.__name__, (cls,), {}) cls.channel_order = property(lambda self: args[0], lambda self, v: args.__setitem__(0, v)) cls.channel_data_type = property(lambda self: args[1], lambda self, v: args.__setitem__(1, v)) - cls.__hash__ = lambda self: hash(tuple(args)) return object.__new__(cls) @property @@ -590,6 +589,23 @@ class ImageFormat(object): @property def itemsize(self): return self.channel_count * self.dtype_size + + def __repr__(self): + return "ImageFormat(%s, %s)" % ( + channel_order.to_string(self.channel_order, + "<unknown channel order 0x%x>"), + channel_type.to_string(self.channel_data_type, + "<unknown channel data type 0x%x>")) + + def __eq__(self, other): + return (self.channel_order == other.channel_order + and self.channel_data_type == other.channel_data_type) + + def __ne__(self, other): + return not image_format_eq(self, other) + + def __hash__(self): + return hash((ImageFormat, self.channel_order, self.channel_data_type)) def get_supported_image_formats(context, flags, image_type):