-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathttRoutines.h
More file actions
46 lines (32 loc) · 774 Bytes
/
ttRoutines.h
File metadata and controls
46 lines (32 loc) · 774 Bytes
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
////////////////////////////////////////////////////////
// Seung-Chan Kim
// Since 2011
#ifndef TT_ROUTINES_H
#define TT_ROUTINES_H
#ifdef __cplusplus
// category based on http://docs.scipy.org/doc/numpy-1.10.0/reference/routines.html
namespace DD {
template <typename T>
inline void ShuffleArray(T* src, int sz)
{
for(int i=0; i<sz; i++)
{
int nPos = i + (rand() % (sz-i)); //Random remaining position
T temp = src[i];
src[i] = src[nPos];
src[nPos] = temp;
}
}
template <typename T>
inline void ShiftWithNew(T* arr, const T &n_val, int sz)
{
int i;
for(i=0; i< sz-1; i++)
{
arr[sz-1-i] = arr[sz-2-i];
}
arr[0] = n_val;
}
}
#endif /* __cplusplus */
#endif