MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / rotateTest

Function rotateTest

test/rotate_linear.cpp:52–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

absFunction · 0.70
af_create_arrayFunction · 0.50
af_indexFunction · 0.50
af_rotateFunction · 0.50
af_get_data_ptrFunction · 0.50
af_release_arrayFunction · 0.50
ndimsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected