diff --git a/doc/source/reference.rst b/doc/source/reference.rst index 13c92a63460fcdee8f62aa707366885ec6e18b89..30bb4417b3655aeb182dc23421d72bc265cf0b8e 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 7977933ac9bed3c6a33188e5d532ef5eab712e01..f8ca1bdd7a9b5fd196cac1e421a0182ec7d2fa88 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 7ecaef49bf708164332b5a1bd708c8f4a93545d2..6515692417a0f7b116701f3347b9785f0943816f 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,