[python-arrayfire] 29/250: FEAT/TEST: imported all functions from singal.h

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:27 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 5b7241c465004d16e119c0a77e77b33baec147d7
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Wed Jul 15 15:21:18 2015 -0400

    FEAT/TEST: imported all functions from singal.h
---
 arrayfire/__init__.py  |  17 ++--
 arrayfire/signal.py    | 216 +++++++++++++++++++++++++++++++++++++++++++++++++
 arrayfire/util.py      |   9 ++-
 tests/simple_signal.py |  73 +++++++++++++++++
 4 files changed, 305 insertions(+), 10 deletions(-)

diff --git a/arrayfire/__init__.py b/arrayfire/__init__.py
index 779693b..0df736e 100644
--- a/arrayfire/__init__.py
+++ b/arrayfire/__init__.py
@@ -7,12 +7,13 @@
 # http://arrayfire.com/licenses/BSD-3-Clause
 ########################################################
 
-from .library import *
-from .data import *
-from .util import *
-from .algorithm import *
-from .device import *
-from .blas import *
-from .arith import *
+from .library    import *
+from .data       import *
+from .util       import *
+from .algorithm  import *
+from .device     import *
+from .blas       import *
+from .arith      import *
 from .statistics import *
-from .lapack import *
+from .lapack     import *
+from .signal     import *
diff --git a/arrayfire/signal.py b/arrayfire/signal.py
new file mode 100644
index 0000000..b037b6d
--- /dev/null
+++ b/arrayfire/signal.py
@@ -0,0 +1,216 @@
+#######################################################
+# Copyright (c) 2014, 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
+########################################################
+
+from .library import *
+from .array import *
+
+def approx1(signal, pos0, method=AF_INTERP_LINEAR, off_grid=0.0):
+    output = array()
+    safe_call(clib.af_approx1(pointer(output.arr), signal.arr, pos0.arr, method, c_double(off_grid)))
+    return output
+
+def approx2(signal, pos0, pos1, method=AF_INTERP_LINEAR, off_grid=0.0):
+    output = array()
+    safe_call(clib.af_approx2(pointer(output.arr), signal.arr, \
+                              pos0.arr, pos1.arr, method, c_double(off_grid)))
+    return output
+
+def fft(signal, dim0 = None , scale = None):
+
+    if dim0 is None:
+        dim0 = 0
+
+    if scale is None:
+        scale = 1.0
+
+    output = array()
+    safe_call(clib.af_fft(pointer(output.arr), signal.arr, c_double(scale), c_longlong(dim0)))
+    return output
+
+def fft2(signal, dim0 = None, dim1 = None , scale = None):
+
+    if dim0 is None:
+        dim0 = 0
+
+    if dim1 is None:
+        dim1 = 0
+
+    if scale is None:
+        scale = 1.0
+
+    output = array()
+    safe_call(clib.af_fft2(pointer(output.arr), signal.arr, c_double(scale),\
+                           c_longlong(dim0), c_longlong(dim1)))
+    return output
+
+def fft3(signal, dim0 = None, dim1 = None , dim2 = None, scale = None):
+
+    if dim0 is None:
+        dim0 = 0
+
+    if dim1 is None:
+        dim1 = 0
+
+    if dim2 is None:
+        dim2 = 0
+
+    if scale is None:
+        scale = 1.0
+
+    output = array()
+    safe_call(clib.af_fft3(pointer(output.arr), signal.arr, c_double(scale),\
+                           c_longlong(dim0), c_longlong(dim1), c_longlong(dim2)))
+    return output
+
+def ifft(signal, dim0 = None , scale = None):
+
+    if dim0 is None:
+        dim0 = signal.dims()[0]
+
+    if scale is None:
+        scale = 1.0/float(dim0)
+
+    output = array()
+    safe_call(clib.af_ifft(pointer(output.arr), signal.arr, c_double(scale), c_longlong(dim0)))
+    return output
+
+def ifft2(signal, dim0 = None, dim1 = None , scale = None):
+
+    dims = signal.dims()
+
+    if (len(dims) < 2):
+        return ifft(signal)
+
+    if dim0 is None:
+        dim0 = dims[0]
+
+    if dim1 is None:
+        dim1 = dims[1]
+
+    if scale is None:
+        scale = 1.0/float(dim0 * dim1)
+
+    output = array()
+    safe_call(clib.af_ifft2(pointer(output.arr), signal.arr, c_double(scale),\
+                            c_longlong(dim0), c_longlong(dim1)))
+    return output
+
+def ifft3(signal, dim0 = None, dim1 = None , dim2 = None, scale = None):
+
+    dims = signal.dims()
+
+    if (len(dims) < 3):
+        return ifft2(signal)
+
+    if dim0 is None:
+        dim0 = dims[0]
+
+    if dim1 is None:
+        dim1 = dims[1]
+
+    if dim2 is None:
+        dim2 = dims[2]
+
+    if scale is None:
+        scale = 1.0 / float(dim0 * dim1 * dim2)
+
+    output = array()
+    safe_call(clib.af_ifft3(pointer(output.arr), signal.arr, c_double(scale),\
+                            c_longlong(dim0), c_longlong(dim1), c_longlong(dim2)))
+    return output
+
+def dft(signal, scale = None, odims=(None, None, None, None)):
+
+    odims4 = dim4_tuple(odims, default=None)
+
+    dims = signal.dims()
+    ndims = len(dims)
+
+    if (ndims == 1):
+        return fft(signal, scale, dims[0])
+    elif (ndims == 2):
+        return fft2(signal, scale, dims[0], dims[1])
+    else:
+        return fft3(signal, scale, dims[0], dims[1], dims[2])
+
+def idft(signal, scale = None, odims=(None, None, None, None)):
+
+    odims4 = dim4_tuple(odims, default=None)
+
+    dims = signal.dims()
+    ndims = len(dims)
+
+    if (ndims == 1):
+        return ifft(signal, scale, dims[0])
+    elif (ndims == 2):
+        return ifft2(signal, scale, dims[0], dims[1])
+    else:
+        return ifft3(signal, scale, dims[0], dims[1], dims[2])
+
+def convolve1(signal, kernel, conv_mode = AF_CONV_DEFAULT, conv_domain = AF_CONV_AUTO):
+    output = array()
+    safe_call(clib.af_convolve1(pointer(output.arr), signal.arr, kernel.arr, conv_mode, conv_domain))
+    return output
+
+def convolve2(signal, kernel, conv_mode = AF_CONV_DEFAULT, conv_domain = AF_CONV_AUTO):
+    output = array()
+    safe_call(clib.af_convolve2(pointer(output.arr), signal.arr, kernel.arr, conv_mode, conv_domain))
+    return output
+
+def convolve3(signal, kernel, conv_mode = AF_CONV_DEFAULT, conv_domain = AF_CONV_AUTO):
+    output = array()
+    safe_call(clib.af_convolve3(pointer(output.arr), signal.arr, kernel.arr, conv_mode, conv_domain))
+    return output
+
+def convolve(signal, kernel, conv_mode = AF_CONV_DEFAULT, conv_domain = AF_CONV_AUTO):
+    dims = signal.dims()
+    ndims = len(dims)
+
+    if (ndims == 1):
+        return convolve1(signal, kernel, conv_mode, conv_domain)
+    elif (ndims == 2):
+        return convolve2(signal, kernel, conv_mode, conv_domain)
+    else:
+        return convolve3(signal, kernel, conv_mode, conv_domain)
+
+def fft_convolve1(signal, kernel, conv_mode = AF_CONV_DEFAULT):
+    output = array()
+    safe_call(clib.af_fft_convolve1(pointer(output.arr), signal.arr, kernel.arr, conv_mode))
+    return output
+
+def fft_convolve2(signal, kernel, conv_mode = AF_CONV_DEFAULT):
+    output = array()
+    safe_call(clib.af_fft_convolve2(pointer(output.arr), signal.arr, kernel.arr, conv_mode))
+    return output
+
+def fft_convolve3(signal, kernel, conv_mode = AF_CONV_DEFAULT):
+    output = array()
+    safe_call(clib.af_fft_convolve3(pointer(output.arr), signal.arr, kernel.arr, conv_mode))
+    return output
+
+def fft_convolve(signal, kernel, conv_mode = AF_CONV_DEFAULT):
+    dims = signal.dims()
+    ndims = len(dims)
+
+    if (ndims == 1):
+        return fft_convolve1(signal, kernel, conv_mode)
+    elif (ndims == 2):
+        return fft_convolve2(signal, kernel, conv_mode)
+    else:
+        return fft_convolve3(signal, kernel, conv_mode)
+
+def fir(B, X):
+    Y = array()
+    safe_call(clib.af_fir(pointer(Y.arr), B.arr, X.arr))
+    return Y
+
+def iir(B, A, X):
+    Y = array()
+    safe_call(clib.af_iir(pointer(Y.arr), B.arr, A.arr, X.arr))
+    return Y
diff --git a/arrayfire/util.py b/arrayfire/util.py
index e7d3560..30095cd 100644
--- a/arrayfire/util.py
+++ b/arrayfire/util.py
@@ -8,6 +8,7 @@
 ########################################################
 
 from .library import *
+import numbers
 
 def dim4(d0=1, d1=1, d2=1, d3=1):
     c_dim4 = c_longlong * 4
@@ -18,9 +19,13 @@ def dim4(d0=1, d1=1, d2=1, d3=1):
 
     return out
 
-def dim4_tuple(dims):
+def dim4_tuple(dims, default=1):
     assert(isinstance(dims, tuple))
-    out = [1]*4
+
+    if (default is not None):
+        assert(isinstance(default, numbers.Number))
+
+    out = [default]*4
 
     for i, dim in enumerate(dims):
         out[i] = dim
diff --git a/tests/simple_signal.py b/tests/simple_signal.py
new file mode 100755
index 0000000..d1adb68
--- /dev/null
+++ b/tests/simple_signal.py
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+#######################################################
+# Copyright (c) 2014, 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
+
+a = af.randu(10, 1)
+pos0 = af.randu(10) * 10
+af.print_array(af.approx1(a, pos0))
+
+a = af.randu(3, 3)
+pos0 = af.randu(3, 3) * 10
+pos1 = af.randu(3, 3) * 10
+
+af.print_array(af.approx2(a, pos0, pos1))
+
+a = af.randu(8, 1)
+af.print_array(a)
+
+af.print_array(af.fft(a))
+af.print_array(af.dft(a))
+af.print_array(af.real(af.ifft(af.fft(a))))
+af.print_array(af.real(af.idft(af.dft(a))))
+
+a = af.randu(4, 4)
+af.print_array(a)
+
+af.print_array(af.fft2(a))
+af.print_array(af.dft(a))
+af.print_array(af.real(af.ifft2(af.fft2(a))))
+af.print_array(af.real(af.idft(af.dft(a))))
+
+a = af.randu(4, 4, 2)
+af.print_array(a)
+
+af.print_array(af.fft3(a))
+af.print_array(af.dft(a))
+af.print_array(af.real(af.ifft3(af.fft3(a))))
+af.print_array(af.real(af.idft(af.dft(a))))
+
+a = af.randu(10, 1)
+b = af.randu(3, 1)
+af.print_array(af.convolve1(a, b))
+af.print_array(af.fft_convolve1(a, b))
+af.print_array(af.convolve(a, b))
+af.print_array(af.fft_convolve(a, b))
+
+a = af.randu(5, 5)
+b = af.randu(3, 3)
+af.print_array(af.convolve2(a, b))
+af.print_array(af.fft_convolve2(a, b))
+af.print_array(af.convolve(a, b))
+af.print_array(af.fft_convolve(a, b))
+
+a = af.randu(5, 5, 3)
+b = af.randu(3, 3, 2)
+af.print_array(af.convolve3(a, b))
+af.print_array(af.fft_convolve3(a, b))
+af.print_array(af.convolve(a, b))
+af.print_array(af.fft_convolve(a, b))
+
+
+b = af.randu(3, 1)
+x = af.randu(10, 1)
+a = af.randu(2, 1)
+af.print_array(af.fir(b, x))
+af.print_array(af.iir(b, a, x))

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