[arrayfire] 230/408: saveArray returns index of array

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:12:04 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 57449b0f91857c0fa9ed57ad535574d5fa4b78cb
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date:   Tue Aug 11 18:38:23 2015 -0400

    saveArray returns index of array
---
 include/af/util.h    |  7 +++++--
 src/api/c/stream.cpp | 28 ++++++++++++++++------------
 src/api/cpp/util.cpp |  7 ++++---
 3 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/include/af/util.h b/include/af/util.h
index ef8fbab..441a93e 100644
--- a/include/af/util.h
+++ b/include/af/util.h
@@ -39,9 +39,11 @@ namespace af
         \param[in] append is used to append to an existing file when true and create or
         overwrite an existing file when false
 
+        \returns index of the saved array in the file
+
         \ingroup stream_func_save
     */
-    AFAPI void saveArray(const char *key, const array &arr, const char *filename, const bool append = false);
+    AFAPI int saveArray(const char *key, const array &arr, const char *filename, const bool append = false);
 
     /**
         \param[in] filename is the path to the location on disk
@@ -149,6 +151,7 @@ extern "C" {
     AFAPI af_err af_print_array_p(const char *exp, const af_array arr, const int precision);
 
     /**
+        \param[out] index is the index location of the array in the file
         \param[in] key is an expression used as tag/key for the array during \ref readArray
         \param[in] arr is the array to be written
         \param[in] filename is the path to the location on disk
@@ -157,7 +160,7 @@ extern "C" {
 
         \ingroup stream_func_save
     */
-    AFAPI af_err af_save_array(const char* key, const af_array arr, const char *filename, const bool append);
+    AFAPI af_err af_save_array(int *index, const char* key, const af_array arr, const char *filename, const bool append);
 
     /**
         \param[out] out is the array read from index
diff --git a/src/api/c/stream.cpp b/src/api/c/stream.cpp
index d966699..1161703 100644
--- a/src/api/c/stream.cpp
+++ b/src/api/c/stream.cpp
@@ -27,7 +27,7 @@ using namespace detail;
 static const char sfv_char = STREAM_FORMAT_VERSION;
 
 template<typename T>
-static void save(const char *key, const af_array arr, const char *filename, const bool append = false)
+static int save(const char *key, const af_array arr, const char *filename, const bool append = false)
 {
     // (char     )   Version (Once)
     // (int      )   No. of Arrays (Once)
@@ -109,9 +109,11 @@ static void save(const char *key, const af_array arr, const char *filename, cons
     fs.write((char*)&odims, sizeof(intl) * 4);
     fs.write((char*)&data.front(), sizeof(T) * data.size());
     fs.close();
+
+    return n_arrays - 1;
 }
 
-af_err af_save_array(const char *key, const af_array arr, const char *filename, const bool append)
+af_err af_save_array(int *index, const char *key, const af_array arr, const char *filename, const bool append)
 {
     try {
         ARG_ASSERT(0, key != NULL);
@@ -119,19 +121,21 @@ af_err af_save_array(const char *key, const af_array arr, const char *filename,
 
         ArrayInfo info = getInfo(arr);
         af_dtype type = info.getType();
+        int id = -1;
         switch(type) {
-            case f32:   save<float>   (key, arr, filename, append);   break;
-            case c32:   save<cfloat>  (key, arr, filename, append);   break;
-            case f64:   save<double>  (key, arr, filename, append);   break;
-            case c64:   save<cdouble> (key, arr, filename, append);   break;
-            case b8:    save<char>    (key, arr, filename, append);   break;
-            case s32:   save<int>     (key, arr, filename, append);   break;
-            case u32:   save<unsigned>(key, arr, filename, append);   break;
-            case u8:    save<uchar>   (key, arr, filename, append);   break;
-            case s64:   save<intl>    (key, arr, filename, append);   break;
-            case u64:   save<uintl>   (key, arr, filename, append);   break;
+            case f32:   id = save<float>   (key, arr, filename, append);   break;
+            case c32:   id = save<cfloat>  (key, arr, filename, append);   break;
+            case f64:   id = save<double>  (key, arr, filename, append);   break;
+            case c64:   id = save<cdouble> (key, arr, filename, append);   break;
+            case b8:    id = save<char>    (key, arr, filename, append);   break;
+            case s32:   id = save<int>     (key, arr, filename, append);   break;
+            case u32:   id = save<unsigned>(key, arr, filename, append);   break;
+            case u8:    id = save<uchar>   (key, arr, filename, append);   break;
+            case s64:   id = save<intl>    (key, arr, filename, append);   break;
+            case u64:   id = save<uintl>   (key, arr, filename, append);   break;
             default:    TYPE_ERROR(1, type);
         }
+        std::swap(*index, id);
     }
     CATCHALL;
     return AF_SUCCESS;
diff --git a/src/api/cpp/util.cpp b/src/api/cpp/util.cpp
index 6ff144e..bccaa53 100644
--- a/src/api/cpp/util.cpp
+++ b/src/api/cpp/util.cpp
@@ -29,10 +29,11 @@ namespace af
         return;
     }
 
-    void saveArray(const char *key, const array &arr, const char *filename, const bool append)
+    int saveArray(const char *key, const array &arr, const char *filename, const bool append)
     {
-        AF_THROW(af_save_array(key, arr.get(), filename, append));
-        return;
+        int index = -1;
+        AF_THROW(af_save_array(&index, key, arr.get(), filename, append));
+        return index;
     }
 
     array readArray(const char *filename, const unsigned index)

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