[arrayfire] 61/408: FEAT: Adding function to get use_count of shared pointers

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:16 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 0672f56cfac6a3c13c72ac889ccaa237d5ad0e1b
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Tue Jun 30 11:03:33 2015 -0400

    FEAT: Adding function to get use_count of shared pointers
---
 include/af/array.h           |  9 +++++++++
 src/api/c/data.cpp           | 28 ++++++++++++++++++++++++++++
 src/backend/cpu/Array.hpp    |  6 ++++++
 src/backend/cuda/Array.hpp   |  6 ++++++
 src/backend/opencl/Array.hpp |  6 ++++++
 5 files changed, 55 insertions(+)

diff --git a/include/af/array.h b/include/af/array.h
index 8a9ab48..e77a53e 100644
--- a/include/af/array.h
+++ b/include/af/array.h
@@ -1270,6 +1270,15 @@ extern "C" {
     AFAPI af_err af_retain_array(af_array *out, const af_array in);
 
     /**
+       \ingroup method_mat
+       @{
+
+       Get the use count of `af_array`
+    */
+    AFAPI af_err af_get_data_ref_count(int *use_count, const af_array in);
+
+
+    /**
        Evaluate any expressions in the Array
     */
     AFAPI af_err af_eval(af_array in);
diff --git a/src/api/c/data.cpp b/src/api/c/data.cpp
index 08267be..183e69f 100644
--- a/src/api/c/data.cpp
+++ b/src/api/c/data.cpp
@@ -247,6 +247,34 @@ af_err af_copy_array(af_array *out, const af_array in)
     return AF_SUCCESS;
 }
 
+//Strong Exception Guarantee
+af_err af_get_data_ref_count(int *use_count, const af_array in)
+{
+    try {
+        ArrayInfo info = getInfo(in);
+        const af_dtype type = info.getType();
+
+        int res;
+        switch(type) {
+        case f32:   res = getArray<float   >(in).useCount(); break;
+        case c32:   res = getArray<cfloat  >(in).useCount(); break;
+        case f64:   res = getArray<double  >(in).useCount(); break;
+        case c64:   res = getArray<cdouble >(in).useCount(); break;
+        case b8:    res = getArray<char    >(in).useCount(); break;
+        case s32:   res = getArray<int     >(in).useCount(); break;
+        case u32:   res = getArray<uint    >(in).useCount(); break;
+        case u8:    res = getArray<uchar   >(in).useCount(); break;
+        case s64:   res = getArray<intl    >(in).useCount(); break;
+        case u64:   res = getArray<uintl   >(in).useCount(); break;
+        default:    TYPE_ERROR(1, type);
+        }
+        std::swap(*use_count, res);
+    }
+    CATCHALL
+    return AF_SUCCESS;
+}
+
+
 template<typename T>
 static inline af_array randn_(const af::dim4 &dims)
 {
diff --git a/src/backend/cpu/Array.hpp b/src/backend/cpu/Array.hpp
index fa0afd9..3b0ff6d 100644
--- a/src/backend/cpu/Array.hpp
+++ b/src/backend/cpu/Array.hpp
@@ -170,6 +170,12 @@ namespace cpu
             return data.get() + (withOffset ? offset : 0);
         }
 
+        int useCount() const
+        {
+            if (!isReady()) eval();
+            return data.use_count();
+        }
+
         TNJ::Node_ptr getNode() const;
 
         friend Array<T> createValueArray<T>(const af::dim4 &size, const T& value);
diff --git a/src/backend/cuda/Array.hpp b/src/backend/cuda/Array.hpp
index eaafd31..3616ebb 100644
--- a/src/backend/cuda/Array.hpp
+++ b/src/backend/cuda/Array.hpp
@@ -181,6 +181,12 @@ namespace cuda
             return data.get() + (withOffset ? offset : 0);
         }
 
+        int useCount() const
+        {
+            if (!isReady()) eval();
+            return data.use_count();
+        }
+
         operator Param<T>()
         {
             Param<T> out;
diff --git a/src/backend/opencl/Array.hpp b/src/backend/opencl/Array.hpp
index 658962f..a4ecd2c 100644
--- a/src/backend/opencl/Array.hpp
+++ b/src/backend/opencl/Array.hpp
@@ -162,6 +162,12 @@ namespace opencl
             return data.get();
         }
 
+        int useCount() const
+        {
+            if (!isReady()) eval();
+            return data.use_count();
+        }
+
         const dim_t getOffset() const
         {
             return offset;

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