[python-arrayfire] 140/250: FEAT: Adding support for arrays to save to and read from disk

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:41 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 aad0cd8223920d79c74cae4a47cd6700fe3385fa
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Wed Nov 11 10:40:19 2015 -0500

    FEAT: Adding support for arrays to save to and read from disk
---
 arrayfire/array.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/arrayfire/array.py b/arrayfire/array.py
index 509b0b2..82266ae 100644
--- a/arrayfire/array.py
+++ b/arrayfire/array.py
@@ -1070,4 +1070,69 @@ def display(a, precision=4):
     safe_call(backend.get().af_print_array_gen(name.encode('utf-8'),
                                                a.arr, ct.c_int(precision)))
 
+def save_array(key, a, filename, append=False):
+    """
+    Save an array to disk.
+
+    Parameters
+    ----------
+    key     : str
+            A name / key associated with the array
+
+    a       : af.Array
+            The array to be stored to disk
+
+    filename : str
+             Location of the data file.
+
+    append   : Boolean. optional. default: False.
+             If the file already exists, specifies if the data should be appended or overwritten.
+
+    Returns
+    ---------
+    index   : int
+            The index of the array stored in the file.
+    """
+    index = ct.c_int(-1)
+    safe_call(backend.get().af_save_array(ct.pointer(index),
+                                          key.encode('utf-8'),
+                                          a.arr,
+                                          filename.encode('utf-8'),
+                                          append))
+    return index.value
+
+def read_array(filename, index=None, key=None):
+    """
+    Read an array from disk.
+
+    Parameters
+    ----------
+
+    filename : str
+             Location of the data file.
+
+    index   : int. Optional. Default: None.
+            - The index of the array stored in the file.
+            - If None, key is used.
+
+    key     : str. Optional. Default: None.
+            - A name / key associated with the array
+            - If None, index is used.
+
+    Returns
+    ---------
+    """
+    assert((index is not None) or (key is not None))
+    out = Array()
+    if (index is not None):
+        safe_call(backend.get().af_read_array_index(ct.pointer(out.arr),
+                                                    filename.encode('utf-8'),
+                                                    index))
+    elif (key is not None):
+        safe_call(backend.get().af_read_array_key(ct.pointer(out.arr),
+                                                  filename.encode('utf-8'),
+                                                  key.encode('utf-8')))
+
+    return out
+
 from .algorithm import sum

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