| 45 | |
| 46 | template<typename T> |
| 47 | void rotateTest(string pTestFile, const unsigned resultIdx, const float angle, |
| 48 | const bool crop) { |
| 49 | SUPPORTED_TYPE_CHECK(T); |
| 50 | |
| 51 | vector<dim4> numDims; |
| 52 | vector<vector<T>> in; |
| 53 | vector<vector<T>> tests; |
| 54 | readTests<T, T, float>(pTestFile, numDims, in, tests); |
| 55 | |
| 56 | dim4 dims = numDims[0]; |
| 57 | |
| 58 | af_array inArray = 0; |
| 59 | af_array outArray = 0; |
| 60 | af_array tempArray = 0; |
| 61 | |
| 62 | float theta = angle * PI / 180.0f; |
| 63 | |
| 64 | ASSERT_SUCCESS(af_create_array(&inArray, &(in[0].front()), dims.ndims(), |
| 65 | dims.get(), |
| 66 | (af_dtype)dtype_traits<T>::af_type)); |
| 67 | |
| 68 | ASSERT_SUCCESS( |
| 69 | af_rotate(&outArray, inArray, theta, crop, AF_INTERP_NEAREST)); |
| 70 | |
| 71 | // Get result |
| 72 | T* outData = new T[tests[resultIdx].size()]; |
| 73 | ASSERT_SUCCESS(af_get_data_ptr((void*)outData, outArray)); |
| 74 | |
| 75 | // Compare result |
| 76 | size_t nElems = tests[resultIdx].size(); |
| 77 | |
| 78 | // This is a temporary solution. The reason we need this is because of |
| 79 | // floating point error in the index computations on CPU/GPU, some |
| 80 | // elements of GPU(CUDA/OpenCL) versions are different from the CPU version. |
| 81 | // That is, the input index of CPU/GPU may differ by 1 (rounding error) on |
| 82 | // x or y, hence a different value is copied. |
| 83 | // We expect 99.99% values to be same between the CPU/GPU versions and |
| 84 | // ASSERT_EQ (in comments below) to pass for CUDA & OpenCL backends |
| 85 | size_t fail_count = 0; |
| 86 | for (size_t i = 0; i < nElems; i++) { |
| 87 | if (abs((tests[resultIdx][i] - (T)outData[i])) > 0.001) fail_count++; |
| 88 | } |
| 89 | ASSERT_EQ(true, ((fail_count / (float)nElems) < 0.005)); |
| 90 | |
| 91 | // for (size_t elIter = 0; elIter < nElems; ++elIter) { |
| 92 | // ASSERT_EQ(tests[resultIdx][elIter], outData[elIter]) << "at: " << |
| 93 | // elIter << endl; |
| 94 | //} |
| 95 | |
| 96 | // Delete |
| 97 | delete[] outData; |
| 98 | |
| 99 | if (inArray != 0) af_release_array(inArray); |
| 100 | if (outArray != 0) af_release_array(outArray); |
| 101 | if (tempArray != 0) af_release_array(tempArray); |
| 102 | } |
| 103 | |
| 104 | #define ROTATE_INIT(desc, file, resultIdx, angle, crop) \ |
nothing calls this directly
no test coverage detected