shuffle-def.h
Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
00008 All rights reserved.
00009 
00010 This file is part of the VLFeat library and is made available under
00011 the terms of the BSD license (see the COPYING file).
00012 */
00013 
00019 #include "host.h"
00020 #include "random.h"
00021 #include <assert.h>
00022 
00023 #ifndef VL_SHUFFLE_prefix
00024 #error "VL_SHUFFLE_prefix must be defined"
00025 #endif
00026 
00027 #ifndef VL_SHUFFLE_array
00028 #ifndef VL_SHUFFLE_type
00029 #error "VL_SHUFFLE_type must be defined if VL_SHUFFLE_array is not"
00030 #endif
00031 #define VL_SHUFFLE_array VL_SHUFFLE_type*
00032 #endif
00033 
00034 #ifdef __DOXYGEN__
00035 #define VL_SHUFFLE_prefix  ShufflePrefix       
00036 #define VL_SHUFFLE_type    ShuffleType         
00037 #define VL_SHUFFLE_array   ShuffleType*        
00038 #endif
00039 
00040 /* ---------------------------------------------------------------- */
00041 
00042 #if ! defined(VL_SHUFFLE_swap) || defined(__DOXYGEN__)
00043 #define VL_SHUFFLE_swap VL_XCAT(VL_SHUFFLE_prefix, _swap)
00044 
00055 VL_INLINE void
00056 VL_SHUFFLE_swap
00057 (VL_SHUFFLE_array array,
00058  vl_uindex indexA,
00059  vl_uindex indexB)
00060 {
00061   VL_SHUFFLE_type t = array [indexA] ;
00062   array [indexA] = array [indexB] ;
00063   array [indexB] = t ;
00064 }
00065 
00066 /* VL_SHUFFLE_swap */
00067 #endif
00068 
00069 /* ---------------------------------------------------------------- */
00070 
00071 #if ! defined(VL_SHUFFLE_shuffle) || defined(__DOXYGEN__)
00072 #define VL_SHUFFLE_shuffle VL_XCAT(VL_SHUFFLE_prefix, _shuffle)
00073 
00082 VL_INLINE void
00083 VL_SHUFFLE_shuffle
00084 (VL_SHUFFLE_array array, vl_size size, VlRand * rand)
00085 {
00086   vl_uindex n = size ;
00087   while (n > 1) {
00088     vl_uindex k = vl_rand_uindex (rand, n) ;
00089     n -- ;
00090     VL_SHUFFLE_swap (array, n, k) ;
00091   }
00092 }
00093 
00094 /* VL_SHUFFLE_shuffle */
00095 #endif
00096 
00097 #undef VL_SHUFFLE_prefix
00098 #undef VL_SHUFFLE_swap
00099 #undef VL_SHUFFLE_shuffle
00100 #undef VL_SHUFFLE_type
00101 #undef VL_SHUFFLE_array


libvlfeat
Author(s): Andrea Vedaldi
autogenerated on Thu Jun 6 2019 20:25:51