[python-arrayfire] 172/250: Adding convolve example

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:45 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.

commit 1315d82d49525adb628a2bfa6e2af3d3d7b8b003
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Wed Dec 9 19:19:37 2015 -0500

    Adding convolve example
---
 examples/getting_started/convolve.py | 42 ++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/examples/getting_started/convolve.py b/examples/getting_started/convolve.py
new file mode 100644
index 0000000..6c9e245
--- /dev/null
+++ b/examples/getting_started/convolve.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+
+#######################################################
+# Copyright (c) 2015, ArrayFire
+# All rights reserved.
+#
+# This file is distributed under 3-clause BSD license.
+# The complete license agreement can be obtained at:
+# http://arrayfire.com/licenses/BSD-3-Clause
+########################################################
+
+import arrayfire as af
+import sys
+from array import array
+
+def af_assert(left, right, eps=1E-6):
+    if (af.max(af.abs(left -right)) > eps):
+        raise ValueError("Arrays not within dictated precision")
+    return
+
+if __name__ == "__main__":
+    if (len(sys.argv) > 1):
+        af.set_device(int(sys.argv[1]))
+    af.info()
+
+    h_dx = array('f', (1.0/12, -8.0/12, 0, 8.0/12, 1.0/12))
+    h_spread = array('f', (1.0/5, 1.0/5, 1.0/5, 1.0/5, 1.0/5))
+
+    img = af.randu(640, 480)
+    dx = af.Array(h_dx, (5,1))
+    spread = af.Array(h_spread, (1, 5))
+    kernel = af.matmul(dx, spread)
+
+    full_res = af.convolve2(img, kernel)
+    sep_res = af.convolve2_separable(dx, spread, img)
+
+    af_assert(full_res, sep_res)
+
+    print("full      2D convolution time: %.5f ms" %
+          (1000 * af.timeit(af.convolve2, img, kernel)))
+    print("separable 2D convolution time: %.5f ms" %
+          (1000 * af.timeit(af.convolve2_separable, dx, spread, img)))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git



More information about the debian-science-commits mailing list