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

Function moddimsTest

test/moddims.cpp:47–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45
46template<typename T>
47void moddimsTest(string pTestFile, bool isSubRef = false,
48 const vector<af_seq> *seqv = NULL) {
49 SUPPORTED_TYPE_CHECK(T);
50
51 vector<dim4> numDims;
52
53 vector<vector<T>> in;
54 vector<vector<T>> tests;
55 readTests<T, T, int>(pTestFile, numDims, in, tests);
56 dim4 dims = numDims[0];
57
58 T *outData;
59
60 if (isSubRef) {
61 af_array inArray = 0;
62 af_array subArray = 0;
63 af_array outArray = 0;
64
65 ASSERT_SUCCESS(af_create_array(&inArray, &(in[0].front()), dims.ndims(),
66 dims.get(),
67 (af_dtype)dtype_traits<T>::af_type));
68
69 ASSERT_SUCCESS(
70 af_index(&subArray, inArray, seqv->size(), &seqv->front()));
71
72 dim4 newDims(1);
73 newDims[0] = 2;
74 newDims[1] = 3;
75 ASSERT_SUCCESS(
76 af_moddims(&outArray, subArray, newDims.ndims(), newDims.get()));
77
78 dim_t nElems;
79 ASSERT_SUCCESS(af_get_elements(&nElems, outArray));
80
81 outData = new T[nElems];
82 ASSERT_SUCCESS(af_get_data_ptr((void *)outData, outArray));
83
84 ASSERT_SUCCESS(af_release_array(inArray));
85 ASSERT_SUCCESS(af_release_array(outArray));
86 ASSERT_SUCCESS(af_release_array(subArray));
87 } else {
88 af_array inArray = 0;
89 af_array outArray = 0;
90
91 ASSERT_SUCCESS(af_create_array(&inArray, &(in[0].front()), dims.ndims(),
92 dims.get(),
93 (af_dtype)dtype_traits<T>::af_type));
94
95 dim4 newDims(1);
96 newDims[0] = dims[1];
97 newDims[1] = dims[0] * dims[2];
98 ASSERT_SUCCESS(
99 af_moddims(&outArray, inArray, newDims.ndims(), newDims.get()));
100
101 outData = new T[dims.elements()];
102 ASSERT_SUCCESS(af_get_data_ptr((void *)outData, outArray));
103
104 ASSERT_SUCCESS(af_release_array(inArray));

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected