# HG changeset patch # User Carnë Draug # Date 1473875644 -3600 # Node ID ca03f89e9f2a7be046c686629a4df2cb18be875b # Parent 541a20a4961cdb4dea49cc2983fd1415c3cc3719# Parent 9263b2889003a90f0a5480053e0254d4d9ba2d51 maint: merge away accidental head. diff -r 541a20a4961c -r ca03f89e9f2a libinterp/corefcn/mex.cc --- 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 (data); + else if (val.is_real_type ()) + return *static_cast (data); + else // Complex type, only return real part + return *static_cast (data); + } + else + return val.scalar_value (true); + } void *get_data (void) const { @@ -2834,8 +2851,6 @@ return static_cast (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) {