From c27ccd268fb15981122d614b9e30027ff9024db0 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Wed, 25 Jul 2012 10:41:18 -0500
Subject: [PATCH] Tweak dump-properties to allow short output.

---
 examples/dump-properties.py | 82 +++++++++++++++++++++----------------
 test/test_array.py          | 30 ++++++++++----
 2 files changed, 69 insertions(+), 43 deletions(-)

diff --git a/examples/dump-properties.py b/examples/dump-properties.py
index 8732c4cc..b9726b8e 100644
--- a/examples/dump-properties.py
+++ b/examples/dump-properties.py
@@ -1,4 +1,11 @@
 import pyopencl as cl
+from optparse import OptionParser
+
+parser = OptionParser()
+parser.add_option("-s", "--short", action="store_true",
+                  help="don't print all device properties")
+
+(options, args) = parser.parse_args()
 
 def print_info(obj, info_cls):
     for info_name in sorted(dir(info_cls)):
@@ -20,42 +27,45 @@ for platform in cl.get_platforms():
     print(75*"=")
     print(platform)
     print(75*"=")
-    print_info(platform, cl.platform_info)
+    if not options.short:
+        print_info(platform, cl.platform_info)
 
     for device in platform.get_devices():
-        print(75*"-")
+        if not options.short:
+            print(75*"-")
         print(device)
-        print(75*"-")
-        print_info(device, cl.device_info)
-        ctx = cl.Context([device])
-        #for mf in [cl.mem_flags.READ_ONLY, cl.mem_flags.READ_WRITE, cl.mem_flags.WRITE_ONLY]:
-        for mf in [cl.mem_flags.READ_ONLY]:
-            for itype in [cl.mem_object_type.IMAGE2D, cl.mem_object_type.IMAGE3D]:
-                try:
-                    formats = cl.get_supported_image_formats(ctx, mf, itype)
-                except:
-                    formats = "<error>"
-                else:
-                    def str_chd_type(chdtype):
-                        result = cl.channel_type.to_string(chdtype,
-                                "<unknown channel data type %d>")
-
-                        result = result.replace("_INT", "")
-                        result = result.replace("UNSIGNED", "U")
-                        result = result.replace("SIGNED", "S")
-                        result = result.replace("NORM", "N")
-                        result = result.replace("FLOAT", "F")
-                        return result
-
-                    formats = ", ".join(
-                            "%s-%s" % (
-                                cl.channel_order.to_string(iform.channel_order, 
-                                    "<unknown channel order 0x%x>"),
-                                str_chd_type(iform.channel_data_type))
-                            for iform in formats)
-
-                print "%s %s FORMATS: %s\n" % (
-                        cl.mem_object_type.to_string(itype),
-                        cl.mem_flags.to_string(mf),
-                        formats)
-        del ctx
+        if not options.short:
+            print(75*"-")
+            print_info(device, cl.device_info)
+            ctx = cl.Context([device])
+            #for mf in [cl.mem_flags.READ_ONLY, cl.mem_flags.READ_WRITE, cl.mem_flags.WRITE_ONLY]:
+            for mf in [cl.mem_flags.READ_ONLY]:
+                for itype in [cl.mem_object_type.IMAGE2D, cl.mem_object_type.IMAGE3D]:
+                    try:
+                        formats = cl.get_supported_image_formats(ctx, mf, itype)
+                    except:
+                        formats = "<error>"
+                    else:
+                        def str_chd_type(chdtype):
+                            result = cl.channel_type.to_string(chdtype,
+                                    "<unknown channel data type %d>")
+
+                            result = result.replace("_INT", "")
+                            result = result.replace("UNSIGNED", "U")
+                            result = result.replace("SIGNED", "S")
+                            result = result.replace("NORM", "N")
+                            result = result.replace("FLOAT", "F")
+                            return result
+
+                        formats = ", ".join(
+                                "%s-%s" % (
+                                    cl.channel_order.to_string(iform.channel_order,
+                                        "<unknown channel order 0x%x>"),
+                                    str_chd_type(iform.channel_data_type))
+                                for iform in formats)
+
+                    print "%s %s FORMATS: %s\n" % (
+                            cl.mem_object_type.to_string(itype),
+                            cl.mem_flags.to_string(mf),
+                            formats)
+            del ctx
diff --git a/test/test_array.py b/test/test_array.py
index a78e2334..4dea140a 100644
--- a/test/test_array.py
+++ b/test/test_array.py
@@ -768,21 +768,37 @@ def test_struct_reduce(ctx_factory):
 def summarize_error(obtained, desired, orig, thresh=1e-5):
     err = obtained - desired
     ok_count = 0
+    bad_count = 0
+
+    bad_limit = 200
+
+    def summarize_counts():
+        if ok_count:
+            entries.append("<%d ok>" % ok_count)
+        if bad_count >= bad_limit:
+            entries.append("<%d more bad>" % (bad_count-bad_limit))
 
     entries = []
     for i, val in enumerate(err):
         if abs(val) > thresh:
             if ok_count:
-                entries.append("<%d ok>" % ok_count)
+                summarize_counts()
                 ok_count = 0
 
-            entries.append("%r (want: %r, got: %r, orig: %r)" % (obtained[i], desired[i],
-                obtained[i], orig[i]))
+            bad_count += 1
+
+            if bad_count < bad_limit:
+                entries.append("%r (want: %r, got: %r, orig: %r)" % (obtained[i], desired[i],
+                    obtained[i], orig[i]))
         else:
+            if bad_count:
+                summarize_counts()
+                bad_count = 0
+
             ok_count += 1
 
-    if ok_count:
-        entries.append("<%d ok>" % ok_count)
+
+    summarize_counts()
 
     return " ".join(entries)
 
@@ -818,7 +834,6 @@ def test_scan(ctx_factory):
         knl = cls(context, dtype, "a+b", "0")
 
         for n in scan_test_counts:
-
             host_data = np.random.randint(0, 10, n).astype(dtype)
             dev_data = cl_array.to_device(queue, host_data)
 
@@ -832,9 +847,10 @@ def test_scan(ctx_factory):
 
             is_ok = (dev_data.get() == desired_result).all()
             if 1 and not is_ok:
+                print "something went wrong, summarizing error..."
                 print(summarize_error(dev_data.get(), desired_result, host_data))
 
-            print(n, is_ok)
+            print("n:%d %s worked:%s" % (n, cls, is_ok))
             assert is_ok
             from gc import collect
             collect()
-- 
GitLab