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

Function cppModdimsTest

test/moddims.cpp:197–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195
196template<typename T>
197void cppModdimsTest(string pTestFile, bool isSubRef = false,
198 const vector<af_seq> *seqv = NULL) {
199 SUPPORTED_TYPE_CHECK(T);
200
201 vector<dim4> numDims;
202
203 vector<vector<T>> in;
204 vector<vector<T>> tests;
205 readTests<T, T, int>(pTestFile, numDims, in, tests);
206 dim4 dims = numDims[0];
207
208 T *outData;
209
210 if (isSubRef) {
211 array input(dims, &(in[0].front()));
212
213 array subArray = input(seqv->at(0), seqv->at(1));
214
215 dim4 newDims(1);
216 newDims[0] = 2;
217 newDims[1] = 3;
218 array output = moddims(subArray, newDims.ndims(), newDims.get());
219
220 dim_t nElems = output.elements();
221 outData = new T[nElems];
222 output.host((void *)outData);
223 } else {
224 array input(dims, &(in[0].front()));
225
226 dim4 newDims(1);
227 newDims[0] = dims[1];
228 newDims[1] = dims[0] * dims[2];
229
230 array output = moddims(input, newDims.ndims(), newDims.get());
231
232 outData = new T[dims.elements()];
233 output.host((void *)outData);
234 }
235
236 for (size_t testIter = 0; testIter < tests.size(); ++testIter) {
237 vector<T> currGoldBar = tests[testIter];
238 size_t nElems = currGoldBar.size();
239 for (size_t elIter = 0; elIter < nElems; ++elIter) {
240 ASSERT_EQ(currGoldBar[elIter], outData[elIter])
241 << "at: " << elIter << endl;
242 }
243 }
244 delete[] outData;
245}
246
247TEST(Moddims, Basic_CPP) {
248 cppModdimsTest<float>(string(TEST_DIR "/moddims/basic.test"));

Callers

nothing calls this directly

Calls 5

moddimsFunction · 0.85
hostMethod · 0.80
ndimsMethod · 0.45
getMethod · 0.45
elementsMethod · 0.45

Tested by

no test coverage detected