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

Function reduceTest

test/reduce.cpp:51–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50template<typename Ti, typename To, reduceFunc af_reduce>
51void reduceTest(string pTestFile, int off = 0, bool isSubRef = false,
52 const vector<af_seq> seqv = vector<af_seq>()) {
53 SUPPORTED_TYPE_CHECK(Ti);
54 SUPPORTED_TYPE_CHECK(To);
55
56 vector<dim4> numDims;
57
58 vector<vector<int>> data;
59 vector<vector<int>> tests;
60 readTests<int, int, int>(pTestFile, numDims, data, tests);
61 dim4 dims = numDims[0];
62
63 vector<Ti> in(data[0].size());
64 transform(data[0].begin(), data[0].end(), in.begin(), convert_to<Ti, int>);
65
66 af_array inArray = 0;
67 af_array outArray = 0;
68 af_array tempArray = 0;
69
70 // Get input array
71 if (isSubRef) {
72 ASSERT_SUCCESS(
73 af_create_array(&tempArray, &in.front(), dims.ndims(), dims.get(),
74 (af_dtype)af::dtype_traits<Ti>::af_type));
75 ASSERT_SUCCESS(
76 af_index(&inArray, tempArray, seqv.size(), &seqv.front()));
77 ASSERT_SUCCESS(af_release_array(tempArray));
78 } else {
79 ASSERT_SUCCESS(
80 af_create_array(&inArray, &in.front(), dims.ndims(), dims.get(),
81 (af_dtype)af::dtype_traits<Ti>::af_type));
82 }
83
84 // Compare result
85 for (int d = 0; d < (int)tests.size(); ++d) {
86 vector<To> currGoldBar(tests[d].begin(), tests[d].end());
87
88 // Run sum
89 ASSERT_SUCCESS(af_reduce(&outArray, inArray, d + off));
90
91 af_dtype t;
92 af_get_type(&t, outArray);
93
94 // Get result
95 vector<To> outData(dims.elements());
96 ASSERT_SUCCESS(af_get_data_ptr((void *)&outData.front(), outArray));
97
98 size_t nElems = currGoldBar.size();
99 if (std::equal(currGoldBar.begin(), currGoldBar.end(),
100 outData.begin()) == false) {
101 for (size_t elIter = 0; elIter < nElems; ++elIter) {
102 EXPECT_EQ(currGoldBar[elIter], outData[elIter])
103 << "at: " << elIter << " for dim " << d + off << endl;
104 }
105 for (int i = 0; i < (int)nElems; i++) {
106 cout << currGoldBar[i] << ", ";
107 }
108

Callers

nothing calls this directly

Calls 9

af_get_typeFunction · 0.85
transformFunction · 0.50
af_create_arrayFunction · 0.50
af_indexFunction · 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