From 298583fa66680a65c009d2a9d9c5a18dc172e7c8 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 15 Sep 2009 20:54:43 -0400 Subject: [PATCH] Add Image.shape. (suggested by David Garcia) --- doc/source/reference.rst | 4 ++++ pyopencl/__init__.py | 10 ++++++++++ test/test_wrapper.py | 7 +++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/source/reference.rst b/doc/source/reference.rst index 13c92a63..30bb4417 100644 --- a/doc/source/reference.rst +++ b/doc/source/reference.rst @@ -264,6 +264,10 @@ Images may be used as attributes on instances of this class to directly query info attributes. + .. attribute:: shape + + Return the value of the *shape* constructor argument as a :class:`tuple`. + .. method:: get_image_info(param) See :class:`image_info` for values of *param*. diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 7977933a..f8ca1bdd 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -155,8 +155,18 @@ def _add_functionality(): else: return self.event.get_image_info(inf_attr) + def image_shape(self): + if self.type == mem_object_type.IMAGE2D: + return (self.width, self.height) + elif self.type == mem_object_type.IMAGE3D: + return (self.width, self.height, self.depth) + else: + raise LogicError("only images have shapes") + _cl.Image.image = property(ImageInfoGetter) + _cl.Image.shape = property(image_shape) + # Event ------------------------------------------------------------------- def event_wait(self): wait_for_events([self]) return self diff --git a/test/test_wrapper.py b/test/test_wrapper.py index 7ecaef49..65156924 100644 --- a/test/test_wrapper.py +++ b/test/test_wrapper.py @@ -129,10 +129,9 @@ class TestCL: img_format = cl.get_supported_image_formats( ctx, cl.mem_flags.READ_ONLY, cl.mem_object_type.IMAGE2D)[0] - img = cl.create_image_2d(ctx, cl.mem_flags.READ_ONLY, img_format, - 128, 128) - #img = cl.Image(ctx, cl.mem_flags.READ_ONLY, img_format, - #(128, 128)) + img = cl.Image(ctx, cl.mem_flags.READ_ONLY, img_format, (128, 256)) + assert img.shape == (128, 256) + img.depth img.image.depth do_test(img, cl.image_info, -- GitLab