generic.h File Reference


Detailed Description

This module provides the following functionalities:

See also:
http://predef.sourceforge.net/index.php

Error handling

Error handling uses the same style of the standard C library. Most functions return 0 when they succeed and -1 when they fail, and set the global variable vl_err_no with a code identifying the error occurred. This variable is never set on success and should be examined right after an error had occurred.

Heap allocation

VLFeat uses the vl_malloc(), vl_realloc(), vl_calloc() and vl_free() functions to allocate the heap. Normally these functions are mapped to the underlying standard C library implementations. However vl_set_alloc_func() can be used to map them to other implementations. For instance, in MATALB MEX files these functions are mapped to the MATLAB equivalent which has a garbage collection mechanism to cope with interruptions during execution.

Logging

VLFeat uses the macros VL_PRINT and VL_PRINTF to print progress or debug informations. These functions are normally mapped to the printf function of the underlying standard C library. However vl_set_printf_func() can be used to map it to a different implementation. For instance, in MATLAB MEX files this function is mapped to mexPrintf. Setting the function to NULL disables logging.

Author:
Andrea Vedaldi

Definition in file generic.h.

#include <stddef.h>
#include <time.h>
#include <assert.h>
#include "host.h"

Go to the source code of this file.


Logging

#define VL_PRINTF   (*vl_printf_func)
 Call user-customizable printf function.
#define VL_PRINT(string)   ((*vl_printf_func)(string))
 Call user-customizable printf function (no varags).
VL_EXPORT void vl_set_printf_func (int(*printf_func)(char const *str,...))
 Call user-customizable printf function.

Error handling

#define VL_ERR_MSG_LEN   1024
 The maximum length of an error description.
#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
VL_EXPORT int vl_err_no
 The number of the last error.
VL_EXPORT char vl_err_msg [VL_ERR_MSG_LEN+1]
 The description of the last error.

Defines

#define VL_VERSION_STRING   "0.9.2"
 Library version string.
#define VL_STRINGIFY_(x)   # x
 VL_STRINGIFY helper.
#define VL_STRINGIFY(x)   VL_STRINGIFY_(x)
 Convert to a string.
#define VL_LOG_OF_2   0.693147180559945
 Logarithm of 2 (math constant).
#define VL_PI   3.141592653589793
 Pi (math constant).
#define VL_EPSILON_F   1.19209290E-07F
 Single precision epsilon (math constant).
#define VL_EPSILON_D   2.220446049250313e-16
 Double precision epsilon (math constant).
#define VL_NAN_F   (vl_nan_f.value)
 Single NaN (not signaling).
#define VL_INFINITY_F   (vl_infinity_f.value)
 Single Infinity (not signaling).
#define VL_NAN_D   (vl_nan_d.value)
 Double NaN (not signaling).
#define VL_INFINITY_D   (vl_infinity_d.value)
 Double Infinity (not signaling).
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

VL_EXPORT char const * vl_get_version_string ()
 Get version string.
VL_EXPORT void vl_print_info ()
 Print information about the library.
Heap allocation
VL_EXPORT 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.
VL_INLINE void * vl_malloc (size_t n)
 Call customizable malloc function.
VL_INLINE void * vl_realloc (void *ptr, size_t n)
 Call customizable resize function.
VL_INLINE void * vl_calloc (size_t n, size_t size)
 Call customizable calloc function.
VL_INLINE void vl_free (void *ptr)
 Call customizable free function.
Measuring time
---------------------------------------------------------------

VL_EXPORT void vl_tic ()
 Set time reference.
VL_EXPORT double vl_toc ()
 Get time since reference.
Endianness detection and conversion
---------------------------------------------------------------

VL_INLINE void vl_swap_host_big_endianness_8 (void *dst, void *src)
 Host <-> big endian transformation for 8-bytes value.
VL_INLINE void vl_swap_host_big_endianness_4 (void *dst, void *src)
 Host <-> big endian transformation for 4-bytes value.
VL_INLINE void vl_swap_host_big_endianness_2 (void *dst, void *src)
 Host <-> big endian transformation for 2-bytes value.

Variables

VL_EXPORT int(* vl_printf_func )(char const *format,...)
 Customizable printf function pointer.
VL_EXPORT void *(* vl_malloc_func )(size_t)
 Customizable malloc function pointer.
VL_EXPORT void *(* vl_realloc_func )(void *, size_t)
 Customizable realloc function pointer.
VL_EXPORT void *(* vl_calloc_func )(size_t, size_t)
 Customizable calloc function pointer.
VL_EXPORT void(* vl_free_func )(void *)
 Customizable free function pointer.

Define Documentation

#define VL_EPSILON_D   2.220446049250313e-16

Difference of the smallest representable number greater than 1.0 and 1.0.

Definition at line 72 of file generic.h.

Referenced by vl_sift_calc_raw_descriptor().

#define VL_EPSILON_F   1.19209290E-07F

Difference of the smallest representable number greater than 1.0 and 1.0.

Definition at line 65 of file generic.h.

Referenced by normalize_histogram(), and vl_pgm_write_f().

#define VL_ERR_ALLOC   2

Resource allocation error

Definition at line 187 of file generic.h.

#define VL_ERR_BAD_ARG   3

Bad argument or illegal data error

Definition at line 188 of file generic.h.

Referenced by vl_pgm_read_new().

#define VL_ERR_EOF   5

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

Definition at line 190 of file generic.h.

Referenced by vl_sift_process_first_octave(), and vl_sift_process_next_octave().

#define VL_ERR_IO   4

Input/output error

Definition at line 189 of file generic.h.

#define VL_ERR_NO_MORE   5

End-of-sequence

Deprecated:

Definition at line 191 of file generic.h.

#define VL_ERR_OK   0

No error

Definition at line 185 of file generic.h.

Referenced by vl_sift_process_first_octave(), and vl_sift_process_next_octave().

#define VL_ERR_OVERFLOW   1

Buffer overflow error

Definition at line 186 of file generic.h.

#define VL_MAX ( x,
 )     (((x)>(y))?(x):(y))

#define VL_PRINT ( string   )     ((*vl_printf_func)(string))

Parameters:
string string to print.
This macro is the same as VL_PRINTF() and should be used when the variable list of arguments is empty.

Returns:
results of the user-customizable printf.

Definition at line 167 of file generic.h.

#define VL_PRINTF   (*vl_printf_func)

Parameters:
format format string.
... printf variable arguments.
The function calls the user customizable printf.

Returns:
results of the user-customizable printf.
Examples:
/Users/brian/vlmess/vl/generic.h.

Definition at line 155 of file generic.h.

Referenced by vl_aib_process(), vl_ikm_train(), vl_ikm_train_elkan(), vl_print_host_info(), vl_print_info(), and xmeans().

#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:
x value.
n number of shift positions.
Returns:
x << n .

Definition at line 222 of file generic.h.

Referenced by vl_sift_new(), vl_sift_process_first_octave(), and vl_sift_process_next_octave().

#define VL_STRINGIFY (  )     VL_STRINGIFY_(x)

Parameters:
x macro to convert to a string
For instance, the following fragment
 #define A x.y.z
 printf(VL_STRINGIFY(A)) ;
will print the string x.y.z.

Definition at line 40 of file generic.h.

#define VL_STRINGIFY_ (  )     # x

For internal use only.

See also:
VL_STRINGIFY

Definition at line 28 of file generic.h.


Function Documentation

VL_INLINE void * vl_calloc ( size_t  n,
size_t  size 
)

Parameters:
n size of each element in byte.
size size of the array to allocate (number of elements).
The function calls the user-customizable calloc.

Returns:
result of the user-customizable calloc.

Definition at line 350 of file generic.h.

References vl_calloc_func.

Referenced by vl_mser_new().

VL_EXPORT char const* vl_get_version_string (  ) 

---------------------------------------------------------------

Returns:
library version string

Definition at line 236 of file generic.c.

References VL_VERSION_STRING.

Referenced by vl_print_info().

VL_INLINE void * vl_malloc ( size_t  n  ) 

---------------------------------------------------------------

Parameters:
n number of bytes to allocate.
The function calls the user customizable malloc.

Returns:
result of malloc

Definition at line 338 of file generic.h.

References vl_malloc_func.

Referenced by _vl_dhog_new_kernel(), alloc(), vl_aib_new(), vl_aib_new_nodelist(), vl_aib_new_Pc(), vl_aib_new_Px(), vl_aib_update_beta(), vl_dhog_new(), vl_hikm_copy_subset(), vl_hikm_new(), vl_ikm_init_elkan(), vl_ikm_init_rand_data(), vl_ikm_new(), vl_ikm_train_elkan(), vl_ikm_train_lloyd(), vl_mser_ell_fit(), vl_mser_new(), vl_mser_process(), vl_pgm_insert(), vl_pgm_read_new(), vl_pgm_read_new_f(), vl_pgm_write_f(), vl_sift_detect(), vl_sift_new(), and xmeans().

VL_EXPORT void vl_print_info (  ) 

Returns:
library version string

Definition at line 247 of file generic.c.

References vl_get_version_string(), vl_print_host_info(), and VL_PRINTF.

VL_INLINE void * vl_realloc ( void *  ptr,
size_t  n 
)

Parameters:
ptr buffer to reallocate.
n number of bytes to allocate.
The function calls the user-customizable realloc.

Returns:
result of the user-customizable realloc.

Definition at line 344 of file generic.h.

References vl_realloc_func.

Referenced by vl_sift_detect().

VL_EXPORT 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_func pointer to malloc.
realloc_func pointer to realloc.
calloc_func pointer to calloc.
free_func pointer to free.

Definition at line 325 of file generic.c.

References vl_calloc_func, vl_free_func, vl_malloc_func, and vl_realloc_func.

VL_EXPORT void vl_set_printf_func ( int(*)(char const *str,...)  printf_func  ) 

Parameters:
format format string.
... printf variable arguments.
The function calls the user customizable printf.

Returns:
results of the user-customizable printf.

VL_INLINE void vl_swap_host_big_endianness_2 ( void *  dst,
void *  src 
)

Parameters:
dst destination 2-byte buffer.
src source 2-byte bufffer.
See also:
Endianness.

Definition at line 318 of file generic.h.

VL_INLINE void vl_swap_host_big_endianness_4 ( void *  dst,
void *  src 
)

Parameters:
dst destination 4-byte buffer.
src source 4-byte bufffer.
See also:
Endianness.

Definition at line 292 of file generic.h.

VL_INLINE void vl_swap_host_big_endianness_8 ( void *  dst,
void *  src 
)

Parameters:
dst destination 8-byte buffer.
src source 8-byte bufffer.
See also:
Endianness.

Definition at line 258 of file generic.h.

VL_EXPORT double vl_toc (  ) 

Returns the processor time elapsed since vl_tic() was called.

Returns:
time in seconds.

Definition at line 368 of file generic.c.


Variable Documentation

VL_EXPORT void*(* vl_calloc_func)(size_t, size_t)

For internal use only.

Referenced by vl_calloc(), and vl_set_alloc_func().

VL_EXPORT void(* vl_free_func)(void *)

For internal use only.

Referenced by vl_set_alloc_func().

VL_EXPORT void*(* vl_malloc_func)(size_t)

For internal use only.

Referenced by vl_malloc(), and vl_set_alloc_func().

VL_EXPORT int(* vl_printf_func)(char const *format,...)

For internal use only.

Referenced by vl_set_printf_func().

VL_EXPORT void*(* vl_realloc_func)(void *, size_t)

For internal use only.

Referenced by vl_realloc(), and vl_set_alloc_func().