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

Function approx1Test

test/approx1.cpp:69–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67
68template<typename T>
69void approx1Test(string pTestFile, const unsigned resultIdx,
70 const af_interp_type method, bool isSubRef = false,
71 const vector<af_seq>* seqv = NULL) {
72 SUPPORTED_TYPE_CHECK(T);
73
74 typedef typename dtype_traits<T>::base_type BT;
75 vector<dim4> numDims;
76 vector<vector<BT>> in;
77 vector<vector<T>> tests;
78 readTests<BT, T, float>(pTestFile, numDims, in, tests);
79
80 dim4 idims = numDims[0];
81 dim4 pdims = numDims[1];
82
83 af_array inArray = 0;
84 af_array posArray = 0;
85 af_array outArray = 0;
86 af_array tempArray = 0;
87
88 vector<T> input(in[0].begin(), in[0].end());
89
90 if (isSubRef) {
91 ASSERT_SUCCESS(af_create_array(&tempArray, &(input.front()),
92 idims.ndims(), idims.get(),
93 (af_dtype)dtype_traits<T>::af_type));
94
95 ASSERT_SUCCESS(
96 af_index(&inArray, tempArray, seqv->size(), &seqv->front()));
97 } else {
98 ASSERT_SUCCESS(af_create_array(&inArray, &(input.front()),
99 idims.ndims(), idims.get(),
100 (af_dtype)dtype_traits<T>::af_type));
101 }
102
103 ASSERT_SUCCESS(af_create_array(&posArray, &(in[1].front()), pdims.ndims(),
104 pdims.get(),
105 (af_dtype)dtype_traits<BT>::af_type));
106
107 ASSERT_SUCCESS(af_approx1(&outArray, inArray, posArray, method, 0));
108
109 // Get result
110 T* outData = new T[tests[resultIdx].size()];
111 ASSERT_SUCCESS(af_get_data_ptr((void*)outData, outArray));
112
113 // Compare result
114 size_t nElems = tests[resultIdx].size();
115 bool ret = true;
116 for (size_t elIter = 0; elIter < nElems; ++elIter) {
117 ret = (abs(tests[resultIdx][elIter] - outData[elIter]) < 0.0005);
118 ASSERT_EQ(true, ret) << tests[resultIdx][elIter] << "\t"
119 << outData[elIter] << "at: " << elIter << endl;
120 }
121
122 // Delete
123 delete[] outData;
124
125 if (inArray != 0) af_release_array(inArray);
126 if (posArray != 0) af_release_array(posArray);

Callers

nothing calls this directly

Calls 8

absFunction · 0.70
af_create_arrayFunction · 0.50
af_indexFunction · 0.50
af_approx1Function · 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