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

Function trsTest

test/transpose.cpp:55–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53
54template<typename T>
55void trsTest(string pTestFile, bool isSubRef = false,
56 const vector<af_seq> *seqv = NULL) {
57 SUPPORTED_TYPE_CHECK(T);
58
59 vector<dim4> numDims;
60
61 vector<vector<T>> in;
62 vector<vector<T>> tests;
63 readTests<T, T, int>(pTestFile, numDims, in, tests);
64 dim4 dims = numDims[0];
65
66 af_array outArray = 0;
67 af_array inArray = 0;
68 T *outData;
69 ASSERT_SUCCESS(af_create_array(&inArray, &(in[0].front()), dims.ndims(),
70 dims.get(),
71 (af_dtype)dtype_traits<T>::af_type));
72
73 // check if the test is for indexed Array
74 if (isSubRef) {
75 dim4 newDims(dims[1] - 4, dims[0] - 4, dims[2], dims[3]);
76 af_array subArray = 0;
77 ASSERT_SUCCESS(
78 af_index(&subArray, inArray, seqv->size(), &seqv->front()));
79 ASSERT_SUCCESS(af_transpose(&outArray, subArray, false));
80 // destroy the temporary indexed Array
81 ASSERT_SUCCESS(af_release_array(subArray));
82
83 dim_t nElems;
84 ASSERT_SUCCESS(af_get_elements(&nElems, outArray));
85 outData = new T[nElems];
86 } else {
87 ASSERT_SUCCESS(af_transpose(&outArray, inArray, false));
88 outData = new T[dims.elements()];
89 }
90
91 ASSERT_SUCCESS(af_get_data_ptr((void *)outData, outArray));
92
93 for (size_t testIter = 0; testIter < tests.size(); ++testIter) {
94 vector<T> currGoldBar = tests[testIter];
95 size_t nElems = currGoldBar.size();
96 for (size_t elIter = 0; elIter < nElems; ++elIter) {
97 ASSERT_EQ(currGoldBar[elIter], outData[elIter])
98 << "at: " << elIter << endl;
99 }
100 }
101
102 // cleanup
103 delete[] outData;
104 ASSERT_SUCCESS(af_release_array(inArray));
105 ASSERT_SUCCESS(af_release_array(outArray));
106}
107
108TYPED_TEST(Transpose, Vector) {
109 trsTest<TypeParam>(string(TEST_DIR "/transpose/vector.test"));

Callers

nothing calls this directly

Calls 9

af_get_elementsFunction · 0.85
af_create_arrayFunction · 0.50
af_indexFunction · 0.50
af_transposeFunction · 0.50
af_release_arrayFunction · 0.50
af_get_data_ptrFunction · 0.50
ndimsMethod · 0.45
getMethod · 0.45
elementsMethod · 0.45

Tested by

no test coverage detected