[arrayfire] 33/408: FEAT / TEST: Adding af::copy()

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:11 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 691f0d190406794ac178da45a62e1a11596437fc
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Wed Jun 24 10:08:01 2015 -0400

    FEAT / TEST: Adding af::copy()
---
 include/af/index.h    | 18 ++++++++++++++++++
 src/api/cpp/index.cpp | 18 ++++++++++++++++++
 test/assign.cpp       | 38 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/include/af/index.h b/include/af/index.h
index 8a05e6d..2957390 100644
--- a/include/af/index.h
+++ b/include/af/index.h
@@ -131,6 +131,24 @@ class AFAPI index {
 
 AFAPI array lookup(const array &in, const array &idx, const int dim = -1);
 
+///
+/// Copy the values of an input array based on index
+///
+/// \param[out] dst The destination array
+/// \param[in] src The source array
+/// \param[in] idx0 The first index
+/// \param[in] idx1 The second index (defaults to \ref af::span)
+/// \param[in] idx2 The third index (defaults to \ref af::span)
+/// \param[in] idx3 The fourth index (defaults to \ref af::span)
+/// \ingroup index_func_index
+///
+
+AFAPI void copy(array &dst, const array &src,
+                const index &idx0,
+                const index &idx1 = span,
+                const index &idx2 = span,
+                const index &idx3 = span);
+
 }
 #endif
 
diff --git a/src/api/cpp/index.cpp b/src/api/cpp/index.cpp
index 83ac93d..2b66dd6 100644
--- a/src/api/cpp/index.cpp
+++ b/src/api/cpp/index.cpp
@@ -23,6 +23,24 @@ array lookup(const array &in, const array &idx, const int dim)
     return array(out);
 }
 
+void copy(array &dst, const array &src,
+          const index &idx0,
+          const index &idx1,
+          const index &idx2,
+          const index &idx3)
+{
+    unsigned nd = dst.numdims();
+
+    af_index_t indices[] = {idx0.get(),
+                            idx1.get(),
+                            idx2.get(),
+                            idx3.get()};
+
+    af_array lhs = dst.get();
+    const af_array rhs = src.get();
+    AF_THROW(af_assign_gen(&lhs, lhs, nd, indices, rhs));
+}
+
 index::index() {
     impl.idx.seq = af_span;
     impl.isSeq = true;
diff --git a/test/assign.cpp b/test/assign.cpp
index 37bbac5..aa92079 100644
--- a/test/assign.cpp
+++ b/test/assign.cpp
@@ -771,8 +771,6 @@ TEST(ArrayAssign, CPP_ASSIGN_VECTOR_SEQ_2D)
     array a0 = a;
     array b = af::randu(len);
 
-    array idx = af::seq(st, en);
-
     a(af::seq(st, en)) = b;
 
     ASSERT_EQ(a.dims(0) , (dim_t)nx);
@@ -796,3 +794,39 @@ TEST(ArrayAssign, CPP_ASSIGN_VECTOR_SEQ_2D)
     delete[] h_a;
     delete[] h_b;
 }
+
+TEST(Assign, Copy)
+{
+    using af::array;
+
+    const int num = 20;
+    const int len = 10;
+    const int st = 3;
+    const int en = st + len - 1;
+
+    array a = af::randu(num, 1);
+    float *h_a0 = a.host<float>();
+
+    array b = af::randu(len);
+
+    float *d_ptr = a.device<float>();
+    af::copy(a, b, af::seq(st, en));
+
+    // Ensure that a still has same device pointer
+    ASSERT_EQ(d_ptr, a.device<float>());
+
+    float *h_a  =  a.host<float>();
+    float *h_b  =  b.host<float>();
+
+    for (int i = 0; i < num; i++) {
+        if (i >= st && i <= en) {
+            ASSERT_EQ(h_a[i], h_b[i - st]);
+        } else {
+            ASSERT_EQ(h_a[i], h_a0[i]);
+        }
+    }
+
+    delete[] h_a0;
+    delete[] h_a;
+    delete[] h_b;
+}

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