-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlignmentRandomRepa.cpp
More file actions
147 lines (140 loc) · 3.25 KB
/
AlignmentRandomRepa.cpp
File metadata and controls
147 lines (140 loc) · 3.25 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "AlignmentRandomRepa.h"
#include <cstring>
#include <stdlib.h>
using namespace Alignment;
// historyRepasShuffle_u :: HistoryRepa -> Int -> HistoryRepa
std::unique_ptr<HistoryRepa> Alignment::historyRepasShuffle_u(const HistoryRepa& hr, unsigned s)
{
auto n = hr.dimension;
auto vv = hr.vectorVar;
auto sh = hr.shape;
auto z = hr.size;
auto rr = hr.arr;
auto hr1 = std::make_unique<HistoryRepa>();
if (!rr)
return hr1;
hr1->dimension = n;
hr1->vectorVar = new std::size_t[n];
auto vv1 = hr1->vectorVar;
hr1->shape = new std::size_t[n];
auto sh1 = hr1->shape;
for (std::size_t i = 0; i < n; i++)
{
vv1[i] = vv[i];
sh1[i] = sh[i];
}
hr1->size = z;
hr1->evient = hr.evient;
hr1->arr = new unsigned char[z*n];
auto rr1 = hr1->arr;
memcpy(rr1, rr, z*n);
srand(s);
if (hr.evient)
for (std::size_t j = z-1; j != 0; j--)
{
auto jn = j*n;
auto j1 = j+1;
for (std::size_t i = 0; i < n; i++)
{
auto k = rand() % j1;
auto kn = k*n;
auto x = rr1[kn + i];
rr1[kn + i] = rr1[jn + i];
rr1[jn + i] = x;
}
}
else
for (std::size_t i = 0; i < n; i++)
{
auto iz = i*z;
for (std::size_t j = z - 1; j != 0; j--)
{
auto k = rand() % (j + 1);
auto x = rr1[iz + k];
rr1[iz + k] = rr1[iz + j];
rr1[iz + j] = x;
}
}
return hr1;
}
std::unique_ptr<HistoryRepa> Alignment::historyRepasShuffle_us(const HistoryRepa& hr, std::ranlux48_base& generator)
{
auto n = hr.dimension;
auto vv = hr.vectorVar;
auto sh = hr.shape;
auto z = hr.size;
auto rr = hr.arr;
auto hr1 = std::make_unique<HistoryRepa>();
if (!rr)
return hr1;
hr1->dimension = n;
hr1->vectorVar = new std::size_t[n];
auto vv1 = hr1->vectorVar;
hr1->shape = new std::size_t[n];
auto sh1 = hr1->shape;
for (std::size_t i = 0; i < n; i++)
{
vv1[i] = vv[i];
sh1[i] = sh[i];
}
hr1->size = z;
hr1->evient = hr.evient;
hr1->arr = new unsigned char[z*n];
auto rr1 = hr1->arr;
memcpy(rr1, rr, z*n);
if (hr.evient)
for (std::size_t j = z-1; j != 0; j--)
{
auto jn = j*n;
auto j1 = j+1;
for (std::size_t i = 0; i < n; i++)
{
auto k = generator() % j1;
auto kn = k*n;
auto x = rr1[kn + i];
rr1[kn + i] = rr1[jn + i];
rr1[jn + i] = x;
}
}
else
for (std::size_t i = 0; i < n; i++)
{
auto iz = i*z;
for (std::size_t j = z - 1; j != 0; j--)
{
auto k = generator() % (j + 1);
auto x = rr1[iz + k];
rr1[iz + k] = rr1[iz + j];
rr1[iz + j] = x;
}
}
return hr1;
}
std::unique_ptr<HistorySparseArray> Alignment::historySparseArrayShuffle_us(const HistorySparseArray& hr, std::ranlux48_base& generator)
{
auto n = hr.capacity;
auto z = hr.size;
auto rr = hr.arr;
auto hr1 = std::make_unique<HistorySparseArray>();
if (!(n*z) || !rr)
return hr1;
hr1->capacity = n;
hr1->size = z;
hr1->arr = new std::size_t[z*n];
auto rr1 = hr1->arr;
memcpy(rr1, rr, z*n*sizeof(std::size_t));
for (std::size_t j = z-1; j != 0; j--)
{
auto jn = j*n;
auto j1 = j+1;
for (std::size_t i = 0; i < n; i++)
{
auto k = generator() % j1;
auto kn = k*n;
auto x = rr1[kn + i];
rr1[kn + i] = rr1[jn + i];
rr1[jn + i] = x;
}
}
return hr1;
}