On Wed, Feb 3, 2016 at 2:49 PM, Jerome Kieffer <[email protected]> wrote:
> On Wed, 3 Feb 2016 10:29:43 -0600
> Brian Paterni <[email protected]> wrote:
>
>> > One example in the book walks through computing a histogram of an image,
>> > but while the example code provided (in C) works and produces the
>> > expected output histogram, my attempt to translate the same program into
>> > Python raises some question. the kernel runs and produces results that
>> > resembles the reference histogram, only values are much, much larger
>> > than expected.
>
> Are you not mixing int32 and int64 ?
> if you play on linux64, python works with int64 for int while the
> OpenCL is likely to consider them as 32bits only.

Aha!

Originally I thought I had taken necessary precautions to make sure
this wasn't the issue. After seeing your mail though, I examined the
code closer and found that the input numpy array is being read in with
a datatype of 'int' which is, in fact, 64 bits. With the following
changes, the python-based histogram computation produces the correct
result:

diff --git a/histogram.py b/histogram.py
index a31c391..55d905d 100644
--- a/histogram.py
+++ b/histogram.py
@@ -27,8 +27,8 @@ class Main:
         n_elements = i_cat.size[0] * i_cat.size[1]
         hist_size  = Main.HIST_BINS

-        np_img_in = numpy.array(i_cat.getdata(), int)
-        np_out_hist = numpy.zeros(hist_size, int)
+        np_img_in = numpy.array(i_cat.getdata(), numpy.int32)
+        np_out_hist = numpy.zeros(hist_size, numpy.int32)

         print 'cat size: {}x{} = {} pixels'.format(
                 i_cat.size[0], i_cat.size[1],


Thank you very much for the suggestion to reexamine the code! I shall
be more cautious in the future! :)

_______________________________________________
PyOpenCL mailing list
[email protected]
http://lists.tiker.net/listinfo/pyopencl

Reply via email to