- Main Page
- Data Structures
- Files
- Related Pages

# mexutils.h File Reference

MEX helper functions. More...

`#include "mex.h"`
`#include <ctype.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 opion 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 array with pre-allocated data.
static int | uIsScalar (const mxArray *A)
| Is the array a numeric scalar?
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, const int *dims)
| Is the array real with specified dimensions?
static int | uIsString (const mxArray *A, int L)
| Is the array a string?
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.

## Detailed Description

Author:
  Andrea Vedaldi

This module provides helper functions for MATLAB MEX files.

## 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.

## Typedef Documentation

typedef struct _uMexOption uMexOption

See also:
  _uMexOption

## 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.

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.

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.

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.

static int uIsRealArray | ( | const mxArray * | A,
|  | int | D,
|  | const 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 dimesion of the array.

Returns:
  test result.

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.

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.

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.

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

Parameters:

  | A | array to test.

An array is numeric and scalar if:

- It is numeric.
- It as only one element.

Returns:
  test result.

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.

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.

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 suppsed 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 exhausetd. In case of an error (e.g. unkown option) the function prints an error message and quits the MEX file.

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

Parameters:

  | s1 | fisrt string.
  | s2 | second string.

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