C API

mexutils.h File Reference


Detailed Description

Author:
Andrea Vedaldi
This header file provides utility function that help writing MATLAB MEX files.

  • It is numeric.
  • It has DOUBLE storage class.
  • It has only a real component.
  • It is full.

Definition in file mexutils.h.

#include "mex.h"
#include <vl/generic.h>
#include <ctype.h>
#include <stdio.h>
#include <stdarg.h>

Go to the source code of this file.


Data Structures

struct  _uMexOption
 MEX option. More...

Defines

#define VL_USE_MATLAB_ENV
 Let VLFeat use MATLAB memory allocation/logging facilities.

Typedefs

typedef struct _uMexOption uMexOption
 MEX option type.

Functions

static mxArray * uCreateNumericArray (mwSize ndim, const mwSize *dims, mxClassID classid, void *data)
 Create array with pre-allocated data.
static mxArray * uCreateNumericMatrix (int M, int N, mxClassID classid, void *data)
 Create an array with pre-allocated data.
static mxArray * uCreateScalar (double x)
 Create a plain scalar.
static int uIsScalar (const mxArray *A)
 Is the array a numeric scalar?
static vl_bool uIsPlainArray (const mxArray *A)
 Is the array plain matrix?
static int uIsMatrix (const mxArray *A, int M, int N)
 Is the array a numeric matrix?
static int uIsVector (const mxArray *A, int N)
 Is the array a vector?
static int uIsReal (const mxArray *A)
 Is the array real?
static int uIsRealScalar (const mxArray *A)
 Is the array real and scalar?
static int uIsRealMatrix (const mxArray *A, int M, int N)
 Is the array a real matrix?
static int uIsRealVector (const mxArray *A, int N)
 Is the array a real vector?
static int uIsRealArray (const mxArray *A, int D, int *dims)
 Is the array real with specified dimensions?
static int uIsString (const mxArray *A, int L)
 Is the array a string?
void uErrMsgTxt (char const *format,...)
 Formatted mexErrMsgTxt().
static int uStrICmp (const char *s1, const char *s2)
 Case insensitive string comparison.
static int uNextOption (mxArray const *args[], int nargs, uMexOption const *options, int *next, mxArray const **optarg)
 Process next option.

Define Documentation

#define VL_USE_MATLAB_ENV

Value:

vl_set_alloc_func (mxMalloc, mxRealloc, mxCalloc, mxFree) ;   \
  vl_set_printf_func (mexPrintf) ;
This makes VLFeat use MATLAB version of the memory allocation and logging functions.

Definition at line 50 of file mexutils.h.


Typedef Documentation

typedef struct _uMexOption uMexOption

See also:
_uMexOption

Definition at line 449 of file mexutils.h.


Function Documentation

static mxArray* uCreateNumericArray ( mwSize  ndim,
const mwSize *  dims,
mxClassID  classid,
void *  data 
) [static]

Parameters:
ndim number of dimensions.
dims dimensions.
classid storage class ID.
data pre-allocated data.
If data is set to NULL, the data is allocated from the heap. If data is a buffer allocated by mxMalloc, then this buffer is used as data.

Returns:
new array.

Definition at line 70 of file mexutils.h.

static mxArray* uCreateNumericMatrix ( int  M,
int  N,
mxClassID  classid,
void *  data 
) [static]

Parameters:
M number of rows.
N number of columns.
classid class ID.
data pre-allocated data.
If data is set to NULL, the data is allocated from the heap. If data is a buffer allocated by mxMalloc, then this buffer is used as data.

Returns:
new array.

Definition at line 103 of file mexutils.h.

static mxArray* uCreateScalar ( double  x  )  [static]

Parameters:
x inital value.
Returns:
new array.

Definition at line 128 of file mexutils.h.

void uErrMsgTxt ( char const *  format,
  ... 
)

Parameters:
args Format string (for sprintf).
... format string arguments.

Definition at line 419 of file mexutils.h.

static int uIsMatrix ( const mxArray *  A,
int  M,
int  N 
) [static]

Parameters:
A array to test.
M number of rows.
N number of columns.
The array A satisfies the test if:
  • It is numeric.
  • It as two dimensions.
  • M < 0 or the number of rows is equal to M.
  • N < 0 or the number of columns is equal to N.

Returns:
test result.

Definition at line 225 of file mexutils.h.

Referenced by uIsVector().

static vl_bool uIsPlainArray ( const mxArray *  A  )  [static]

Parameters:
A array to test.
M number of rows.
N number of columns.
The array A satisfies the test if:

  • It is a plain matrix
  • M < 0 or the number of rows is equal to M.
  • N < 0 or the number of columns is equal to N.

Returns:
test result.

Definition at line 171 of file mexutils.h.

static int uIsReal ( const mxArray *  A  )  [static]

Parameters:
A array to test.
An array satisfies the test if:
  • The storage class is DOUBLE.
  • There is no imaginary part.

Returns:
test result.

Definition at line 268 of file mexutils.h.

Referenced by uIsRealScalar().

static int uIsRealArray ( const mxArray *  A,
int  D,
int *  dims 
) [static]

Parameters:
A array to check.
D number of dimensions.
dims dimensions.
The array A satisfies the test if:
  • It is real (see uIsReal()).
  • ndims < 0 or it has ndims dimensions and
    • for each element of dims, either that element is negative or it is equal to the corresponding dimension of the array.

Returns:
test result.

Definition at line 359 of file mexutils.h.

static int uIsRealMatrix ( const mxArray *  A,
int  M,
int  N 
) [static]

Parameters:
A array to test.
M number of rows.
N number of columns.
The array A satisfies the test if:
  • It is real (see uIsReal()).
  • It as two dimensions.
  • M < 0 or the number of rows is equal to M.
  • N < 0 or the number of columns is equal to N.

Returns:
test result.

Definition at line 311 of file mexutils.h.

Referenced by uIsRealVector().

static int uIsRealScalar ( const mxArray *  A  )  [static]

Parameters:
A array to test.
An array is real and scalar if:
  • It is real (see uIsReal()).
  • It as only one element.

Returns:
test result.

Definition at line 288 of file mexutils.h.

References uIsReal().

static int uIsRealVector ( const mxArray *  A,
int  N 
) [static]

Parameters:
A array to test.
N number of elements.
The array A satisfies the test if
  • It is a real matrix (see uIsRealMatrix()).
  • It has a singleton dimension.
  • N < 0 or the other dimension is equal to N.

Returns:
test result.

Definition at line 336 of file mexutils.h.

References uIsRealMatrix().

static int uIsScalar ( const mxArray *  A  )  [static]

Parameters:
A array to test.
An array is numeric and scalar if:
  • It is numeric.
  • It as exactly one element.

Returns:
test result.

Definition at line 148 of file mexutils.h.

static int uIsString ( const mxArray *  A,
int  L 
) [static]

Parameters:
A array to test.
L string length.
The array A satisfies the test if:
  • its storage class is CHAR;
  • it has two dimensions;
  • it has one row;
  • L < 0 or it has L columns.

Returns:
test result.

Definition at line 399 of file mexutils.h.

Referenced by uNextOption().

static int uIsVector ( const mxArray *  A,
int  N 
) [static]

Parameters:
A array to test.
N number of elements.
The array A satisfies the test if
  • It is a matrix (see uIsMatrix()).
  • It has a singleton dimension.
  • N < 0 or the other dimension is equal to N.

Returns:
test result.

Definition at line 249 of file mexutils.h.

References uIsMatrix().

static int uNextOption ( mxArray const *  args[],
int  nargs,
uMexOption const *  options,
int *  next,
mxArray const **  optarg 
) [static]

Parameters:
args MEX argument array.
nargs MEX argument array length.
options List of option definitions.
next Pointer to the next option (in and out).
optarg Pointer to the option optional argument (out).
The function scans the MEX driver arguments array args of nargs elements for the next option starting at location next.

This argument is supposed to be the name of an option (case insensitive). The option is looked up in the option table options and decoded as the value uMexOption::val. Furthermore, if uMexOption::has_arg is true, the next entry in the array args is assumed to be argument of the option and stored in optarg. Finally, next is advanced to point to the next option.

Returns:
the code of the option, or -1 if the argument list is exhausted. In case of an error (e.g. unknown option) the function prints an error message and quits the MEX file.

Definition at line 501 of file mexutils.h.

References _uMexOption::has_arg, _uMexOption::name, uIsString(), uStrICmp(), and _uMexOption::val.

static int uStrICmp ( const char *  s1,
const char *  s2 
) [static]

Parameters:
s1 first string.
s2 second string.
Returns:
0 if the strings are equal, >0 if the first string is greater (in lexicographical order) and <0 otherwise.

Definition at line 462 of file mexutils.h.

Referenced by uNextOption().