GKlib/util.c
Go to the documentation of this file.
1 
11 #include <GKlib.h>
12 
13 
14 
15 /*************************************************************************
16 * This file randomly permutes the contents of an array.
17 * flag == 0, don't initialize perm
18 * flag == 1, set p[i] = i
19 **************************************************************************/
20 void gk_RandomPermute(size_t n, int *p, int flag)
21 {
22  gk_idx_t i, u, v;
23  int tmp;
24 
25  if (flag == 1) {
26  for (i=0; i<n; i++)
27  p[i] = i;
28  }
29 
30  for (i=0; i<n/2; i++) {
31  v = RandomInRange(n);
32  u = RandomInRange(n);
33  gk_SWAP(p[v], p[u], tmp);
34  }
35 }
36 
37 
38 /************************************************************************/
61 /************************************************************************/
62 void gk_array2csr(size_t n, size_t range, int *array, int *ptr, int *ind)
63 {
64  gk_idx_t i;
65 
66  gk_iset(range+1, 0, ptr);
67 
68  for (i=0; i<n; i++)
69  ptr[array[i]]++;
70 
71  /* Compute the ptr, ind structure */
72  MAKECSR(i, range, ptr);
73  for (i=0; i<n; i++)
74  ind[ptr[array[i]]++] = i;
75  SHIFTCSR(i, range, ptr);
76 }
77 
78 
79 
80 /*************************************************************************
81 * This function returns the log2(x)
82 **************************************************************************/
83 int gk_log2(int a)
84 {
85  gk_idx_t i;
86 
87  for (i=1; a > 1; i++, a = a>>1);
88  return i-1;
89 }
90 
91 
92 /*************************************************************************
93 * This function checks if the argument is a power of 2
94 **************************************************************************/
95 int gk_ispow2(int a)
96 {
97  return (a == (1<<gk_log2(a)));
98 }
99 
100 
101 /*************************************************************************
102 * This function returns the log2(x)
103 **************************************************************************/
104 float gk_flog2(float a)
105 {
106  return log(a)/log(2.0);
107 }
108 
ind
std::vector< int > ind
Definition: Slicing_stdvector_cxx11.cpp:1
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
log
const EIGEN_DEVICE_FUNC LogReturnType log() const
Definition: ArrayCwiseUnaryOps.h:128
gk_idx_t
ssize_t gk_idx_t
Definition: gk_types.h:22
gk_flog2
float gk_flog2(float a)
Definition: GKlib/util.c:104
gtsam::range
Double_ range(const Point2_ &p, const Point2_ &q)
Definition: slam/expressions.h:30
n
int n
Definition: BiCGSTAB_simple.cpp:1
gk_log2
int gk_log2(int a)
Definition: GKlib/util.c:83
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
SHIFTCSR
#define SHIFTCSR(i, n, a)
Definition: gk_macros.h:80
array
Definition: numpy.h:821
GKlib.h
gk_SWAP
#define gk_SWAP(a, b, tmp)
Definition: gk_macros.h:19
p
float * p
Definition: Tutorial_Map_using.cpp:9
RandomInRange
#define RandomInRange(u)
Definition: gk_macros.h:24
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
gk_ispow2
int gk_ispow2(int a)
Definition: GKlib/util.c:95
MAKECSR
#define MAKECSR(i, n, a)
Definition: gk_macros.h:73
gk_RandomPermute
void gk_RandomPermute(size_t n, int *p, int flag)
Definition: GKlib/util.c:20
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
gk_array2csr
void gk_array2csr(size_t n, size_t range, int *array, int *ptr, int *ind)
Converts an element-based set membership into a CSR-format set-based membership.
Definition: GKlib/util.c:62


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:18:23