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

Function cppMatMulCheck

test/blas.cpp:130–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128
129template<typename T, bool isBVector>
130void cppMatMulCheck(string TestFile) {
131 SUPPORTED_TYPE_CHECK(T);
132
133 vector<dim4> numDims;
134
135 vector<vector<T>> hData;
136 vector<vector<T>> tests;
137 readTests<T, T, int>(TestFile, numDims, hData, tests);
138
139 array a(numDims[0], &hData[0].front());
140 array b(numDims[1], &hData[1].front());
141
142 dim4 atdims = numDims[0];
143 {
144 dim_t f = atdims[0];
145 atdims[0] = atdims[1];
146 atdims[1] = f;
147 }
148 dim4 btdims = numDims[1];
149 {
150 dim_t f = btdims[0];
151 btdims[0] = btdims[1];
152 btdims[1] = f;
153 }
154
155 array aT = moddims(a, atdims.ndims(), atdims.get());
156 array bT = moddims(b, btdims.ndims(), btdims.get());
157
158 vector<array> out(tests.size());
159 if (isBVector) {
160 out[0] = matmul(aT, b, AF_MAT_NONE, AF_MAT_NONE);
161 out[1] = matmul(bT, a, AF_MAT_NONE, AF_MAT_NONE);
162 out[2] = matmul(b, a, AF_MAT_TRANS, AF_MAT_NONE);
163 out[3] = matmul(bT, aT, AF_MAT_NONE, AF_MAT_TRANS);
164 out[4] = matmul(b, aT, AF_MAT_TRANS, AF_MAT_TRANS);
165 } else {
166 out[0] = matmul(a, b, AF_MAT_NONE, AF_MAT_NONE);
167 out[1] = matmul(a, bT, AF_MAT_NONE, AF_MAT_TRANS);
168 out[2] = matmul(a, bT, AF_MAT_TRANS, AF_MAT_NONE);
169 out[3] = matmul(aT, bT, AF_MAT_TRANS, AF_MAT_TRANS);
170 }
171
172 for (size_t i = 0; i < tests.size(); i++) {
173 dim_t elems = out[i].elements();
174 vector<T> h_out(elems);
175 out[i].host((void *)&h_out.front());
176
177 if (false == equal(h_out.begin(), h_out.end(), tests[i].begin())) {
178 cout << "Failed test " << i << "\nCalculated: " << endl;
179 copy(h_out.begin(), h_out.end(), ostream_iterator<T>(cout, ", "));
180 cout << "Expected: " << endl;
181 copy(tests[i].begin(), tests[i].end(),
182 ostream_iterator<T>(cout, ", "));
183 FAIL();
184 }
185 }
186}
187

Callers

nothing calls this directly

Calls 7

moddimsFunction · 0.85
hostMethod · 0.80
matmulFunction · 0.50
copyFunction · 0.50
ndimsMethod · 0.45
getMethod · 0.45
elementsMethod · 0.45

Tested by

no test coverage detected