changeset 22483:ca03f89e9f2a

maint: merge away accidental head.
author Carnë Draug <carandraug@octave.org>
date Wed, 14 Sep 2016 18:54:04 +0100
parents 541a20a4961c (current diff) 9263b2889003 (diff)
children 8607bdc16206
files
diffstat 1 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/mex.cc	Wed Sep 14 18:52:26 2016 +0100
+++ b/libinterp/corefcn/mex.cc	Wed Sep 14 18:54:04 2016 +0100
@@ -378,8 +378,25 @@
   // Not allowed.
   void set_cell (mwIndex /*idx*/, mxArray * /*val*/) { request_mutation (); }
 
-  // FIXME: For sparse arrays, this should return the first non-zero value.
-  double get_scalar (void) const { return val.scalar_value (true); }
+  double get_scalar (void) const
+  {
+    if (val.is_sparse_type ())
+      {
+        // For sparse arrays, return the first non-zero value. 
+        void * data = val.mex_get_data (); 
+        if (data == NULL)
+          return 0.0;
+
+        if (val.is_bool_type ())
+          return *static_cast<bool *> (data);
+        else if (val.is_real_type ())
+          return *static_cast<double *> (data);
+        else  // Complex type, only return real part
+          return *static_cast<double *> (data);
+      }
+    else
+      return val.scalar_value (true);
+  }
 
   void *get_data (void) const
   {
@@ -2834,8 +2851,6 @@
   return static_cast<double *> (ptr->get_imag_data ());
 }
 
-// FIXME: For sparse arrays, mxGetScalar should return the first non-zero
-// element, rather than just the first element.
 double
 mxGetScalar (const mxArray *ptr)
 {