From 047f40c714739170c0419571998a7969ad790174 Mon Sep 17 00:00:00 2001 From: Marko Bencun <mbencun@gmail.com> Date: Sun, 8 Sep 2013 17:48:31 +0200 Subject: [PATCH] ImageFormat hashing++ --- pyopencl/_init.py | 26 -------------------------- pyopencl/cffi_cl.py | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/pyopencl/_init.py b/pyopencl/_init.py index 3b110de7..d68c610c 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 a1f74b79..463758d6 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): -- GitLab