| 128 | // Mul |
| 129 | template<typename T> |
| 130 | void sparseArithTesterMul(const int m, const int n, int factor, |
| 131 | const double eps) { |
| 132 | deviceGC(); |
| 133 | |
| 134 | SUPPORTED_TYPE_CHECK(T); |
| 135 | |
| 136 | #if 1 |
| 137 | array A = cpu_randu<T>(dim4(m, n)); |
| 138 | array B = cpu_randu<T>(dim4(m, n)); |
| 139 | #else |
| 140 | array A = randu(m, n, (dtype)dtype_traits<T>::af_type); |
| 141 | array B = randu(m, n, (dtype)dtype_traits<T>::af_type); |
| 142 | #endif |
| 143 | |
| 144 | A = makeSparse<T>(A, factor); |
| 145 | |
| 146 | array RA = sparse(A, AF_STORAGE_CSR); |
| 147 | array OA = sparse(A, AF_STORAGE_COO); |
| 148 | |
| 149 | // Forward |
| 150 | { |
| 151 | // Arith Op |
| 152 | array resR = arith_op<af_mul_t>()(RA, B); |
| 153 | array resO = arith_op<af_mul_t>()(OA, B); |
| 154 | |
| 155 | // We will test this by converting the COO to CSR and CSR to COO and |
| 156 | // comparing them. In essense, we are comparing the resR and resO |
| 157 | // TODO: Make a better comparison using dense |
| 158 | |
| 159 | // Check resR against conR |
| 160 | array conR = sparseConvertTo(resR, AF_STORAGE_CSR); |
| 161 | ASSERT_ARRAYS_NEAR(resR, conR, eps); |
| 162 | |
| 163 | // Check resO against conO |
| 164 | array conO = sparseConvertTo(resR, AF_STORAGE_COO); |
| 165 | ASSERT_ARRAYS_NEAR(resO, conO, eps); |
| 166 | } |
| 167 | |
| 168 | // Reverse |
| 169 | { |
| 170 | // Arith Op |
| 171 | array resR = arith_op<af_mul_t>()(B, RA); |
| 172 | array resO = arith_op<af_mul_t>()(B, OA); |
| 173 | |
| 174 | // We will test this by converting the COO to CSR and CSR to COO and |
| 175 | // comparing them. In essense, we are comparing the resR and resO |
| 176 | // TODO: Make a better comparison using dense |
| 177 | |
| 178 | // Check resR against conR |
| 179 | array conR = sparseConvertTo(resR, AF_STORAGE_CSR); |
| 180 | ASSERT_ARRAYS_NEAR(resR, conR, eps); |
| 181 | |
| 182 | // Check resO against conO |
| 183 | array conO = sparseConvertTo(resR, AF_STORAGE_COO); |
| 184 | ASSERT_ARRAYS_NEAR(resO, conO, eps); |
| 185 | } |
| 186 | } |
| 187 |
nothing calls this directly
no test coverage detected