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 
ssize_t gk_idx_t
Definition: gk_types.h:22
#define gk_SWAP(a, b, tmp)
Definition: gk_macros.h:19
#define MAKECSR(i, n, a)
Definition: gk_macros.h:73
Definition: numpy.h:680
int n
EIGEN_DEVICE_FUNC const LogReturnType log() const
int gk_log2(int a)
Definition: GKlib/util.c:83
void gk_RandomPermute(size_t n, int *p, int flag)
Definition: GKlib/util.c:20
int gk_ispow2(int a)
Definition: GKlib/util.c:95
float gk_flog2(float a)
Definition: GKlib/util.c:104
std::vector< int > ind
Array< int, Dynamic, 1 > v
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
#define SHIFTCSR(i, n, a)
Definition: gk_macros.h:80
Double_ range(const Point2_ &p, const Point2_ &q)
#define RandomInRange(u)
Definition: gk_macros.h:24
float * p


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:40:43