| 61 | |
| 62 | template<typename T> |
| 63 | void approx2Test(string pTestFile, const unsigned resultIdx, |
| 64 | const af_interp_type method, bool isSubRef = false, |
| 65 | const vector<af_seq>* seqv = NULL) { |
| 66 | SUPPORTED_TYPE_CHECK(T); |
| 67 | typedef typename dtype_traits<T>::base_type BT; |
| 68 | vector<dim4> numDims; |
| 69 | vector<vector<BT>> in; |
| 70 | vector<vector<T>> tests; |
| 71 | readTests<BT, T, float>(pTestFile, numDims, in, tests); |
| 72 | |
| 73 | dim4 idims = numDims[0]; |
| 74 | dim4 pdims = numDims[1]; |
| 75 | dim4 qdims = numDims[2]; |
| 76 | |
| 77 | af_array inArray = 0; |
| 78 | af_array pos0Array = 0; |
| 79 | af_array pos1Array = 0; |
| 80 | af_array outArray = 0; |
| 81 | af_array tempArray = 0; |
| 82 | |
| 83 | vector<T> input(in[0].begin(), in[0].end()); |
| 84 | |
| 85 | if (isSubRef) { |
| 86 | ASSERT_SUCCESS(af_create_array(&tempArray, &(input.front()), |
| 87 | idims.ndims(), idims.get(), |
| 88 | (af_dtype)dtype_traits<T>::af_type)); |
| 89 | |
| 90 | ASSERT_SUCCESS( |
| 91 | af_index(&inArray, tempArray, seqv->size(), &seqv->front())); |
| 92 | } else { |
| 93 | ASSERT_SUCCESS(af_create_array(&inArray, &(input.front()), |
| 94 | idims.ndims(), idims.get(), |
| 95 | (af_dtype)dtype_traits<T>::af_type)); |
| 96 | } |
| 97 | |
| 98 | ASSERT_SUCCESS(af_create_array(&pos0Array, &(in[1].front()), pdims.ndims(), |
| 99 | pdims.get(), |
| 100 | (af_dtype)dtype_traits<BT>::af_type)); |
| 101 | ASSERT_SUCCESS(af_create_array(&pos1Array, &(in[2].front()), qdims.ndims(), |
| 102 | qdims.get(), |
| 103 | (af_dtype)dtype_traits<BT>::af_type)); |
| 104 | |
| 105 | ASSERT_SUCCESS( |
| 106 | af_approx2(&outArray, inArray, pos0Array, pos1Array, method, 0)); |
| 107 | |
| 108 | // Get result |
| 109 | T* outData = new T[tests[resultIdx].size()]; |
| 110 | ASSERT_SUCCESS(af_get_data_ptr((void*)outData, outArray)); |
| 111 | |
| 112 | // Compare result |
| 113 | size_t nElems = tests[resultIdx].size(); |
| 114 | bool ret = true; |
| 115 | for (size_t elIter = 0; elIter < nElems; ++elIter) { |
| 116 | ret = (abs(tests[resultIdx][elIter] - outData[elIter]) < 0.001); |
| 117 | ASSERT_EQ(true, ret) << tests[resultIdx][elIter] << "\t" |
| 118 | << outData[elIter] << "at: " << elIter << endl; |
| 119 | } |
| 120 |
nothing calls this directly
no test coverage detected