| 60 | |
| 61 | template<typename T, af_storage stype> |
| 62 | SparseArray<T> sparseConvertDenseToStorage(const Array<T> &in_) { |
| 63 | in_.eval(); |
| 64 | |
| 65 | uint nNZ = getScalar<uint>(reduce_all<af_notzero_t, T, uint>(in_)); |
| 66 | |
| 67 | SparseArray<T> sparse_ = createEmptySparseArray<T>(in_.dims(), nNZ, stype); |
| 68 | sparse_.eval(); |
| 69 | |
| 70 | Array<T> &values = sparse_.getValues(); |
| 71 | Array<int> &rowIdx = sparse_.getRowIdx(); |
| 72 | Array<int> &colIdx = sparse_.getColIdx(); |
| 73 | |
| 74 | kernel::dense2csr<T>(values, rowIdx, colIdx, in_); |
| 75 | |
| 76 | return sparse_; |
| 77 | } |
| 78 | |
| 79 | // Partial template specialization of sparseConvertStorageToDense for COO |
| 80 | // However, template specialization is not allowed |