| 147 | |
| 148 | template<typename T> |
| 149 | static void convertCSR(const int M, const int N, const double ratio, |
| 150 | int targetDevice = -1) { |
| 151 | if (targetDevice >= 0) af::setDevice(targetDevice); |
| 152 | |
| 153 | SUPPORTED_TYPE_CHECK(T); |
| 154 | #if 1 |
| 155 | af::array a = cpu_randu<T>(af::dim4(M, N)); |
| 156 | #else |
| 157 | af::array a = af::randu(M, N); |
| 158 | #endif |
| 159 | a = a * (a > ratio); |
| 160 | |
| 161 | af::array s = af::sparse(a, AF_STORAGE_CSR); |
| 162 | af::array aa = af::dense(s); |
| 163 | |
| 164 | ASSERT_ARRAYS_EQ(a, aa); |
| 165 | } |
| 166 | |
| 167 | template<typename T> |
| 168 | static void convertCSC(const int M, const int N, const double ratio, |