| 93 | |
| 94 | template<typename T, af_op_t op> |
| 95 | void sparseArithTester(const int m, const int n, int factor, const double eps) { |
| 96 | deviceGC(); |
| 97 | |
| 98 | SUPPORTED_TYPE_CHECK(T); |
| 99 | |
| 100 | #if 1 |
| 101 | array A = cpu_randu<T>(dim4(m, n)); |
| 102 | array B = cpu_randu<T>(dim4(m, n)); |
| 103 | #else |
| 104 | array A = randu(m, n, (dtype)dtype_traits<T>::af_type); |
| 105 | array B = randu(m, n, (dtype)dtype_traits<T>::af_type); |
| 106 | #endif |
| 107 | |
| 108 | A = makeSparse<T>(A, factor); |
| 109 | |
| 110 | array RA = sparse(A, AF_STORAGE_CSR); |
| 111 | array OA = sparse(A, AF_STORAGE_COO); |
| 112 | |
| 113 | // Arith Op |
| 114 | array resR = arith_op<op>()(RA, B); |
| 115 | array resO = arith_op<op>()(OA, B); |
| 116 | array resD = arith_op<op>()(A, B); |
| 117 | |
| 118 | array revR = arith_op<op>()(B, RA); |
| 119 | array revO = arith_op<op>()(B, OA); |
| 120 | array revD = arith_op<op>()(B, A); |
| 121 | |
| 122 | ASSERT_ARRAYS_NEAR(resD, resR, eps); |
| 123 | ASSERT_ARRAYS_NEAR(resD, resO, eps); |
| 124 | ASSERT_ARRAYS_NEAR(revD, revR, eps); |
| 125 | ASSERT_ARRAYS_NEAR(revD, revO, eps); |
| 126 | } |
| 127 | |
| 128 | // Mul |
| 129 | template<typename T> |