Skip to content

Commit 95685d3

Browse files
committed
redo checking
1 parent 55d058a commit 95685d3

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

Libraries/oneMKL/random_sampling_without_replacement/lottery.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,23 @@ int main(int argc, char ** argv) {
134134
std::terminate();
135135
}
136136

137-
// check correctness whether experiment contains unique numbers or not
137+
// Print output
138+
print_results(result_ptr, m, num_exp);
139+
140+
// Check correctness whether experiment contains unique numbers or not
138141
for(size_t i = 0; i < num_exp; ++i){
139142
auto first_iter = result_ptr + m * i;
140-
std::unordered_set<size_t> unique_set(first_iter, first_iter + m);
141-
if(unique_set.size() != m &&
143+
std::sort(first_iter, first_iter + m);
144+
if(std::adjacent_find(first_iter, first_iter + m) != first_iter + m &&
142145
// if all elements are in the [0, n] range
143-
std::count_if(unique_set.begin(), unique_set.end(), [n](auto val){return val > n && val >= 0;}) == 0)
146+
std::count_if(first_iter, first_iter + m, [n](auto val){return val > n && val >= 0;}) == 0)
144147
{
145148
std::cout << "TEST FAILED" << std::endl;
146149
std::cout << "Error: the experiment "<< i <<" contains duplicates" << std::endl;
147-
std::cout << "Number of unique elements in the result: " << unique_set.size() << std::endl;
148150
return 1;
149151
}
150152
}
151153
std::cout << "TEST PASSED" << std::endl;
152154

153-
// Print output
154-
print_results(result_ptr, m, num_exp);
155-
156155
return 0;
157156
}

Libraries/oneMKL/random_sampling_without_replacement/lottery_device_api.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,23 @@ int main(int argc, char ** argv) {
123123
std::terminate();
124124
}
125125

126-
// check correctness whether experiment contains unique numbers or not
126+
// Print output
127+
print_results(result_vec, m);
128+
129+
// Check correctness whether experiment contains unique numbers or not
127130
for(size_t i = 0; i < num_exp; ++i){
128131
auto first_iter = result_vec.begin() + m * i;
129-
std::unordered_set<size_t> unique_set(first_iter, first_iter + m);
130-
if(unique_set.size() != m &&
132+
std::sort(first_iter, first_iter + m);
133+
if(std::adjacent_find(first_iter, first_iter + m) != first_iter + m &&
131134
// if all elements are in the [0, n] range
132-
std::count_if(unique_set.begin(), unique_set.end(), [n](auto val){return val > n && val >= 0;}) == 0)
135+
std::count_if(first_iter, first_iter + m, [n](auto val){return val > n && val >= 0;}) == 0)
133136
{
134137
std::cout << "TEST FAILED" << std::endl;
135138
std::cout << "Error: the experiment "<< i <<" contains duplicates" << std::endl;
136-
std::cout << "Number of unique elements in the result: " << unique_set.size() << std::endl;
137139
return 1;
138140
}
139141
}
140142
std::cout << "TEST PASSED" << std::endl;
141143

142-
// Print output
143-
print_results(result_vec, m);
144-
145144
return 0;
146145
}

Libraries/oneMKL/random_sampling_without_replacement/lottery_usm.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,24 @@ int main(int argc, char ** argv) {
134134
std::terminate();
135135
}
136136

137-
// check correctness whether experiment contains unique numbers or not
137+
// Print output
138+
std::cout << "Results with Host API:" << std::endl;
139+
print_results(result_ptr, m, num_exp);
140+
141+
// Check correctness whether experiment contains unique numbers or not
138142
for(size_t i = 0; i < num_exp; ++i){
139143
auto first_iter = result_ptr + m * i;
140-
std::unordered_set<size_t> unique_set(first_iter, first_iter + m);
141-
if(unique_set.size() != m &&
144+
std::sort(first_iter, first_iter + m);
145+
if(std::adjacent_find(first_iter, first_iter + m) != first_iter + m &&
142146
// if all elements are in the [0, n] range
143-
std::count_if(unique_set.begin(), unique_set.end(), [n](auto val){return val > n && val >= 0;}) == 0)
147+
std::count_if(first_iter, first_iter + m, [n](auto val){return val > n && val >= 0;}) == 0)
144148
{
145149
std::cout << "TEST FAILED" << std::endl;
146150
std::cout << "Error: the experiment "<< i <<" contains duplicates" << std::endl;
147-
std::cout << "Number of unique elements in the result: " << unique_set.size() << std::endl;
148151
return 1;
149152
}
150153
}
151154
std::cout << "TEST PASSED" << std::endl;
152155

153-
// Print output
154-
std::cout << "Results with Host API:" << std::endl;
155-
print_results(result_ptr, m, num_exp);
156-
157156
return 0;
158157
}

0 commit comments

Comments
 (0)