Commit b52da5de authored by Antoine Merle's avatar Antoine Merle
Browse files

Add check for numeric type

parent cf7ae313
Pipeline #132165 passed with stages
in 23 seconds
......@@ -104,6 +104,7 @@ These create exceptions with id `${MEXNAME}:nargin`.
### Argument type
- `CHECK_NUMERIC(ARG)`, checks that argument `ARG` is of numeric type
- `CHECK_DOUBLE(ARG)`, checks that argument `ARG` is of `double` type
- `CHECK_INT8(ARG)`, checks that argument `ARG` is of `int8` type
- `CHECK_INT32(ARG)`, checks that argument `ARG` is of `int32` type
......
......@@ -14,6 +14,7 @@
/* Type checks */
# define CHECK_TYPE(ARG,ARGNAME,TYPE,CHECK) if (!CHECK(ARG)) mexErrMsgIdAndTxt(STR(MEXNAME)":inputType",STR(MEXNAME)" expects "ARGNAME" to be a "#TYPE" array but got %s instead",mxGetClassName(ARG))
# define CHECK_NUMERIC(ARG) CHECK_TYPE(ARG,#ARG,numeric,mxIsNumeric)
# define CHECK_DOUBLE(ARG) CHECK_TYPE(ARG,#ARG,double,mxIsDouble)
# define CHECK_INT8(ARG) CHECK_TYPE(ARG,#ARG,int8,mxIsInt8)
# define CHECK_INT32(ARG) CHECK_TYPE(ARG,#ARG,int32,mxIsInt32)
......
......@@ -86,13 +86,19 @@ classdef mexargs_test
case {'type','type_match'}
if strcmp(checkname,'type_match')
newtype = 'single'; % Assumes this only occurs for real
else
else
newtype = 'int32';
if ~ismember(checkval,{'real','double','single'})
if strcmp(checkval,'numeric')
newtype = 'cell';
elseif ~ismember(checkval,{'real','double','single'})
newtype = 'double';
end
end
args{iarg} = cast(args{iarg},newtype);
if strcmp(newtype,'cell')
args{iarg} = {args{iarg}};
else
args{iarg} = cast(args{iarg},newtype);
end
errorid = sprintf('%s:inputType',obj.fun);
case {'numel','ncols','nrows','scalar','scalar_or_empty'}
def = args{iarg};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment