26 struct ComparePair :
public std::unary_function<std::pair<int32, int32>, bool>
28 explicit ComparePair(
const std::pair<int32, int32> &correct_pair):
37 public std::unary_function<std::pair<int32, int32>, bool>
43 if (pair_.first == arg.first)
44 return pair_.second == arg.second;
51 std::vector<std::vector<std::pair<int32, int32> > > vec_vec_pair) {
52 std::ostringstream ostream;
53 for (
int32 i = 0;
i < vec_vec_pair.size();
i++) {
54 for (
int32 j = 0;
j < vec_vec_pair[
i].size();
j++) {
55 ostream <<
"(" << vec_vec_pair[
i][
j].first <<
"," 56 << vec_vec_pair[
i][
j].second <<
") ";
71 int32 minibatch_size =
Rand() % 1024 + 100;
72 int32 num_submat_indexes =
Rand() % 10 + 1;
73 int32 max_submat_list_size =
Rand() % 10 + 1;
77 max_submat_list_size = min_num_kaddrows + max_submat_list_size;
79 std::vector<std::pair<int32, int32> > all_pairs;
80 all_pairs.reserve(minibatch_size * max_submat_list_size);
81 std::vector<std::vector<std::pair<int32, int32> > >
82 submat_lists(minibatch_size),
84 std::vector<int32> submat_indexes(num_submat_indexes);
85 for (
int32 i = 0;
i < num_submat_indexes;
i++) {
86 submat_indexes[
i] =
Rand();
90 int32 max_generated_submat_list_size = 0;
91 for (
int32 i = 0;
i < minibatch_size;
i++) {
92 int32 num_locations =
Rand() % max_submat_list_size + 1;
93 max_generated_submat_list_size =
94 max_generated_submat_list_size < num_locations ?
95 num_locations : max_generated_submat_list_size;
96 submat_lists[
i].reserve(num_locations);
97 for (
int32 j = 0;
j < num_locations;
j++) {
98 if (
j <= min_num_kaddrows &&
j < num_submat_indexes)
101 submat_lists[
i].push_back(std::make_pair(submat_indexes[
j],
102 Rand() % minibatch_size));
103 submat_lists[
i].push_back(
104 std::make_pair(submat_indexes[
Rand() % num_submat_indexes],
105 Rand() % minibatch_size));
107 all_pairs.insert(all_pairs.end(), submat_lists[
i].begin(),
108 submat_lists[
i].end());
113 for (
int32 i = 0;
i < split_lists.size();
i++) {
115 std::vector<int32> second_values;
118 std::vector<int32> occurred_values;
119 int32 prev_value = -10;
120 for (
int32 j = 0;
j < second_values.size();
j++) {
121 if (second_values[
j] == -1)
123 if (second_values[
j] != prev_value) {
124 std::vector<int32>::iterator iter = std::find(occurred_values.begin(),
125 occurred_values.end(),
131 std::vector<std::pair<int32, int32> > list_of_pairs;
133 for (
int32 j = 0;
j < split_lists[
i].size();
j++) {
134 if (split_lists[i][
j].first == -1)
136 std::vector<std::pair<int32, int32> >::const_iterator iter =
137 std::find_if(list_of_pairs.begin(), list_of_pairs.end(),
140 list_of_pairs.push_back(split_lists[i][j]);
149 KALDI_LOG <<
"===========================";
151 int32 num_kaddrows_in_output = 0;
153 std::vector<int32> second_values;
156 for (
int32 i = 0 ;
i < split_lists.size();
i++) {
157 second_values.clear();
161 for (
int32 j = 0;
j < second_values.size();
j++) {
162 if (split_lists[i][
j].first != -1)
164 (split_lists[i][
j].second == second_values[
j]));
166 num_kaddrows_in_output++;
168 for (
int32 j = 0;
j < split_lists[
i].size();
j++) {
169 if (split_lists[i][
j].first == -1)
171 std::vector<std::pair<int32, int32> >::iterator iter =
172 std::find_if(all_pairs.begin(), all_pairs.end(),
175 all_pairs.erase(iter);
181 KALDI_ASSERT(num_kaddrows_in_output >= min_num_kaddrows);
186 for (
int32 k = 0; k < 10; k++) {
188 std::vector<int32> indexes(size);
191 std::vector<std::pair<int32, int32> > reverse_indexes;
195 bool found_example =
false;
197 if (indexes[
i] != -1) {
198 bool found_not_same =
false;
200 if (indexes[
j] != indexes[
i]) found_not_same =
true;
201 else if (found_not_same) found_example =
true;
208 for (
int32 i = 0;
i < reverse_indexes.size();
i++) {
209 for (
int32 j = reverse_indexes[
i].first;
210 j < reverse_indexes[
i].second;
j++) {
223 for (
int32 k = 0; k < 10; k++) {
225 std::vector<int32> indexes(size);
228 std::vector<std::pair<int32, int32> > reverse_indexes;
232 std::vector<std::vector<int32> > indexes_split;
234 if (indexes.size() == 0 ||
235 *std::max_element(indexes.begin(), indexes.end()) == -1) {
239 indexes_split[0] == indexes);
242 std::vector<std::vector<int32> > indexes_split;
245 for (
int32 i = 0;
i < indexes.size();
i++) {
246 int32 this_val = indexes[
i];
247 bool found = (this_val == -1);
249 for (
int32 j = 0;
j < indexes_split.size();
j++) {
253 if (indexes_split[
j][
i] == this_val) {
261 for (
int32 j = 0;
j < indexes_split.size();
j++) {
276 int32 minibatch_size =
Rand() % 1024 + 100;
277 int32 num_submat_indexes =
Rand() % 10 + 1;
278 int32 max_submat_list_size =
Rand() % 10 + 1;
282 max_submat_list_size = min_num_kaddrows + max_submat_list_size;
284 std::vector<std::pair<int32, int32> > all_pairs;
285 all_pairs.reserve(minibatch_size * max_submat_list_size);
286 std::vector<std::vector<std::pair<int32, int32> > >
287 submat_lists(minibatch_size),
289 std::vector<int32> submat_indexes(num_submat_indexes);
290 for (
int32 i = 0;
i < num_submat_indexes;
i++) {
291 submat_indexes[
i] =
Rand();
295 int32 max_generated_submat_list_size = 0;
296 for (
int32 i = 0;
i < minibatch_size;
i++) {
297 int32 num_locations =
Rand() % max_submat_list_size + 1;
298 max_generated_submat_list_size =
299 max_generated_submat_list_size < num_locations ?
300 num_locations : max_generated_submat_list_size;
301 submat_lists[
i].reserve(num_locations);
302 for (
int32 j = 0;
j < num_locations;
j++) {
305 if (
j <= min_num_kaddrows &&
j < num_submat_indexes) {
308 submat_lists[
i].push_back(std::make_pair(submat_indexes[
j],
309 Rand() % minibatch_size));
311 submat_lists[
i].push_back(
312 std::make_pair(submat_indexes[
Rand() % num_submat_indexes],
313 Rand() % minibatch_size));
315 all_pairs.insert(all_pairs.end(), submat_lists[
i].begin(),
316 submat_lists[
i].end());
325 KALDI_LOG <<
"===========================";
328 int32 num_kaddrows_in_output = 0;
330 std::vector<int32> second_values;
333 for (
int32 i = 0 ;
i < split_lists.size();
i++) {
334 second_values.clear();
337 for (
int32 j = 0;
j < second_values.size();
j++) {
338 if (split_lists[i][
j].first != -1)
340 (split_lists[i][
j].second == second_values[
j]));
342 num_kaddrows_in_output++;
344 for (
int32 j = 0;
j < split_lists[
i].size();
j++) {
345 if (split_lists[i][
j].first == -1)
347 std::vector<std::pair<int32, int32> >::iterator iter =
348 std::find_if(all_pairs.begin(), all_pairs.end(),
351 all_pairs.erase(iter);
357 KALDI_ASSERT(num_kaddrows_in_output >= min_num_kaddrows);
364 using namespace kaldi;
366 bool verbose =
false;
367 for (
int32 loop = 0; loop < 10; loop++) {
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool HasContiguousProperty(const std::vector< int32 > &indexes, std::vector< std::pair< int32, int32 > > *reverse_indexes)
This function returns true if for each integer i != -1, all the indexes j at which indexes[j] == i ar...
bool ConvertToIndexes(const std::vector< std::pair< int32, int32 > > &location_vector, int32 *first_value, std::vector< int32 > *second_values)
If it is the case for some i >= 0 that all the .first elements of "location_vector" are either i or -...
void SplitLocations(const std::vector< std::vector< std::pair< int32, int32 > > > &submat_lists, std::vector< std::vector< std::pair< int32, int32 > > > *split_lists)
The input to this function is a vector (indexed by matrix-row-index) of lists of pairs (submat_index...
ComparePair(const std::pair< int32, int32 > &correct_pair)
void UnitTestSplitLocations(bool verbose)
void EnsureContiguousProperty(const std::vector< int32 > &indexes, std::vector< std::vector< int32 > > *indexes_out)
This function takes a vector of indexes and splits it up into as separate vectors of the same size...
void PrintVectorVectorPair(std::vector< std::vector< std::pair< int32, int32 > > > vec_vec_pair)
int Rand(struct RandomState *state)
void UnitTestHasContiguousProperty()
void SplitLocationsBackward(const std::vector< std::vector< std::pair< int32, int32 > > > &submat_lists, std::vector< std::vector< std::pair< int32, int32 > > > *split_lists)
This function has the same interface as SplitLocations(); however, it ensures certain additional prop...
#define KALDI_ASSERT(cond)
PairIsEqualComparator(const std::pair< int32, int32 > pair)
void UnitTestSplitLocationsBackward(bool verbose)
std::pair< int32, int32 > correct_pair_
void UnitTestEnsureContiguousProperty()
bool operator()(std::pair< int32, int32 > const &arg)
std::pair< int32, int32 > pair_
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)