Skip to content

Commit af4ebe7

Browse files
author
Raghuveer Devulapalli
committed
Add argsort test to sort an array with nan
1 parent 33e30e6 commit af4ebe7

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

tests/test_argsort.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,46 @@ TYPED_TEST_P(avx512argsort, test_reverse)
174174
}
175175
}
176176

177+
TYPED_TEST_P(avx512argsort, test_array_with_nan)
178+
{
179+
if (!cpu_has_avx512bw()) {
180+
GTEST_SKIP() << "Skipping this test, it requires avx512bw ISA";
181+
}
182+
if (!std::is_floating_point<TypeParam>::value) {
183+
GTEST_SKIP() << "Skipping this test, it is meant for float/double";
184+
}
185+
std::vector<int64_t> arrsizes;
186+
for (int64_t ii = 2; ii <= 1024; ++ii) {
187+
arrsizes.push_back(ii);
188+
}
189+
std::vector<TypeParam> arr;
190+
for (auto &size : arrsizes) {
191+
arr = get_uniform_rand_array<TypeParam>(size);
192+
arr[0] = std::numeric_limits<TypeParam>::quiet_NaN();
193+
arr[1] = std::numeric_limits<TypeParam>::quiet_NaN();
194+
std::vector<int64_t> inx
195+
= avx512_argsort<TypeParam>(arr.data(), arr.size());
196+
std::vector<TypeParam> sort1;
197+
for (size_t jj = 0; jj < size; ++jj) {
198+
sort1.push_back(arr[inx[jj]]);
199+
}
200+
if ((!std::isnan(sort1[size-1])) || (!std::isnan(sort1[size-2]))) {
201+
FAIL() << "NAN's aren't sorted to the end";
202+
}
203+
if (!std::is_sorted(sort1.begin(), sort1.end() - 2)) {
204+
FAIL() << "Array isn't sorted";
205+
}
206+
arr.clear();
207+
}
208+
}
209+
177210
REGISTER_TYPED_TEST_SUITE_P(avx512argsort,
178211
test_random,
179212
test_reverse,
180213
test_constant,
181214
test_sorted,
182-
test_small_range);
215+
test_small_range,
216+
test_array_with_nan);
183217

184218
using ArgSortTestTypes = testing::Types<int32_t,
185219
uint32_t,

0 commit comments

Comments
 (0)