| 122 | |
| 123 | template<typename T, af_storage dest, af_storage src> |
| 124 | SparseArray<T> sparseConvertStorageToStorage(const SparseArray<T> &in) { |
| 125 | in.eval(); |
| 126 | |
| 127 | SparseArray<T> converted = createEmptySparseArray<T>( |
| 128 | in.dims(), static_cast<int>(in.getNNZ()), dest); |
| 129 | converted.eval(); |
| 130 | |
| 131 | if (src == AF_STORAGE_CSR && dest == AF_STORAGE_COO) { |
| 132 | Array<int> index = range<int>(in.getNNZ(), 0); |
| 133 | index.eval(); |
| 134 | |
| 135 | Array<T> &ovalues = converted.getValues(); |
| 136 | Array<int> &orowIdx = converted.getRowIdx(); |
| 137 | Array<int> &ocolIdx = converted.getColIdx(); |
| 138 | const Array<T> &ivalues = in.getValues(); |
| 139 | const Array<int> &irowIdx = in.getRowIdx(); |
| 140 | const Array<int> &icolIdx = in.getColIdx(); |
| 141 | |
| 142 | kernel::csr2coo<T>(ovalues, orowIdx, ocolIdx, ivalues, irowIdx, icolIdx, |
| 143 | index); |
| 144 | |
| 145 | } else if (src == AF_STORAGE_COO && dest == AF_STORAGE_CSR) { |
| 146 | Array<int> index = range<int>(in.getNNZ(), 0); |
| 147 | index.eval(); |
| 148 | |
| 149 | Array<T> &ovalues = converted.getValues(); |
| 150 | Array<int> &orowIdx = converted.getRowIdx(); |
| 151 | Array<int> &ocolIdx = converted.getColIdx(); |
| 152 | const Array<T> &ivalues = in.getValues(); |
| 153 | const Array<int> &irowIdx = in.getRowIdx(); |
| 154 | const Array<int> &icolIdx = in.getColIdx(); |
| 155 | |
| 156 | Array<int> rowCopy = copyArray<int>(irowIdx); |
| 157 | rowCopy.eval(); |
| 158 | |
| 159 | kernel::coo2csr<T>(ovalues, orowIdx, ocolIdx, ivalues, irowIdx, icolIdx, |
| 160 | index, rowCopy, in.dims()[0]); |
| 161 | |
| 162 | } else { |
| 163 | // Should never come here |
| 164 | AF_ERROR("OpenCL Backend invalid conversion combination", |
| 165 | AF_ERR_NOT_SUPPORTED); |
| 166 | } |
| 167 | |
| 168 | return converted; |
| 169 | } |
| 170 | |
| 171 | #define INSTANTIATE_TO_STORAGE(T, S) \ |
| 172 | template SparseArray<T> \ |