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