///////////////////////////// CPP //////////////////////////////////////
| 160 | ////////////////////////////////// CPP ////////////////////////////////////// |
| 161 | // |
| 162 | TEST(Rotate, CPP) { |
| 163 | const unsigned resultIdx = 0; |
| 164 | const float angle = 180; |
| 165 | const bool crop = false; |
| 166 | |
| 167 | vector<dim4> numDims; |
| 168 | vector<vector<float>> in; |
| 169 | vector<vector<float>> tests; |
| 170 | readTests<float, float, float>(string(TEST_DIR "/rotate/rotate1.test"), |
| 171 | numDims, in, tests); |
| 172 | |
| 173 | dim4 dims = numDims[0]; |
| 174 | float theta = angle * PI / 180.0f; |
| 175 | |
| 176 | array input(dims, &(in[0].front())); |
| 177 | array output = rotate(input, theta, crop, AF_INTERP_NEAREST); |
| 178 | |
| 179 | // Get result |
| 180 | float* outData = new float[tests[resultIdx].size()]; |
| 181 | output.host((void*)outData); |
| 182 | |
| 183 | // Compare result |
| 184 | size_t nElems = tests[resultIdx].size(); |
| 185 | |
| 186 | // This is a temporary solution. The reason we need this is because of |
| 187 | // floating point error in the index computations on CPU/GPU, some |
| 188 | // elements of GPU(CUDA/OpenCL) versions are different from the CPU version. |
| 189 | // That is, the input index of CPU/GPU may differ by 1 (rounding error) on |
| 190 | // x or y, hence a different value is copied. |
| 191 | // We expect 99.99% values to be same between the CPU/GPU versions and |
| 192 | // ASSERT_EQ (in comments below) to pass for CUDA & OpenCL backends |
| 193 | size_t fail_count = 0; |
| 194 | for (size_t i = 0; i < nElems; i++) { |
| 195 | if (fabs(tests[resultIdx][i] - outData[i]) > 0.0001) fail_count++; |
| 196 | } |
| 197 | ASSERT_EQ(true, ((fail_count / (float)nElems) < 0.01)); |
| 198 | |
| 199 | // Delete |
| 200 | delete[] outData; |
| 201 | } |