| 49 | |
| 50 | template<typename T> |
| 51 | void sortTest(string pTestFile, const bool dir, const unsigned resultIdx0, |
| 52 | const unsigned resultIdx1, bool isSubRef = false, |
| 53 | const vector<af_seq>* seqv = NULL) { |
| 54 | SUPPORTED_TYPE_CHECK(T); |
| 55 | |
| 56 | vector<dim4> numDims; |
| 57 | vector<vector<T>> in; |
| 58 | vector<vector<float>> tests; |
| 59 | readTests<T, float, int>(pTestFile, numDims, in, tests); |
| 60 | |
| 61 | dim4 idims = numDims[0]; |
| 62 | |
| 63 | af_array inArray = 0; |
| 64 | af_array tempArray = 0; |
| 65 | af_array sxArray = 0; |
| 66 | af_array ixArray = 0; |
| 67 | |
| 68 | if (isSubRef) { |
| 69 | ASSERT_SUCCESS(af_create_array(&tempArray, &(in[0].front()), |
| 70 | idims.ndims(), idims.get(), |
| 71 | (af_dtype)dtype_traits<T>::af_type)); |
| 72 | |
| 73 | ASSERT_SUCCESS( |
| 74 | af_index(&inArray, tempArray, seqv->size(), &seqv->front())); |
| 75 | } else { |
| 76 | ASSERT_SUCCESS(af_create_array(&inArray, &(in[0].front()), |
| 77 | idims.ndims(), idims.get(), |
| 78 | (af_dtype)dtype_traits<T>::af_type)); |
| 79 | } |
| 80 | |
| 81 | ASSERT_SUCCESS(af_sort_index(&sxArray, &ixArray, inArray, 0, dir)); |
| 82 | |
| 83 | vector<T> sxTest(tests[resultIdx0].size()); |
| 84 | transform(tests[resultIdx0].begin(), tests[resultIdx0].end(), |
| 85 | sxTest.begin(), convert_to<T, float>); |
| 86 | |
| 87 | ASSERT_VEC_ARRAY_EQ(sxTest, idims, sxArray); |
| 88 | |
| 89 | #ifdef AF_OPENCL |
| 90 | UNUSED(resultIdx1); |
| 91 | #else |
| 92 | vector<unsigned> ixTest(tests[resultIdx1].begin(), tests[resultIdx1].end()); |
| 93 | ASSERT_VEC_ARRAY_EQ(ixTest, idims, ixArray); |
| 94 | #endif |
| 95 | |
| 96 | if (inArray != 0) af_release_array(inArray); |
| 97 | if (sxArray != 0) af_release_array(sxArray); |
| 98 | if (ixArray != 0) af_release_array(ixArray); |
| 99 | if (tempArray != 0) af_release_array(tempArray); |
| 100 | } |
| 101 | |
| 102 | #define SORT_INIT(desc, file, dir, resultIdx0, resultIdx1) \ |
| 103 | TYPED_TEST(SortIndex, desc) { \ |
nothing calls this directly
no test coverage detected