| 35 | // However, template specialization is not allowed |
| 36 | template<typename T> |
| 37 | SparseArray<T> sparseConvertDenseToCOO(const Array<T> &in) { |
| 38 | in.eval(); |
| 39 | |
| 40 | Array<uint> nonZeroIdx_ = where<T>(in); |
| 41 | Array<int> nonZeroIdx = cast<int, uint>(nonZeroIdx_); |
| 42 | |
| 43 | dim_t nNZ = nonZeroIdx.elements(); |
| 44 | |
| 45 | Array<int> constDim = createValueArray<int>(dim4(nNZ), in.dims()[0]); |
| 46 | constDim.eval(); |
| 47 | |
| 48 | Array<int> rowIdx = |
| 49 | arithOp<int, af_mod_t>(nonZeroIdx, constDim, nonZeroIdx.dims()); |
| 50 | Array<int> colIdx = |
| 51 | arithOp<int, af_div_t>(nonZeroIdx, constDim, nonZeroIdx.dims()); |
| 52 | |
| 53 | Array<T> values = copyArray<T>(in); |
| 54 | values = modDims(values, dim4(values.elements())); |
| 55 | values = lookup<T, int>(values, nonZeroIdx, 0); |
| 56 | |
| 57 | return createArrayDataSparseArray<T>(in.dims(), values, rowIdx, colIdx, |
| 58 | AF_STORAGE_COO); |
| 59 | } |
| 60 | |
| 61 | template<typename T, af_storage stype> |
| 62 | SparseArray<T> sparseConvertDenseToStorage(const Array<T> &in_) { |