[arrayfire] 34/84: Handle printing empty Arrays

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Jan 4 23:22:20 UTC 2016


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

ghisvail-guest pushed a commit to branch master
in repository arrayfire.

commit e94f03799decb1f3b4522797753c6f2e25989091
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date:   Wed Dec 16 14:24:07 2015 -0500

    Handle printing empty Arrays
---
 src/api/c/print.cpp | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/api/c/print.cpp b/src/api/c/print.cpp
index a5c178c..d2d9921 100644
--- a/src/api/c/print.cpp
+++ b/src/api/c/print.cpp
@@ -64,6 +64,22 @@ static void print(const char *exp, af_array arr, const int precision, std::ostre
     }
 
     const ArrayInfo info = getInfo(arr);
+
+    std::ios_base::fmtflags backup = os.flags();
+
+    os << "[" << info.dims() << "]\n";
+#ifndef NDEBUG
+    os <<"   Offsets: [" << info.offsets() << "]" << std::endl;
+    os <<"   Strides: [" << info.strides() << "]" << std::endl;
+#endif
+
+    // Handle empty array
+    if(info.elements() == 0) {
+        os << "<empty>" << std::endl;
+        os.flags(backup);
+        return;
+    }
+
     vector<T> data(info.elements());
 
     af_array arrT;
@@ -81,14 +97,6 @@ static void print(const char *exp, af_array arr, const int precision, std::ostre
         AF_CHECK(af_release_array(arrT));
     }
 
-    std::ios_base::fmtflags backup = os.flags();
-
-    os << "[" << info.dims() << "]\n";
-#ifndef NDEBUG
-    os <<"   Offsets: [" << info.offsets() << "]" << std::endl;
-    os <<"   Strides: [" << info.strides() << "]" << std::endl;
-#endif
-
     printer(os, &data.front(), infoT, infoT.ndims() - 1, precision);
 
     os.flags(backup);

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