Mercurial > octave
changeset 22484:9e90abc3718e
maint: Merge away accidental head.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 14 Sep 2016 10:54:53 -0700 |
parents | ea8d53084b06 (diff) 541a20a4961c (current diff) |
children | 8607bdc16206 |
files | |
diffstat | 2 files changed, 21 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/external.txi Wed Sep 14 18:52:26 2016 +0100 +++ b/doc/interpreter/external.txi Wed Sep 14 10:54:53 2016 -0700 @@ -615,8 +615,8 @@ rows and columns, but only a million nonzero elements. Therefore the number of rows by the number of columns in this case is more than two hundred times the maximum value that can be represented by an unsigned int. -The use of @code{numel} should therefore be avoided useless it is known -it won't overflow. +The use of @code{numel} should therefore be avoided unless it is known +that it will not overflow. Extreme care must be take with the elem method and the @qcode{"()"} operator, which perform basically the same function. The reason is that if a
--- a/libinterp/corefcn/mex.cc Wed Sep 14 18:52:26 2016 +0100 +++ b/libinterp/corefcn/mex.cc Wed Sep 14 10:54:53 2016 -0700 @@ -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) {