[arrayfire] 227/408: FEAT: adding complex support for exp

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:12:03 UTC 2015


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

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

commit 77c31e6db47f7319b8a41e0ed345f8780c4020a5
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Tue Aug 11 12:03:19 2015 -0400

    FEAT: adding complex support for exp
---
 src/api/c/unary.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/src/api/c/unary.cpp b/src/api/c/unary.cpp
index 6062e13..3970128 100644
--- a/src/api/c/unary.cpp
+++ b/src/api/c/unary.cpp
@@ -19,6 +19,9 @@
 #include <backend.hpp>
 #include <unary.hpp>
 #include <implicit.hpp>
+#include <complex.hpp>
+#include <cast.hpp>
+#include <arith.hpp>
 
 using namespace detail;
 
@@ -85,7 +88,6 @@ UNARY(round)
 UNARY(floor)
 UNARY(ceil)
 
-UNARY(exp)
 UNARY(sigmoid)
 UNARY(expm1)
 UNARY(erf)
@@ -102,6 +104,50 @@ UNARY(cbrt)
 UNARY(tgamma)
 UNARY(lgamma)
 
+template<typename Tc, typename Tr>
+af_array expCplx(const af_array a)
+{
+    Array<Tc> In = getArray<Tc>(a);
+    Array<Tr> Real = real<Tr, Tc>(In);
+    Array<Tr> Imag = imag<Tr, Tc>(In);
+
+    Array<Tr> ExpReal = unaryOp<Tr, af_exp_t>(Real);
+    Array<Tr> CosImag = unaryOp<Tr, af_cos_t>(Imag);
+    Array<Tr> SinImag = unaryOp<Tr, af_sin_t>(Imag);
+
+    Array<Tc> Unit  = cplx<Tc, Tr>(CosImag, SinImag, CosImag.dims());
+    Array<Tc> Scale = cast<Tc, Tr>(ExpReal);
+
+    Array<Tc> Result = arithOp<Tc, af_mul_t>(Scale, Unit, Scale.dims());
+
+    return getHandle(Result);
+}
+
+af_err af_exp(af_array *out, const af_array in)
+{
+    try {
+
+        ArrayInfo in_info = getInfo(in);
+        af_dtype in_type = in_info.getType();
+        af_array res;
+
+        // Convert all inputs to floats / doubles
+        af_dtype type = implicit(in_type, f32);
+
+        switch (type) {
+        case f32 : res = unaryOp<float  , af_exp_t>(in); break;
+        case f64 : res = unaryOp<double , af_exp_t>(in); break;
+        case c32 : res = expCplx<cfloat , float >(in); break;
+        case c64 : res = expCplx<cdouble, double>(in); break;
+        default:
+            TYPE_ERROR(1, in_type); break;
+        }
+
+        std::swap(*out, res);
+    }
+    CATCHALL;
+    return AF_SUCCESS;
+}
 
 af_err af_not(af_array *out, const af_array in)
 {

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



More information about the debian-science-commits mailing list