Image-CCV
view release on metacpan or search on metacpan
ccv-src/lib/ccv_internal.h view on Meta::CPAN
/**********************************************************
* C-based/Cached/Core Computer Vision Library
* Liu Liu, 2010-02-01
**********************************************************/
#ifndef GUARD_ccv_internal_h
#define GUARD_ccv_internal_h
static int _CCV_PRINT_COUNT __attribute__ ((unused)) = 0;
static int _CCV_PRINT_LOOP __attribute__ ((unused)) = 0;
/* simple utility functions */
#define ccv_descale(x, n) (((x) + (1 << ((n) - 1))) >> (n))
#define conditional_assert(x, expr) if ((x)) { assert(expr); }
#define MACRO_STRINGIFY(x) #x
#define UNROLL_PRAGMA0(x) MACRO_STRINGIFY(unroll x)
#define UNROLL_FOR0(x, s, ss, ...) _Pragma(UNROLL_PRAGMA0((ss))) for ((x) = 0; (x) < (s); (x)++) {
/* How to use this:
* unroll_for(i, the number of iterations, the number of unrolls)
* Or
* unroll_for(i, the number of iterations)
*/
#define unroll_for(x, s, ...) UNROLL_FOR0(x, s, ##__VA_ARGS__, s)
#define unroll_endfor }
#ifdef USE_OPENMP
#define OMP_PRAGMA0(x) MACRO_STRINGIFY(omp parallel for private(x) schedule(dynamic))
#define parallel_for(x, n) { int x; _Pragma(OMP_PRAGMA0(x)) for ((x) = 0; (x) < (n); (x)++) {
#define parallel_endfor } }
#define FOR_IS_PARALLEL (1)
#elif defined(USE_DISPATCH) // Convert from size_t to int such that we avoid unsigned, and keep it consistent with the rest of parallel_for
#define parallel_for(x, n) dispatch_apply((n), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(size_t _s_##x) { int x = (int)_s_##x; {
#define parallel_endfor }});
#define FOR_IS_PARALLEL (1)
#else
#define parallel_for(x, n) { int x; for ((x) = 0; (x) < (n); (x)++) {
#define parallel_endfor } }
#define FOR_IS_PARALLEL (0)
#endif
/* macro printf utilities */
#define PRINT(l, a, ...) \
do { \
if (CCV_CLI_OUTPUT_LEVEL_IS(l)) \
{ \
printf(a, ##__VA_ARGS__); \
fflush(stdout); \
} \
} while (0) // using do while (0) to force ; line end
#define FLUSH(l, a, ...) \
do { \
if (CCV_CLI_OUTPUT_LEVEL_IS(l)) \
{ \
for (_CCV_PRINT_LOOP = 0; _CCV_PRINT_LOOP < _CCV_PRINT_COUNT; _CCV_PRINT_LOOP++) \
printf("\b"); \
for (_CCV_PRINT_LOOP = 0; _CCV_PRINT_LOOP < _CCV_PRINT_COUNT; _CCV_PRINT_LOOP++) \
printf(" "); \
for (_CCV_PRINT_LOOP = 0; _CCV_PRINT_LOOP < _CCV_PRINT_COUNT; _CCV_PRINT_LOOP++) \
printf("\b"); \
_CCV_PRINT_COUNT = printf(a, ##__VA_ARGS__); \
fflush(stdout); \
} \
} while (0) // using do while (0) to force ; line end
/* the following macro enables the usage such as:
* ccv_object_return_if_cached(, db, dc, dd, ...);
* effectively, it only returns when db, dc and dd are all successfully retrieved from cache */
#define INTERNAL_GARBAGE_TYPEDEF_CONCATENATE_N(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,_51,_52,_53,...
(!(_1) || (((int*)(_1))[0] & CCV_GARBAGE)) && (!(_2) || (((int*)(_2))[0] & CCV_GARBAGE)) && (!(_3) || (((int*)(_3))[0] & CCV_GARBAGE)) && (!(_4) || (((int*)(_4))[0] & CCV_GARBAGE)) && (!(_5) || (((int*)(_5))[0] & CCV_GARBAGE)) && (!(_6) || (((int*)(...
#define INTERNAL_GARBAGE_TYPEDEF_CONCATENATE(...) INTERNAL_GARBAGE_TYPEDEF_CONCATENATE_N(__VA_ARGS__)
#define INTERNAL_EXPAND_RENEW_MATRIX_LINE_N(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,_51,_52,_53,_54...
(void)((_1) && (((int*)(_1))[0] &= ~CCV_GARBAGE));(void)((_2) && (((int*)(_2))[0] &= ~CCV_GARBAGE));(void)((_3) && (((int*)(_3))[0] &= ~CCV_GARBAGE));(void)((_4) && (((int*)(_4))[0] &= ~CCV_GARBAGE));(void)((_5) && (((int*)(_5))[0] &= ~CCV_GARBAGE))...
#define INTERNAL_EXPAND_RENEW_MATRIX_LINE(...) INTERNAL_EXPAND_RENEW_MATRIX_LINE_N(__VA_ARGS__)
#define INTERNAL_SEQ_PADDING_ZERO() 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
#define ccv_revive_object_if_cached(...) \
( run in 0.939 second using v1.01-cache-2.11-cpan-71847e10f99 )