[python-arrayfire] 20/250: Adding all functions from arith.h
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:26 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 99c6ceec8a2e2b7923cbda24c8800bdc4457f4a4
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Mon Jun 22 13:11:35 2015 -0400
Adding all functions from arith.h
---
arrayfire/__init__.py | 1 +
arrayfire/arith.py | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++
arrayfire/array.py | 1 +
arrayfire/util.py | 2 +-
tests/simple_arith.py | 66 ++++++++++++++++++
5 files changed, 253 insertions(+), 1 deletion(-)
diff --git a/arrayfire/__init__.py b/arrayfire/__init__.py
index 816cae2..e44a77f 100644
--- a/arrayfire/__init__.py
+++ b/arrayfire/__init__.py
@@ -4,3 +4,4 @@ from .util import *
from .algorithm import *
from .device import *
from .blas import *
+from .arith import *
diff --git a/arrayfire/arith.py b/arrayfire/arith.py
new file mode 100644
index 0000000..3ccf4ad
--- /dev/null
+++ b/arrayfire/arith.py
@@ -0,0 +1,184 @@
+from .library import *
+from .array import *
+
+def arith_binary_func(lhs, rhs, c_func):
+ out = array()
+
+ is_left_array = isinstance(lhs, array)
+ is_right_array = isinstance(rhs, array)
+
+ if not (is_left_array or is_right_array):
+ TypeError("Atleast one input needs to be of type arrayfire.array")
+
+ elif (is_left_array and is_right_array):
+ safe_call(c_func(pointer(out.arr), lhs.arr, rhs.arr, False))
+
+ elif (is_valid_scalar(rhs)):
+ ldims = dim4_tuple(lhs.dims())
+ lty = lhs.type()
+ other = array()
+ other.arr = constant_array(rhs, ldims[0], ldims[1], ldims[2], ldims[3], lty)
+ safe_call(c_func(pointer(out.arr), lhs.arr, other.arr, False))
+
+ else:
+ rdims = dim4_tuple(rhs.dims())
+ rty = rhs.type()
+ other = array()
+ other.arr = constant_array(lhs, rdims[0], rdims[1], rdims[2], rdims[3], rty)
+ safe_call(c_func(pointer(out.arr), lhs.arr, other.arr, False))
+
+ return out
+
+def arith_unary_func(a, c_func):
+ out = array()
+ safe_call(c_func(pointer(out.arr), a.arr))
+ return out
+
+def cast(a, dtype=f32):
+ out=array()
+ safe_call(clib.af_cast(pointer(out.arr), a.arr, dtype))
+ return out
+
+def minof(lhs, rhs):
+ return arith_binary_func(lhs, rhs, clib.af_minof)
+
+def maxof(lhs, rhs):
+ return arith_binary_func(lhs, rhs, clib.af_maxof)
+
+def rem(lhs, rhs):
+ return arith_binary_func(lhs, rhs, clib.af_rem)
+
+def abs(a):
+ return arith_unary_func(a, clib.af_abs)
+
+def arg(a):
+ return arith_unary_func(a, clib.af_arg)
+
+def sign(a):
+ return arith_unary_func(a, clib.af_sign)
+
+def round(a):
+ return arith_unary_func(a, clib.af_round)
+
+def trunc(a):
+ return arith_unary_func(a, clib.af_trunc)
+
+def floor(a):
+ return arith_unary_func(a, clib.af_floor)
+
+def ceil(a):
+ return arith_unary_func(a, clib.af_ceil)
+
+def hypot(lhs, rhs):
+ return arith_binary_func(lhs, rhs, clib.af_hypot)
+
+def sin(a):
+ return arith_unary_func(a, clib.af_sin)
+
+def cos(a):
+ return arith_unary_func(a, clib.af_cos)
+
+def tan(a):
+ return arith_unary_func(a, clib.af_tan)
+
+def asin(a):
+ return arith_unary_func(a, clib.af_asin)
+
+def acos(a):
+ return arith_unary_func(a, clib.af_acos)
+
+def atan(a):
+ return arith_unary_func(a, clib.af_atan)
+
+def atan2(lhs, rhs):
+ return arith_binary_func(lhs, rhs, clib.af_atan2)
+
+def cplx(lhs, rhs=None):
+ if rhs is None:
+ return arith_unary_func(lhs, clib.af_cplx)
+ else:
+ return arith_binary_func(lhs, rhs, clib.af_cplx2)
+
+def real(lhs):
+ return arith_unary_func(lhs, clib.af_real)
+
+def imag(lhs):
+ return arith_unary_func(lhs, clib.af_imag)
+
+def conjg(lhs):
+ return arith_unary_func(lhs, clib.af_conjg)
+
+def sinh(a):
+ return arith_unary_func(a, clib.af_sinh)
+
+def cosh(a):
+ return arith_unary_func(a, clib.af_cosh)
+
+def tanh(a):
+ return arith_unary_func(a, clib.af_tanh)
+
+def asinh(a):
+ return arith_unary_func(a, clib.af_asinh)
+
+def acosh(a):
+ return arith_unary_func(a, clib.af_acosh)
+
+def atanh(a):
+ return arith_unary_func(a, clib.af_atanh)
+
+def root(lhs, rhs):
+ return arith_binary_func(lhs, rhs, clib.af_root)
+
+def pow(lhs, rhs):
+ return arith_binary_func(lhs, rhs, clib.af_pow)
+
+def pow2(a):
+ return arith_unary_func(a, clib.af_pow2)
+
+def exp(a):
+ return arith_unary_func(a, clib.af_exp)
+
+def expm1(a):
+ return arith_unary_func(a, clib.af_expm1)
+
+def erf(a):
+ return arith_unary_func(a, clib.af_erf)
+
+def erfc(a):
+ return arith_unary_func(a, clib.af_erfc)
+
+def log(a):
+ return arith_unary_func(a, clib.af_log)
+
+def log1p(a):
+ return arith_unary_func(a, clib.af_log1p)
+
+def log10(a):
+ return arith_unary_func(a, clib.af_log10)
+
+def log2(a):
+ return arith_unary_func(a, clib.af_log2)
+
+def sqrt(a):
+ return arith_unary_func(a, clib.af_sqrt)
+
+def cbrt(a):
+ return arith_unary_func(a, clib.af_cbrt)
+
+def factorial(a):
+ return arith_unary_func(a, clib.af_factorial)
+
+def tgamma(a):
+ return arith_unary_func(a, clib.af_tgamma)
+
+def lgamma(a):
+ return arith_unary_func(a, clib.af_lgamma)
+
+def iszero(a):
+ return arith_unary_func(a, clib.af_iszero)
+
+def isinf(a):
+ return arith_unary_func(a, clib.af_isinf)
+
+def isnan(a):
+ return arith_unary_func(a, clib.af_isnan)
diff --git a/arrayfire/array.py b/arrayfire/array.py
index 13c2c57..f20f34f 100644
--- a/arrayfire/array.py
+++ b/arrayfire/array.py
@@ -1,4 +1,5 @@
import array as host
+import inspect
from .library import *
from .util import *
from .data import *
diff --git a/arrayfire/util.py b/arrayfire/util.py
index dbb5047..01d0020 100644
--- a/arrayfire/util.py
+++ b/arrayfire/util.py
@@ -29,4 +29,4 @@ def safe_call(af_error):
c_err_str = c_char_p(0)
c_err_len = c_longlong(0)
clib.af_get_last_error(pointer(c_err_str), pointer(c_err_len))
- raise RuntimeError('test', to_str(c_err_str), af_error)
+ raise RuntimeError(to_str(c_err_str), af_error)
diff --git a/tests/simple_arith.py b/tests/simple_arith.py
index f1a8764..3ea85d2 100644
--- a/tests/simple_arith.py
+++ b/tests/simple_arith.py
@@ -113,3 +113,69 @@ af.print_array(-a)
af.print_array(+a)
af.print_array(~a)
af.print_array(a)
+
+af.print_array(af.cast(a, af.c32))
+af.print_array(af.maxof(a,b))
+af.print_array(af.minof(a,b))
+af.print_array(af.rem(a,b))
+
+a = af.randu(3,3) - 0.5
+b = af.randu(3,3) - 0.5
+
+af.print_array(af.abs(a))
+af.print_array(af.arg(a))
+af.print_array(af.sign(a))
+af.print_array(af.round(a))
+af.print_array(af.trunc(a))
+af.print_array(af.floor(a))
+af.print_array(af.ceil(a))
+af.print_array(af.hypot(a, b))
+af.print_array(af.sin(a))
+af.print_array(af.cos(a))
+af.print_array(af.tan(a))
+af.print_array(af.asin(a))
+af.print_array(af.acos(a))
+af.print_array(af.atan(a))
+af.print_array(af.atan2(a, b))
+
+c = af.cplx(a)
+d = af.cplx(a,b)
+af.print_array(c)
+af.print_array(d)
+af.print_array(af.real(d))
+af.print_array(af.imag(d))
+af.print_array(af.conjg(d))
+
+af.print_array(af.sinh(a))
+af.print_array(af.cosh(a))
+af.print_array(af.tanh(a))
+af.print_array(af.asinh(a))
+af.print_array(af.acosh(a))
+af.print_array(af.atanh(a))
+
+a = af.abs(a)
+b = af.abs(b)
+
+af.print_array(af.root(a, b))
+af.print_array(af.pow(a, b))
+af.print_array(af.pow2(a))
+af.print_array(af.exp(a))
+af.print_array(af.expm1(a))
+af.print_array(af.erf(a))
+af.print_array(af.erfc(a))
+af.print_array(af.log(a))
+af.print_array(af.log1p(a))
+af.print_array(af.log10(a))
+af.print_array(af.log2(a))
+af.print_array(af.sqrt(a))
+af.print_array(af.cbrt(a))
+
+a = af.round(5 * af.randu(3,3) - 1)
+b = af.round(5 * af.randu(3,3) - 1)
+
+af.print_array(af.factorial(a))
+af.print_array(af.tgamma(a))
+af.print_array(af.lgamma(a))
+af.print_array(af.iszero(a))
+af.print_array(af.isinf(a/b))
+af.print_array(af.isnan(a/a))
--
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