Mercurial > octave
changeset 22462:6cb7813e5b2f
Add new mxIsScalar function for MEX API.
* NEWS: Announce new function.
* mex.cc (mxArray_octave_value::is_scalar): New function.
* mex.cc (mxArray_matlab::is_scalar): New function.
* mex.cc (mxIsScalar): New API function which calls internal is_scalar.
* mexproto.h (mxIsScalar): Add new function prototype. Organize list of
prototypes to be clearer.
* mxarray.in.h (mxArray_base::is_scalar): Declare virtual function.
* mxarray.in.h (mxArray::is_scalar): Declare function which calls the is_scalar
member function based on the object type (octave_value or matlab).
author | Rik <rik@octave.org> |
---|---|
date | Sat, 10 Sep 2016 07:40:52 -0700 |
parents | cc4f31e8477f |
children | 913e812ef11d |
files | NEWS libinterp/corefcn/mex.cc libinterp/corefcn/mexproto.h libinterp/corefcn/mxarray.in.h |
diffstat | 4 files changed, 40 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Sat Sep 10 06:20:03 2016 -0700 +++ b/NEWS Sat Sep 10 07:40:52 2016 -0700 @@ -147,7 +147,8 @@ compiled in to debug versions of a MEX file, i.e., that are produced when the '-g' option is given to mex() or mkoctfile(). - ** Other new MEX API functions include mexEvalStringWithTrap. + ** Other new MEX API functions include mexEvalStringWithTrap, + mxIsScalar. ** Other new functions added in 4.2:
--- a/libinterp/corefcn/mex.cc Sat Sep 10 06:20:03 2016 -0700 +++ b/libinterp/corefcn/mex.cc Sat Sep 10 07:40:52 2016 -0700 @@ -305,6 +305,14 @@ int is_empty (void) const { return val.is_empty (); } + bool is_scalar (void) const + { + // Force dims and ndims to be cached. + get_dimensions (); + + return ndims == 2 && dims[0] == 1 && dims[1] == 1; + } + mxClassID get_class_id (void) const { id = mxUNKNOWN_CLASS; @@ -759,6 +767,11 @@ int is_empty (void) const { return get_number_of_elements () == 0; } + bool is_scalar (void) const + { + return ndims == 2 && dims[0] == 1 && dims[1] == 1; + } + mxClassID get_class_id (void) const { return id; } const char *get_class_name (void) const @@ -2688,6 +2701,12 @@ return ptr->is_empty (); } +bool +mxIsScalar (const mxArray *ptr) +{ + return ptr->is_scalar (); +} + // FIXME: Just plain odd thing to ask of a value. // Still, Octave is incompatible because it does not implement this. int
--- a/libinterp/corefcn/mexproto.h Sat Sep 10 06:20:03 2016 -0700 +++ b/libinterp/corefcn/mexproto.h Sat Sep 10 07:40:52 2016 -0700 @@ -79,16 +79,17 @@ extern OCTINTERP_API int mexCallMATLAB (int nargout, mxArray *argout[], int nargin, mxArray *argin[], const char *fname); - extern OCTINTERP_API mxArray * mexCallMATLABWithTrap (int nargout, mxArray *argout[], int nargin, mxArray *argin[], const char *fname); -extern OCTINTERP_API void mexSetTrapFlag (int flag); extern OCTINTERP_API int mexEvalString (const char *s); extern OCTINTERP_API mxArray * mexEvalStringWithTrap (const char *s); + +extern OCTINTERP_API void mexSetTrapFlag (int flag); + extern OCTINTERP_API void mexErrMsgTxt (const char *s); extern OCTINTERP_API void mexErrMsgIdAndTxt (const char *id, const char *s, ...); @@ -105,18 +106,21 @@ extern OCTINTERP_API int mexPutVariable (const char *space, const char *name, const mxArray *ptr); +extern OCTINTERP_API const mxArray *mexGet (double handle, + const char *property); +extern OCTINTERP_API int mexSet (double handle, const char *property, + mxArray *val); + extern OCTINTERP_API void mexMakeArrayPersistent (mxArray *ptr); extern OCTINTERP_API void mexMakeMemoryPersistent (void *ptr); -extern OCTINTERP_API int mexAtExit (void (*f) (void)); -extern OCTINTERP_API const mxArray *mexGet (double handle, - const char *property); +extern OCTINTERP_API void mexLock (void); +extern OCTINTERP_API void mexUnlock (void); + extern OCTINTERP_API int mexIsGlobal (const mxArray *ptr); extern OCTINTERP_API int mexIsLocked (void); -extern OCTINTERP_API void mexLock (void); -extern OCTINTERP_API int mexSet (double handle, const char *property, - mxArray *val); -extern OCTINTERP_API void mexUnlock (void); + +extern OCTINTERP_API int mexAtExit (void (*f) (void)); /* Floating point predicates. */ extern OCTINTERP_API int mxIsFinite (double v); @@ -202,8 +206,9 @@ /* Odd type+size+value predicate. */ extern OCTINTERP_API int mxIsLogicalScalarTrue (const mxArray *ptr); -/* Size predicate. */ +/* Size predicates. */ extern OCTINTERP_API int mxIsEmpty (const mxArray *ptr); +extern OCTINTERP_API bool mxIsScalar (const mxArray *ptr); /* Just plain odd thing to ask of a value. */ extern OCTINTERP_API int mxIsFromGlobalWS (const mxArray *ptr);
--- a/libinterp/corefcn/mxarray.in.h Sat Sep 10 06:20:03 2016 -0700 +++ b/libinterp/corefcn/mxarray.in.h Sat Sep 10 07:40:52 2016 -0700 @@ -214,6 +214,8 @@ virtual int is_empty (void) const = 0; + virtual bool is_scalar (void) const = 0; + virtual mxClassID get_class_id (void) const = 0; virtual const char *get_class_name (void) const = 0; @@ -421,6 +423,8 @@ int is_empty (void) const { return get_number_of_elements () == 0; } + bool is_scalar (void) const { return rep->is_scalar (); } + const char *get_name (void) const { return name; } void set_name (const char *name_arg);