generic.h File Reference
Detailed Description
This module provides the following functionalities:
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 theprintf
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.
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.3" |
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_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_NO_MORE 5 |
#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_MAX | ( | x, | |||
y | ) | (((x)>(y))?(x):(y)) |
- Parameters:
-
x value. y value.
- Returns:
- the maximum of x and y.
Definition at line 211 of file generic.h.
Referenced by vl_irodrigues(), vl_mser_process(), vl_pgm_write_f(), vl_sift_calc_keypoint_descriptor(), vl_sift_calc_keypoint_orientations(), vl_sift_calc_raw_descriptor(), vl_sift_keypoint_init(), and vl_sift_new().
#define VL_MIN | ( | x, | |||
y | ) | (((x)<(y))?(x):(y)) |
- Parameters:
-
x value y value
- Returns:
- the minimum of x and y.
Definition at line 204 of file generic.h.
Referenced by vl_hikm_train(), vl_pgm_write_f(), vl_rand_set_state(), vl_sift_calc_keypoint_descriptor(), vl_sift_calc_keypoint_orientations(), vl_sift_calc_raw_descriptor(), vl_sift_keypoint_init(), vl_sift_new(), vl_sift_process_next_octave(), vl_string_copy(), vl_string_copy_sub(), vl_string_replace_wildcard(), and xmeans().
#define VL_PRINT | ( | string | ) | ((*vl_printf_func)(string)) |
- Parameters:
-
string string to print.
- Returns:
- results of the user-customizable
printf
.
#define VL_PRINTF (*vl_printf_func) |
- Parameters:
-
format format string. ... printf
variable arguments.
printf
.
- Returns:
- results of the user-customizable
printf
.
- Examples:
- /Users/brian/vlfeat/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 | ) | (((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 | ( | x | ) | VL_STRINGIFY_(x) |
#define VL_STRINGIFY_ | ( | x | ) | # x |
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).
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_INLINE void vl_free | ( | void * | ptr | ) |
- Parameters:
-
ptr buffer to free.
free
.
Definition at line 356 of file generic.h.
Referenced by _vl_dhog_with_gaussian_window(), alloc(), vl_aib_delete(), vl_aib_update_beta(), vl_dhog_delete(), vl_hikm_delete(), vl_ikm_delete(), vl_ikm_init_elkan(), vl_ikm_init_rand_data(), vl_ikm_train_elkan(), vl_ikm_train_lloyd(), vl_mser_delete(), vl_mser_ell_fit(), vl_mser_process(), vl_pgm_insert(), vl_pgm_read_new(), vl_pgm_read_new_f(), vl_pgm_write_f(), vl_sift_delete(), xdelete(), and xmeans().
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.
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.
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.
printf
.
- Returns:
- results of the user-customizable
printf
.
VL_INLINE void vl_swap_host_big_endianness_2 | ( | void * | dst, | |
void * | src | |||
) |
VL_INLINE void vl_swap_host_big_endianness_4 | ( | void * | dst, | |
void * | src | |||
) |
VL_INLINE void vl_swap_host_big_endianness_8 | ( | void * | dst, | |
void * | src | |||
) |
VL_EXPORT double vl_toc | ( | ) |
Variable Documentation
VL_EXPORT void*(* vl_calloc_func)(size_t, size_t) |
VL_EXPORT void(* vl_free_func)(void *) |
VL_EXPORT void*(* vl_malloc_func)(size_t) |
VL_EXPORT int(* vl_printf_func)(char const *format,...) |
VL_EXPORT void*(* vl_realloc_func)(void *, size_t) |