[python-arrayfire] 07/250: Generalizing af.constant to handle complex and 64 bit data types

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:25 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 f3824198062699339d2eb83ae549d46631ca946e
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Fri Jun 19 15:32:13 2015 -0400

    Generalizing af.constant to handle complex and 64 bit data types
---
 arrayfire/data.py | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/arrayfire/data.py b/arrayfire/data.py
index fda37cc..61fc9c0 100644
--- a/arrayfire/data.py
+++ b/arrayfire/data.py
@@ -42,6 +42,22 @@ def constant(val, d0, d1=None, d2=None, d3=None, dtype=f32):
 
     out = array()
     dims = dim4(d0, d1, d2, d3)
-    c_val = c_double(val)
-    clib.af_constant(pointer(out.arr), c_val, 4, pointer(dims), dtype)
+
+    if isinstance(val, complex):
+        c_real = c_double(val.real)
+        c_imag = c_double(val.imag)
+
+        if (dtype != c32 and dtype != c64):
+            dtype = c32
+
+        clib.af_constant_complex(pointer(out.arr), c_real, c_imag, 4, pointer(dims), dtype)
+    elif dtype == s64:
+        c_val = c_longlong(val.real)
+        clib.af_constant_long(pointer(out.arr), c_val, 4, pointer(dims))
+    elif dtype == u64:
+        c_val = c_ulonglong(val.real)
+        clib.af_constant_ulong(pointer(out.arr), c_val, 4, pointer(dims))
+    else:
+        c_val = c_double(val)
+        clib.af_constant(pointer(out.arr), c_val, 4, pointer(dims), dtype)
     return out

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