Documentation - C API
generic.h File Reference

Generic (Preprocssor, library state, etc.) More...

#include "host.h"
#include "random.h"
#include <stdlib.h>
#include <stddef.h>
#include <time.h>
#include <assert.h>
#include <Windows.h>

Data Structures

struct  VlThreadSpecificState
 VLFeat thread state. More...
struct  VlState
 VLFeat global state. More...

Defines

#define VL_VERSION_STRING   "0.9.14"
 Library version string.
#define VL_ERR_MSG_LEN   1024
 Maximum length (in characters) of an error message.
Common operations
#define VL_MIN(x, y)   (((x)<(y))?(x):(y))
 Min operation.
#define VL_MAX(x, y)   (((x)>(y))?(x):(y))
 Max operation.
#define VL_SHIFT_LEFT(x, n)   (((n)>=0)?((x)<<(n)):((x)>>-(n)))
 Signed left shift operation.

Functions

Memory allocation
void vl_set_alloc_func (void *(*malloc_func)(size_t), void *(*realloc_func)(void *, size_t), void *(*calloc_func)(size_t, size_t), void(*free_func)(void *))
 Set memory allocation functions.
void * vl_malloc (size_t n)
 Call customizable malloc function.
void * vl_realloc (void *ptr, size_t n)
 Call customizable resize function.
void * vl_calloc (size_t n, size_t size)
 Call customizable calloc function.
void vl_free (void *ptr)
 Call customizable free function.
Measuring time
void vl_tic ()
 Reset processor time reference The function resets VLFeat TIC/TOC time reference.
double vl_toc ()
 Get elapsed time since tic.
double vl_get_cpu_time ()
 Get processor time.

Type identidifers for atomic data types

#define VL_TYPE_FLOAT   1
#define VL_TYPE_DOUBLE   2
#define VL_TYPE_INT8   3
#define VL_TYPE_UINT8   4
#define VL_TYPE_INT16   5
#define VL_TYPE_UINT16   6
#define VL_TYPE_INT32   7
#define VL_TYPE_UINT32   8
#define VL_TYPE_INT64   9
#define VL_TYPE_UINT64   10
typedef vl_uint32 vl_type
char const * vl_get_type_name (vl_type type)
 Get the name of a data type.
vl_size vl_get_type_size (vl_type type)
 Get data type size.

Library state and configuration

VlState _vl_state
 VLFeat global state.
VlStatevl_get_state ()
 Return VLFeat global state.
VlThreadSpecificStatevl_get_thread_specific_state ()
 Get VLFeat thread state.
void vl_lock_state ()
 Lock VLFeat state.
void vl_unlock_state ()
 Unlock VLFeat state.
VlThreadSpecificStatevl_thread_specific_state_new ()
void vl_thread_specific_state_delete (VlThreadSpecificState *self)
char const * vl_get_version_string ()
 Get version string.
char * vl_configuration_to_string_copy ()
 Human readable library configuration.
void vl_set_simd_enabled (vl_bool x)
 Toggle usage of SIMD instructions.
vl_bool vl_get_simd_enabled ()
 Are SIMD instructons enabled?
vl_bool vl_cpu_has_sse3 ()
 Check for SSE3 instruction set.
vl_bool vl_cpu_has_sse2 ()
 Check for SSE2 instruction set.
int vl_get_num_cpus ()
VlRandvl_get_rand ()
 Get the random number generator for this thread.

Error handling

#define VL_ERR_OK   0
#define VL_ERR_OVERFLOW   1
#define VL_ERR_ALLOC   2
#define VL_ERR_BAD_ARG   3
#define VL_ERR_IO   4
#define VL_ERR_EOF   5
#define VL_ERR_NO_MORE   5
int vl_get_last_error ()
 Get VLFeat last error code.
char const * vl_get_last_error_message ()
 Get VLFeat last error message.
int vl_set_last_error (int error, char const *errorMessage,...)
 Set last VLFeat error.

Logging

#define VL_PRINTF   (*vl_get_state()->printf_func)
 Call user-customizable printf function.
#define VL_PRINT   (*vl_get_state()->printf_func)
 Same as VL_PRINTF (legacy code)
typedef int(* printf_func_t )(char const *format,...)
 Customizable printf function pointer type.
void vl_set_printf_func (printf_func_t printf_func)
 Set printf function.

Detailed Description

Author:
Andrea Vedaldi

Define Documentation

#define VL_ERR_ALLOC   2

Resource allocation error

#define VL_ERR_BAD_ARG   3

Bad argument or illegal data error

#define VL_ERR_EOF   5

End-of-file or end-of-sequence error

#define VL_ERR_IO   4

Input/output error

#define VL_ERR_NO_MORE   5

End-of-sequence

Deprecated:
#define VL_ERR_OK   0

No error

#define VL_ERR_OVERFLOW   1

Buffer overflow error

#define VL_MAX (   x,
 
)    (((x)>(y))?(x):(y))
Parameters:
xvalue.
yvalue.
Returns:
the maximum of x and y.
#define VL_MIN (   x,
 
)    (((x)<(y))?(x):(y))
Parameters:
xvalue
yvalue
Returns:
the minimum of x and y.
#define VL_PRINTF   (*vl_get_state()->printf_func)

The function calls the user customizable printf.

#define VL_SHIFT_LEFT (   x,
 
)    (((n)>=0)?((x)<<(n)):((x)>>-(n)))

The macro is equivalent to the builtin << operator, but it supports negative shifts too.

Parameters:
xvalue.
nnumber of shift positions.
Returns:
x << n .
#define VL_TYPE_DOUBLE   2

double type

#define VL_TYPE_FLOAT   1

float type

#define VL_TYPE_INT16   5

vl_int16 type

#define VL_TYPE_INT32   7

vl_int32 type

#define VL_TYPE_INT64   9

vl_int64 type

#define VL_TYPE_INT8   3

vl_int8 type

#define VL_TYPE_UINT16   6

vl_uint16 type

#define VL_TYPE_UINT32   8

vl_uint32 type

#define VL_TYPE_UINT64   10

vl_uint64 type

#define VL_TYPE_UINT8   4

vl_uint8 type


Function Documentation

void * vl_calloc ( size_t  n,
size_t  size 
) [inline]
Parameters:
nsize of each element in byte.
sizesize of the array to allocate (number of elements).

The function calls the user-customizable calloc.

Returns:
result of the user-customizable calloc.
char* vl_configuration_to_string_copy ( )
Returns:
a new string with the library configuration.

The function returns a new string with a human readable rendition of the library configuration.

vl_bool vl_cpu_has_sse2 ( ) [inline]
Returns:
true if SSE2 is present.
vl_bool vl_cpu_has_sse3 ( ) [inline]
Returns:
true if SSE3 is present.
void vl_free ( void *  ptr) [inline]
Parameters:
ptrbuffer to free.

The function calls the user customizable free.

double vl_get_cpu_time ( )
Returns:
processor time.
See also:
vl_tic, vl_toc
int vl_get_last_error ( ) [inline]

The function returns the code of the last error generated by VLFeat.

Returns:
laste error code.
char const * vl_get_last_error_message ( ) [inline]

The function returns the message of the last error generated by VLFeat.

Returns:
last error message.
VlRand* vl_get_rand ( )
Returns:
random number generator.

The function returns a pointer to the random number genrator for this thread.

vl_bool vl_get_simd_enabled ( ) [inline]
Returns:
true is SIMD instructions are enabled.
VlState * vl_get_state ( ) [inline]

The function returns a pointer to VLFeat global state.

Returns:
pointer to the global state structure.
VlThreadSpecificState * vl_get_thread_specific_state ( ) [inline]

The function returns a pointer to VLFeat thread state.

Returns:
pointer to the thread state structure.
char const* vl_get_type_name ( vl_type  type) [inline]
Parameters:
typedata type.
Returns:
data name of the data type.

type is one of VL_TYPE_FLOAT, VL_TYPE_DOUBLE, VL_TYPE_INT8, VL_TYPE_INT16, VL_TYPE_INT32, VL_TYPE_INT64, VL_TYPE_UINT8, VL_TYPE_UINT16, VL_TYPE_UINT32, VL_TYPE_UINT64.

vl_size vl_get_type_size ( vl_type  type) [inline]
char const* vl_get_version_string ( )
Returns:
library version string
void vl_lock_state ( )

The function locks VLFeat global state mutex.

The mutex is recursive: locking multiple times from the same thread is a valid operations, but requires an equivalent number of calls to vl_unlock_state.

See also:
vl_unlock_state
void * vl_malloc ( size_t  n) [inline]
Parameters:
nnumber of bytes to allocate.

The function calls the user customizable malloc.

Returns:
result of malloc
void * vl_realloc ( void *  ptr,
size_t  n 
) [inline]
Parameters:
ptrbuffer to reallocate.
nnumber of bytes to allocate.

The function calls the user-customizable realloc.

Returns:
result of the user-customizable realloc.
void vl_set_alloc_func ( void *(*)(size_t)  malloc_func,
void *(*)(void *, size_t)  realloc_func,
void *(*)(size_t, size_t)  calloc_func,
void(*)(void *)  free_func 
)
Parameters:
malloc_funcpointer to malloc.
realloc_funcpointer to realloc.
calloc_funcpointer to calloc.
free_funcpointer to free.
int vl_set_last_error ( int  error,
char const *  errorMessage,
  ... 
)

The function sets the code and optionally the error message of the last encountered error. errorMessage is the message format. It uses the printf convention and is followed by the format arguments. The maximum lenght of the error message is given by VL_ERR_MSG_LEN (longer messages are truncated).

Passing NULL as errorMessage sets the error message to the empty string.

Parameters:
errorerror code.
errorMessageerror message format string.
...format string arguments.
Returns:
error code.
void vl_set_printf_func ( printf_func_t  printf_func)
Parameters:
printf_funcpointer to printf. Let print_func be NULL to disable printf.
void vl_set_simd_enabled ( vl_bool  x) [inline]
Parameters:
xtrue if SIMD instructions are used.

Notice that SIMD instructions are used only if the CPU model supports them. Note also that data alignment may restrict the use of such instructions.

See also:
vl_cpu_has_sse2(), vl_cpu_has_sse3(), etc.
void vl_tic ( )
See also:
vl_get_cpu_time, vl_toc.
double vl_toc ( )

The function returns the processor time elapsed since vl_tic was called last.

Remarks:
In multi-threaded applications, there is an independent timer for each execution thread.
On UNIX, this function uses the clock() system call. On Windows, it uses the QueryPerformanceCounter() system call, which is more accurate than clock() on this platform.
Returns:
elapsed time in seconds.
void vl_unlock_state ( )

The function unlocks VLFeat global state mutex.

See also:
vl_lock_state

Variable Documentation