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

Function sparseArithTesterDiv

test/sparse_arith.cpp:190–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188// Div
189template<typename T>
190void sparseArithTesterDiv(const int m, const int n, int factor,
191 const double eps) {
192 deviceGC();
193
194 SUPPORTED_TYPE_CHECK(T);
195
196#if 1
197 array A = cpu_randu<T>(dim4(m, n));
198 array B = cpu_randu<T>(dim4(m, n));
199#else
200 array A = randu(m, n, (dtype)dtype_traits<T>::af_type);
201 array B = randu(m, n, (dtype)dtype_traits<T>::af_type);
202#endif
203
204 A = makeSparse<T>(A, factor);
205
206 array RA = sparse(A, AF_STORAGE_CSR);
207 array OA = sparse(A, AF_STORAGE_COO);
208
209 // Arith Op
210 array resR = arith_op<af_div_t>()(RA, B);
211 array resO = arith_op<af_div_t>()(OA, B);
212
213 // Assert division by sparse is not allowed
214 af_array out_temp = 0;
215 ASSERT_EQ(AF_ERR_NOT_SUPPORTED,
216 af_div(&out_temp, B.get(), RA.get(), false));
217 ASSERT_EQ(AF_ERR_NOT_SUPPORTED,
218 af_div(&out_temp, B.get(), OA.get(), false));
219 if (out_temp != 0) af_release_array(out_temp);
220
221 // We will test this by converting the COO to CSR and CSR to COO and
222 // comparing them. In essense, we are comparing the resR and resO
223 // TODO: Make a better comparison using dense
224
225 // Check resR against conR
226 array conR = sparseConvertTo(resR, AF_STORAGE_CSR);
227 ASSERT_ARRAYS_EQ(resR, conR);
228
229 // Check resO against conO
230 array conO = sparseConvertTo(resR, AF_STORAGE_COO);
231 ASSERT_ARRAYS_EQ(resO, conO);
232}
233
234#define ARITH_TESTS_OPS(T, M, N, F, EPS) \
235 TEST(SPARSE_ARITH, T##_ADD_##M##_##N) { \

Callers

nothing calls this directly

Calls 8

deviceGCFunction · 0.85
randuFunction · 0.85
sparseFunction · 0.85
af_divFunction · 0.85
sparseConvertToFunction · 0.85
dim4Class · 0.50
af_release_arrayFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected