[python-arrayfire] 48/250: FEAT: Added the ability to make broadcast a decorator

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:29 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 4441eb5b3ca339e5406d143723610f0a8c3b47c8
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Tue Jul 28 18:08:14 2015 -0400

    FEAT: Added the ability to make broadcast a decorator
---
 arrayfire/broadcast.py | 15 +++++++++++----
 tests/simple_arith.py  |  8 +++++++-
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/arrayfire/broadcast.py b/arrayfire/broadcast.py
index 15e4228..cc39c69 100644
--- a/arrayfire/broadcast.py
+++ b/arrayfire/broadcast.py
@@ -20,7 +20,14 @@ class bcast(object):
         bcast._flag ^= True
 
 def broadcast(func, *args):
-    bcast.toggle()
-    res = func(*args)
-    bcast.toggle()
-    return res
+
+    def wrapper(*func_args):
+        bcast.toggle()
+        res = func(*func_args)
+        bcast.toggle()
+        return res
+
+    if len(args) == 0:
+        return wrapper
+    else:
+        return wrapper(*args)
diff --git a/tests/simple_arith.py b/tests/simple_arith.py
index e6941f1..30b3596 100755
--- a/tests/simple_arith.py
+++ b/tests/simple_arith.py
@@ -190,8 +190,14 @@ af.display(af.isinf(a/b))
 af.display(af.isnan(a/a))
 
 a = af.randu(5, 1)
-b = af.randu(5, 5)
+b = af.randu(1, 5)
 c = af.broadcast(lambda x,y: x+y, a, b)
 af.display(a)
 af.display(b)
 af.display(c)
+
+ at af.broadcast
+def test_add(aa, bb):
+    return aa + bb
+
+af.display(test_add(a, b))

-- 
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