| 182 | ////////////////////////////////// CPP ////////////////////////////////////// |
| 183 | |
| 184 | TEST(RotateLinear, CPP) { |
| 185 | const unsigned resultIdx = 0; |
| 186 | const float angle = 180; |
| 187 | const bool crop = false; |
| 188 | |
| 189 | vector<dim4> numDims; |
| 190 | vector<vector<float>> in; |
| 191 | vector<vector<float>> tests; |
| 192 | readTests<float, float, float>( |
| 193 | string(TEST_DIR "/rotate/rotatelinear1.test"), numDims, in, tests); |
| 194 | |
| 195 | dim4 dims = numDims[0]; |
| 196 | float theta = angle * PI / 180.0f; |
| 197 | |
| 198 | array input(dims, &(in[0].front())); |
| 199 | array output = rotate(input, theta, crop, AF_INTERP_BILINEAR); |
| 200 | |
| 201 | // Get result |
| 202 | float* outData = new float[tests[resultIdx].size()]; |
| 203 | output.host((void*)outData); |
| 204 | |
| 205 | // Compare result |
| 206 | size_t nElems = tests[resultIdx].size(); |
| 207 | |
| 208 | // This is a temporary solution. The reason we need this is because of |
| 209 | // floating point error in the index computations on CPU/GPU, some |
| 210 | // elements of GPU(CUDA/OpenCL) versions are different from the CPU version. |
| 211 | // That is, the input index of CPU/GPU may differ by 1 (rounding error) on |
| 212 | // x or y, hence a different value is copied. |
| 213 | // We expect 99.99% values to be same between the CPU/GPU versions and |
| 214 | // ASSERT_EQ (in comments below) to pass for CUDA & OpenCL backends |
| 215 | size_t fail_count = 0; |
| 216 | for (size_t i = 0; i < nElems; i++) { |
| 217 | if (fabs(tests[resultIdx][i] - outData[i]) > 0.0001) fail_count++; |
| 218 | } |
| 219 | ASSERT_EQ(true, ((fail_count / (float)nElems) < 0.01)); |
| 220 | |
| 221 | // Delete |
| 222 | delete[] outData; |
| 223 | } |